fix: Remove application/octet-stream as valid frontend mimetype (#2126)

* Remove application/octet-stream and add explicit extensions

* Modify the condition to check for extensions too
This commit is contained in:
Saumya Pandey 2021-05-11 20:37:41 +05:30 committed by GitHub
parent fed3774cee
commit a39f7a4e55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 2 deletions

View File

@ -1,4 +1,5 @@
// @flow // @flow
import path from "path";
import invariant from "invariant"; import invariant from "invariant";
import { find, orderBy, filter, compact, omitBy } from "lodash"; import { find, orderBy, filter, compact, omitBy } from "lodash";
import { observable, action, computed, runInAction } from "mobx"; import { observable, action, computed, runInAction } from "mobx";
@ -24,12 +25,13 @@ export default class DocumentsStore extends BaseStore<Document> {
importFileTypes: string[] = [ importFileTypes: string[] = [
".md", ".md",
".doc",
".docx",
"text/markdown", "text/markdown",
"text/plain", "text/plain",
"text/html", "text/html",
"application/msword", "application/msword",
"application/vnd.openxmlformats-officedocument.wordprocessingml.document", "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"application/octet-stream",
]; ];
constructor(rootStore: RootStore) { constructor(rootStore: RootStore) {
@ -532,9 +534,14 @@ export default class DocumentsStore extends BaseStore<Document> {
options: ImportOptions options: ImportOptions
) => { ) => {
// file.type can be an empty string sometimes // file.type can be an empty string sometimes
if (file.type && !this.importFileTypes.includes(file.type)) { if (
file.type &&
!this.importFileTypes.includes(file.type) &&
!this.importFileTypes.includes(path.extname(file.name))
) {
throw new Error(`The selected file type is not supported (${file.type})`); throw new Error(`The selected file type is not supported (${file.type})`);
} }
if (file.size > env.MAXIMUM_IMPORT_SIZE) { if (file.size > env.MAXIMUM_IMPORT_SIZE) {
throw new Error("The selected file was too large to import"); throw new Error("The selected file was too large to import");
} }