diff --git a/src/plugins/uploader.js b/src/plugins/uploader.js index 19642c57..ad4070e4 100644 --- a/src/plugins/uploader.js +++ b/src/plugins/uploader.js @@ -54,7 +54,7 @@ class Uploader { express.post("/uploads/new/:token", Uploader.routeUploadFile); } - static routeGetFile(req, res) { + static async routeGetFile(req, res) { const name = req.params.name; const nameRegex = /^[0-9a-f]{16}$/; @@ -66,7 +66,7 @@ class Uploader { const folder = name.substring(0, 2); const uploadPath = Helper.getFileUploadPath(); const filePath = path.join(uploadPath, folder, name); - const detectedMimeType = Uploader.getFileType(filePath); + const detectedMimeType = await Uploader.getFileType(filePath); // doesn't exist if (detectedMimeType === null) { @@ -232,12 +232,12 @@ class Uploader { // Returns null if an error occurred (e.g. file not found) // Returns a string with the type otherwise - static getFileType(filePath) { + static async getFileType(filePath) { try { const buffer = readChunk.sync(filePath, 0, fileType.minimumBytes); // returns {ext, mime} if found, null if not. - const file = fileType(buffer); + const file = await fileType.fromBuffer(buffer); // if a file type was detected correctly, return it if (file) {