Browse Source

fix(nocodb): utf8ify file originalname

pull/6824/head
աɨռɢӄաօռɢ 1 year ago
parent
commit
30ade1f733
  1. 9
      packages/nocodb/src/services/attachments.service.ts
  2. 9
      packages/nocodb/src/services/public-datas.service.ts

9
packages/nocodb/src/services/attachments.service.ts

@ -8,6 +8,7 @@ import NcPluginMgrv2 from '~/helpers/NcPluginMgrv2';
import Local from '~/plugins/storage/Local'; import Local from '~/plugins/storage/Local';
import mimetypes, { mimeIcons } from '~/utils/mimeTypes'; import mimetypes, { mimeIcons } from '~/utils/mimeTypes';
import { PresignedUrl } from '~/models'; import { PresignedUrl } from '~/models';
import { utf8ify } from '~/helpers/stringHelpers';
@Injectable() @Injectable()
export class AttachmentsService { export class AttachmentsService {
@ -28,7 +29,8 @@ export class AttachmentsService {
const attachments = await Promise.all( const attachments = await Promise.all(
param.files?.map(async (file: any) => { 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( const url = await storageAdapter.fileCreate(
slash(path.join(destPath, fileName)), slash(path.join(destPath, fileName)),
@ -46,11 +48,10 @@ export class AttachmentsService {
signedUrl?: string; signedUrl?: string;
} = { } = {
...(url ? { url } : {}), ...(url ? { url } : {}),
title: file.originalname, title: originalName,
mimetype: file.mimetype, mimetype: file.mimetype,
size: file.size, size: file.size,
icon: icon: mimeIcons[path.extname(originalName).slice(1)] || undefined,
mimeIcons[path.extname(file.originalname).slice(1)] || undefined,
}; };
const promises = []; const promises = [];

9
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 NcConnectionMgrv2 from '~/utils/common/NcConnectionMgrv2';
import { mimeIcons } from '~/utils/mimeTypes'; import { mimeIcons } from '~/utils/mimeTypes';
import { Column, Model, Source, View } from '~/models'; import { Column, Model, Source, View } from '~/models';
import { utf8ify } from '~/helpers/stringHelpers';
// todo: move to utils // todo: move to utils
export function sanitizeUrlPath(paths) { export function sanitizeUrlPath(paths) {
@ -319,7 +320,8 @@ export class PublicDatasService {
fields[fieldName].uidt === UITypes.Attachment fields[fieldName].uidt === UITypes.Attachment
) { ) {
attachments[fieldName] = attachments[fieldName] || []; 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( const url = await storageAdapter.fileCreate(
slash(path.join('nc', 'uploads', ...filePath, fileName)), slash(path.join('nc', 'uploads', ...filePath, fileName)),
@ -337,11 +339,10 @@ export class PublicDatasService {
attachments[fieldName].push({ attachments[fieldName].push({
...(url ? { url } : {}), ...(url ? { url } : {}),
...(attachmentPath ? { path: attachmentPath } : {}), ...(attachmentPath ? { path: attachmentPath } : {}),
title: file.originalname, title: originalName,
mimetype: file.mimetype, mimetype: file.mimetype,
size: file.size, size: file.size,
icon: icon: mimeIcons[path.extname(originalName).slice(1)] || undefined,
mimeIcons[path.extname(file.originalname).slice(1)] || undefined,
}); });
} }
} }

Loading…
Cancel
Save