From 30ade1f7338c6b3543312ecfd923d0bafbd2a211 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D5=A1=C9=A8=D5=BC=C9=A2=D3=84=D5=A1=D6=85=D5=BC=C9=A2?= Date: Sun, 29 Oct 2023 23:29:37 +0800 Subject: [PATCH] fix(nocodb): utf8ify file originalname --- packages/nocodb/src/services/attachments.service.ts | 9 +++++---- packages/nocodb/src/services/public-datas.service.ts | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/packages/nocodb/src/services/attachments.service.ts b/packages/nocodb/src/services/attachments.service.ts index c8e835e61f..ddc671c224 100644 --- a/packages/nocodb/src/services/attachments.service.ts +++ b/packages/nocodb/src/services/attachments.service.ts @@ -8,6 +8,7 @@ import NcPluginMgrv2 from '~/helpers/NcPluginMgrv2'; import Local from '~/plugins/storage/Local'; import mimetypes, { mimeIcons } from '~/utils/mimeTypes'; import { PresignedUrl } from '~/models'; +import { utf8ify } from '~/helpers/stringHelpers'; @Injectable() export class AttachmentsService { @@ -28,7 +29,8 @@ export class AttachmentsService { const attachments = await Promise.all( param.files?.map(async (file: any) => { - const fileName = `${nanoid(18)}${path.extname(file.originalname)}`; + const originalName = utf8ify(file.originalname); + const fileName = `${nanoid(18)}${path.extname(originalName)}`; const url = await storageAdapter.fileCreate( slash(path.join(destPath, fileName)), @@ -46,11 +48,10 @@ export class AttachmentsService { signedUrl?: string; } = { ...(url ? { url } : {}), - title: file.originalname, + title: originalName, mimetype: file.mimetype, size: file.size, - icon: - mimeIcons[path.extname(file.originalname).slice(1)] || undefined, + icon: mimeIcons[path.extname(originalName).slice(1)] || undefined, }; const promises = []; diff --git a/packages/nocodb/src/services/public-datas.service.ts b/packages/nocodb/src/services/public-datas.service.ts index f7eba61fd8..f71a11707d 100644 --- a/packages/nocodb/src/services/public-datas.service.ts +++ b/packages/nocodb/src/services/public-datas.service.ts @@ -14,6 +14,7 @@ import { getColumnByIdOrName } from '~/modules/datas/helpers'; import NcConnectionMgrv2 from '~/utils/common/NcConnectionMgrv2'; import { mimeIcons } from '~/utils/mimeTypes'; import { Column, Model, Source, View } from '~/models'; +import { utf8ify } from '~/helpers/stringHelpers'; // todo: move to utils export function sanitizeUrlPath(paths) { @@ -319,7 +320,8 @@ export class PublicDatasService { fields[fieldName].uidt === UITypes.Attachment ) { attachments[fieldName] = attachments[fieldName] || []; - const fileName = `${nanoid(18)}${path.extname(file.originalname)}`; + const originalName = utf8ify(file.originalname); + const fileName = `${nanoid(18)}${path.extname(originalName)}`; const url = await storageAdapter.fileCreate( slash(path.join('nc', 'uploads', ...filePath, fileName)), @@ -337,11 +339,10 @@ export class PublicDatasService { attachments[fieldName].push({ ...(url ? { url } : {}), ...(attachmentPath ? { path: attachmentPath } : {}), - title: file.originalname, + title: originalName, mimetype: file.mimetype, size: file.size, - icon: - mimeIcons[path.extname(file.originalname).slice(1)] || undefined, + icon: mimeIcons[path.extname(originalName).slice(1)] || undefined, }); } }