From c36df2c36462412294c8a49975eedf20a9e79f0b Mon Sep 17 00:00:00 2001 From: Sean Hatfield <seanhatfield5@gmail.com> Date: Fri, 21 Feb 2025 15:09:34 +0800 Subject: [PATCH] Fix garbled non English chars on document upload (#3301) update handleAPIFileUpload middleware to handle non english chars + update jsdoc --- server/endpoints/api/document/index.js | 7 ++++--- server/swagger/openapi.json | 11 +++++++---- server/utils/files/multer.js | 4 +++- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/server/endpoints/api/document/index.js b/server/endpoints/api/document/index.js index f07d18685..60090bddc 100644 --- a/server/endpoints/api/document/index.js +++ b/server/endpoints/api/document/index.js @@ -35,14 +35,15 @@ function apiDocumentEndpoints(app) { content: { "multipart/form-data": { schema: { - type: 'string', - format: 'binary', + type: 'object', properties: { file: { type: 'string', format: 'binary', + description: 'The file to upload' } - } + }, + required: ['file'] } } } diff --git a/server/swagger/openapi.json b/server/swagger/openapi.json index dd45fe34b..91d0aa53d 100644 --- a/server/swagger/openapi.json +++ b/server/swagger/openapi.json @@ -900,14 +900,17 @@ "content": { "multipart/form-data": { "schema": { - "type": "string", - "format": "binary", + "type": "object", "properties": { "file": { "type": "string", - "format": "binary" + "format": "binary", + "description": "The file to upload" } - } + }, + "required": [ + "file" + ] } } } diff --git a/server/utils/files/multer.js b/server/utils/files/multer.js index 18c6df607..ee0de4b11 100644 --- a/server/utils/files/multer.js +++ b/server/utils/files/multer.js @@ -37,7 +37,9 @@ const fileAPIUploadStorage = multer.diskStorage({ cb(null, uploadOutput); }, filename: function (_, file, cb) { - file.originalname = normalizePath(file.originalname); + file.originalname = normalizePath( + Buffer.from(file.originalname, "latin1").toString("utf8") + ); cb(null, file.originalname); }, }); -- GitLab