Skip to content

Commit 1031bb4

Browse files
committed
Better detection for text files while uploading
1 parent df13048 commit 1031bb4

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

packages/app/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@
222222
"subworkers": "^1.0.1",
223223
"svg-react-loader": "^0.4.4",
224224
"tern": "^0.21.0",
225+
"textextensions": "^3.3.0",
225226
"use-interval": "^1.2.1",
226227
"util": "0.11.1",
227228
"vue": "^2.5.2",

packages/app/src/app/overmind/namespaces/files/internalActions.ts

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ export const uploadFiles: AsyncAction<
7878
const filePaths = Object.keys(files);
7979
const chunkedFilePaths = chunk(filePaths, 5);
8080

81+
const textExtensions = (await import('textextensions/source/index.json'))
82+
.default;
83+
8184
// We traverse all files and upload them when necessary, then add them to the
8285
// parsedFiles object
8386
/* eslint-disable no-restricted-syntax, no-await-in-loop */
@@ -87,20 +90,10 @@ export const uploadFiles: AsyncAction<
8790
const file = files[filePath];
8891
const { dataURI } = file;
8992

93+
const extension = filePath.split('.').pop();
94+
9095
if (
91-
(/\.(j|t)sx?$/.test(filePath) ||
92-
/\.coffee$/.test(filePath) ||
93-
/\.json$/.test(filePath) ||
94-
/\.html$/.test(filePath) ||
95-
/\.vue$/.test(filePath) ||
96-
/\.styl$/.test(filePath) ||
97-
/\.(le|sc|sa)ss$/.test(filePath) ||
98-
/\.haml$/.test(filePath) ||
99-
/\.pug$/.test(filePath) ||
100-
/\.svg$/.test(filePath) ||
101-
/\.md$/.test(filePath) ||
102-
/\.svelte$/.test(filePath) ||
103-
/\.hbs$/.test(filePath) ||
96+
(textExtensions.includes(extension) ||
10497
file.type.startsWith('text/') ||
10598
file.type === 'application/json') &&
10699
dataURI.length < MAX_FILE_SIZE

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28273,6 +28273,11 @@ textextensions@2:
2827328273
version "2.2.0"
2827428274
resolved "https://registry.yarnpkg.com/textextensions/-/textextensions-2.2.0.tgz#38ac676151285b658654581987a0ce1a4490d286"
2827528275

28276+
textextensions@^3.3.0:
28277+
version "3.3.0"
28278+
resolved "https://registry.yarnpkg.com/textextensions/-/textextensions-3.3.0.tgz#03530d5287b86773c08b77458589148870cc71d3"
28279+
integrity sha512-mk82dS8eRABNbeVJrEiN5/UMSCliINAuz8mkUwH4SwslkNP//gbEzlWNS5au0z5Dpx40SQxzqZevZkn+WYJ9Dw==
28280+
2827628281
textextensions@~1.0.0:
2827728282
version "1.0.2"
2827828283
resolved "https://registry.yarnpkg.com/textextensions/-/textextensions-1.0.2.tgz#65486393ee1f2bb039a60cbba05b0b68bd9501d2"

0 commit comments

Comments
 (0)