mirror of
https://github.com/nocodb/nocodb.git
synced 2026-02-02 02:26:57 +00:00
Merge pull request #6364 from nocodb/fix/attachment-part-2
fix: attachment for oss
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import type { NcRequest } from 'nocodb-sdk';
|
||||
import { NcApiVersion, type NcRequest } from 'nocodb-sdk';
|
||||
import type { IBaseModelSqlV2 } from '~/db/IBaseModelSqlV2';
|
||||
import { type AttachmentUrlUploadJobData, JobTypes } from '~/interface/Jobs';
|
||||
import { EMIT_EVENT } from '~/constants';
|
||||
@@ -22,6 +22,10 @@ export class AttachmentUrlUploadPreparator {
|
||||
const postInsertOps: ((rowId: any) => Promise<string>)[] = [];
|
||||
const preInsertOps: (() => Promise<string>)[] = [];
|
||||
const postInsertAuditOps: ((rowId: any) => Promise<void>)[] = [];
|
||||
// return early if not v3
|
||||
if (baseModel.context.api_version !== NcApiVersion.V3) {
|
||||
return { postInsertOps, preInsertOps, postInsertAuditOps };
|
||||
}
|
||||
for (const col of attachmentCols) {
|
||||
let attachmentData: { id?: string; url: string }[];
|
||||
try {
|
||||
@@ -40,24 +44,27 @@ export class AttachmentUrlUploadPreparator {
|
||||
} catch {
|
||||
continue;
|
||||
}
|
||||
postInsertOps.push(async (recordId) => {
|
||||
Noco.eventEmitter.emit(EMIT_EVENT.HANDLE_ATTACHMENT_URL_UPLOAD, {
|
||||
jobName: JobTypes.AttachmentUrlUpload,
|
||||
context: baseModel.context,
|
||||
modelId: baseModel.model.id,
|
||||
column: col,
|
||||
recordId,
|
||||
user: baseModel.context.user,
|
||||
attachments: attachmentData,
|
||||
req,
|
||||
} as AttachmentUrlUploadJobData);
|
||||
return '';
|
||||
});
|
||||
const columnKeyName = dataWrapper(data).getColumnKeyName(col);
|
||||
// remove temp_ ids so it doesn't get recorded in audit
|
||||
data[columnKeyName] = JSON.stringify(
|
||||
attachmentData.filter((dt) => !dt.id?.startsWith('temp_')),
|
||||
);
|
||||
// only process when temp id exists
|
||||
if (attachmentData.some((attr) => attr.id?.startsWith('temp_'))) {
|
||||
postInsertOps.push(async (recordId) => {
|
||||
Noco.eventEmitter.emit(EMIT_EVENT.HANDLE_ATTACHMENT_URL_UPLOAD, {
|
||||
jobName: JobTypes.AttachmentUrlUpload,
|
||||
context: baseModel.context,
|
||||
modelId: baseModel.model.id,
|
||||
column: col,
|
||||
recordId,
|
||||
user: baseModel.context.user,
|
||||
attachments: attachmentData,
|
||||
req,
|
||||
} as AttachmentUrlUploadJobData);
|
||||
return '';
|
||||
});
|
||||
const columnKeyName = dataWrapper(data).getColumnKeyName(col);
|
||||
// remove temp_ ids so it doesn't get recorded in audit
|
||||
data[columnKeyName] = JSON.stringify(
|
||||
attachmentData.filter((dt) => !dt.id?.startsWith('temp_')),
|
||||
);
|
||||
}
|
||||
}
|
||||
return { postInsertOps, preInsertOps, postInsertAuditOps };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user