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. 20
      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 {
const fileName = populateUniqueFileName(
(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 || '',
)
@ -226,7 +226,7 @@ export const [useProvideAttachmentCell, useAttachmentCell] = useInjectionState(
...uploadedFile,
title: populateUniqueFileName(
uploadedFile?.title,
[...attachments.value, ...newAttachments].map((fn) => fn?.title || fn?.fileName || 'image'),
[...attachments.value, ...newAttachments].map((fn) => fn?.title || fn?.fileName),
uploadedFile?.mimetype,
),
})

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

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

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

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

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

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

Loading…
Cancel
Save