fix: Add application/octet-stream as a valid mimetype for docx uploads (#2105)
* fix: Add application/octet-stream as a valid mimetype for docx uploads * fix: Include application/octet-stream in frontend filter fix: Add file size and file type guards * Validate .docx extension in files with application/octet-stream mimetype * refactor: Move MAXIMUM_IMPORT_SIZE to an optional environment config fix: Add file size check on server too Co-authored-by: Saumya Pandey <sp160899@gmail.com>
This commit is contained in:
@@ -8,6 +8,7 @@ import naturalSort from "shared/utils/naturalSort";
|
||||
import BaseStore from "stores/BaseStore";
|
||||
import RootStore from "stores/RootStore";
|
||||
import Document from "models/Document";
|
||||
import env from "env";
|
||||
import type { FetchOptions, PaginationParams, SearchResult } from "types";
|
||||
import { client } from "utils/ApiClient";
|
||||
|
||||
@@ -28,6 +29,7 @@ export default class DocumentsStore extends BaseStore<Document> {
|
||||
"text/html",
|
||||
"application/msword",
|
||||
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
||||
"application/octet-stream",
|
||||
];
|
||||
|
||||
constructor(rootStore: RootStore) {
|
||||
@@ -529,6 +531,14 @@ export default class DocumentsStore extends BaseStore<Document> {
|
||||
collectionId: string,
|
||||
options: ImportOptions
|
||||
) => {
|
||||
// file.type can be an empty string sometimes
|
||||
if (file.type && !this.importFileTypes.includes(file.type)) {
|
||||
throw new Error(`The selected file type is not supported (${file.type})`);
|
||||
}
|
||||
if (file.size > env.MAXIMUM_IMPORT_SIZE) {
|
||||
throw new Error("The selected file was too large to import");
|
||||
}
|
||||
|
||||
const title = file.name.replace(/\.[^/.]+$/, "");
|
||||
const formData = new FormData();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user