Skip to content

Commit 5abb159

Browse files
committed
chore: parameterize file-size limit and document config
1 parent 906626b commit 5abb159

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

DEV-GUIDE.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Dev Guide
2+
3+
## File size limit used by file browser
4+
5+
The file open size limit is configured in [src/toolbarActions/toolbarFunctions.js](src/toolbarActions/toolbarFunctions.js).
6+
7+
- `MAX_FILE_SIZE_MB` controls the limit in MB.
8+
- `MAX_FILE_SIZE` is derived from it as bytes.
9+
10+
To change the limit, update `MAX_FILE_SIZE_MB` only.

src/toolbarActions/toolbarFunctions.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import parser from '../graph-builder/graphml/parser';
33
import { actionType as T } from '../reducer';
44

55
const getGraphFun = (superState) => superState.curGraphInstance;
6-
const MAX_FILE_SIZE = 10 * 1024 * 1024;
6+
const MAX_FILE_SIZE_MB = 10;
7+
const MAX_FILE_SIZE = MAX_FILE_SIZE_MB * 1024 * 1024;
78

89
const createNode = (state, setState) => {
910
setState({
@@ -108,7 +109,7 @@ async function saveGraphMLFile(state) {
108109
const readFile = async (state, setState, file, fileHandle) => {
109110
if (file) {
110111
if (file.size > MAX_FILE_SIZE) {
111-
toast.error('File size exceeds 10MB');
112+
toast.error(`File size exceeds ${MAX_FILE_SIZE_MB}MB`);
112113
return;
113114
}
114115
const fr = new FileReader();
@@ -133,7 +134,7 @@ const readFile = async (state, setState, file, fileHandle) => {
133134
const readTextFile = (state, setState, file, fileHandle) => {
134135
if (file) {
135136
if (file.size > MAX_FILE_SIZE) {
136-
toast.error('File size exceeds 10MB');
137+
toast.error(`File size exceeds ${MAX_FILE_SIZE_MB}MB`);
137138
return;
138139
}
139140
setState({

0 commit comments

Comments
 (0)