From 41e3762e577fa128de425161577973c86f038a2f Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Wed, 8 Jan 2020 16:11:01 +0200 Subject: [PATCH] Update file-type api usage --- src/plugins/uploader.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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) {