Browse Source

fic(nc-gui): handle duplicate filename suffix properly #2379

pull/7695/head
Ramesh Mane 10 months ago
parent
commit
0e6231870b
  1. 4
      packages/nc-gui/components/cell/attachment/utils.ts
  2. 2
      packages/nc-gui/composables/useMultiSelect/convertCellData.ts
  3. 2
      packages/nc-gui/composables/useMultiSelect/index.ts
  4. 22
      packages/nocodb/src/services/public-datas.service.ts

4
packages/nc-gui/components/cell/attachment/utils.ts

@ -162,7 +162,7 @@ export const [useProvideAttachmentCell, useAttachmentCell] = useInjectionState(
} else { } else {
const fileName = populateUniqueFileName( const fileName = populateUniqueFileName(
(file as AttachmentReqType).fileName ?? '', (file as AttachmentReqType).fileName ?? '',
[...attachments.value, ...imageUrls].map((fn) => fn?.title || fn?.fileName || 'image'), [...attachments.value, ...imageUrls].map((fn) => fn?.title || fn?.fileName),
(file as File)?.type || (file as AttachmentReqType)?.mimetype || '', (file as File)?.type || (file as AttachmentReqType)?.mimetype || '',
) )
@ -226,7 +226,7 @@ export const [useProvideAttachmentCell, useAttachmentCell] = useInjectionState(
...uploadedFile, ...uploadedFile,
title: populateUniqueFileName( title: populateUniqueFileName(
uploadedFile?.title, uploadedFile?.title,
[...attachments.value, ...newAttachments].map((fn) => fn?.title || fn?.fileName || 'image'), [...attachments.value, ...newAttachments].map((fn) => fn?.title || fn?.fileName),
uploadedFile?.mimetype, uploadedFile?.mimetype,
), ),
}) })

2
packages/nc-gui/composables/useMultiSelect/convertCellData.ts

@ -205,7 +205,7 @@ export default function convertCellData(
...att, ...att,
title: populateUniqueFileName( title: populateUniqueFileName(
att?.title, att?.title,
[...oldAttachments, ...newAttachments].map((fn) => fn?.title || fn?.fileName || 'image'), [...oldAttachments, ...newAttachments].map((fn) => fn?.title || fn?.fileName),
att?.mimetype, att?.mimetype,
), ),
}) })

2
packages/nc-gui/composables/useMultiSelect/index.ts

@ -1261,7 +1261,7 @@ export function useMultiSelect(
...uploadedFile, ...uploadedFile,
title: populateUniqueFileName( title: populateUniqueFileName(
uploadedFile?.title, uploadedFile?.title,
[...handleParseAttachmentCellData(oldValue), ...newAttachments].map((fn) => fn?.title || fn?.fileName || 'image'), [...handleParseAttachmentCellData(oldValue), ...newAttachments].map((fn) => fn?.title || fn?.fileName),
uploadedFile?.mimetype, uploadedFile?.mimetype,
), ),
}) })

22
packages/nocodb/src/services/public-datas.service.ts

@ -1,7 +1,12 @@
import path from 'path'; import path from 'path';
import { Injectable } from '@nestjs/common'; import { Injectable } from '@nestjs/common';
import { nanoid } from 'nanoid'; import { nanoid } from 'nanoid';
import { ErrorMessages, UITypes, ViewTypes } from 'nocodb-sdk'; import {
ErrorMessages,
UITypes,
ViewTypes,
populateUniqueFileName,
} from 'nocodb-sdk';
import slash from 'slash'; import slash from 'slash';
import { nocoExecute } from 'nc-help'; import { nocoExecute } from 'nc-help';
@ -396,16 +401,11 @@ export class PublicDatasService {
attachments[fieldName] = attachments[fieldName] || []; attachments[fieldName] = attachments[fieldName] || [];
let originalName = utf8ify(file.originalname); let originalName = utf8ify(file.originalname);
let c = 1; originalName = populateUniqueFileName(
while ( originalName,
path.extname(originalName) && attachments[fieldName].map((att) => att?.title),
attachments[fieldName].some((att) => att?.title === originalName) file.mimetype,
) { );
originalName = originalName.replace(
/(.+?)(\.[^.]+)$/,
`$1(${c++})$2`,
);
}
const fileName = `${nanoid(18)}${path.extname(originalName)}`; const fileName = `${nanoid(18)}${path.extname(originalName)}`;

Loading…
Cancel
Save