From 08cbfd5c727412ca21c5664f48eaf878b29bde1d Mon Sep 17 00:00:00 2001 From: Ramesh Mane <101566080+rameshmane7218@users.noreply.github.com> Date: Wed, 20 Nov 2024 17:11:14 +0000 Subject: [PATCH] fix(nocodb): thumbnail generate issue on new public path scope --- packages/nc-gui/components/general/ImageCropper.vue | 4 +++- .../components/general/WorkspaceIconSelector.vue | 2 ++ packages/nocodb/src/interface/Jobs.ts | 3 ++- .../thumbnail-generator.processor.ts | 11 +++++++---- packages/nocodb/src/services/attachments.service.ts | 2 ++ 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/packages/nc-gui/components/general/ImageCropper.vue b/packages/nc-gui/components/general/ImageCropper.vue index 751f96aaae..2c62d9263b 100644 --- a/packages/nc-gui/components/general/ImageCropper.vue +++ b/packages/nc-gui/components/general/ImageCropper.vue @@ -2,7 +2,7 @@ import { Cropper } from 'vue-advanced-cropper' import 'vue-advanced-cropper/dist/style.css' import 'vue-advanced-cropper/dist/theme.classic.css' -import type { AttachmentReqType } from 'nocodb-sdk' +import type { AttachmentReqType, PublicAttachmentScope } from 'nocodb-sdk' import type { ImageCropperConfig } from '#imports' interface Props { @@ -14,6 +14,7 @@ interface Props { cropperConfig: ImageCropperConfig uploadConfig?: { path?: string + scope?: PublicAttachmentScope } showCropper: boolean } @@ -47,6 +48,7 @@ const handleUploadImage = async (fileToUpload: AttachmentReqType[]) => { const uploadResult = await api.storage.uploadByUrl( { path: uploadConfig?.path as string, + scope: uploadConfig?.scope, }, fileToUpload, ) diff --git a/packages/nc-gui/components/general/WorkspaceIconSelector.vue b/packages/nc-gui/components/general/WorkspaceIconSelector.vue index 2e49194d41..589dcca27e 100644 --- a/packages/nc-gui/components/general/WorkspaceIconSelector.vue +++ b/packages/nc-gui/components/general/WorkspaceIconSelector.vue @@ -5,6 +5,7 @@ import data from 'emoji-mart-vue-fast/data/apple.json' import { EmojiIndex, Picker } from 'emoji-mart-vue-fast/src' import { WorkspaceIconType } from '#imports' import 'emoji-mart-vue-fast/css/emoji-mart.css' +import { PublicAttachmentScope } from 'nocodb-sdk' interface Props { icon: string | Record @@ -104,6 +105,7 @@ const imageCropperData = ref({ }, uploadConfig: { path: [NOCO, 'workspace', currentWorkspace.value?.id, 'icon'].join('/'), + scope: PublicAttachmentScope.WORKSPACEPICS, }, }) diff --git a/packages/nocodb/src/interface/Jobs.ts b/packages/nocodb/src/interface/Jobs.ts index 5d11905b8c..f258ab4985 100644 --- a/packages/nocodb/src/interface/Jobs.ts +++ b/packages/nocodb/src/interface/Jobs.ts @@ -1,4 +1,4 @@ -import type { AttachmentResType, UserType } from 'nocodb-sdk'; +import type { AttachmentResType, PublicAttachmentScope, UserType } from 'nocodb-sdk'; import type { NcContext, NcRequest } from '~/interface/config'; export const JOBS_QUEUE = 'jobs'; @@ -161,4 +161,5 @@ export interface DataExportJobData extends JobData { export interface ThumbnailGeneratorJobData extends JobData { attachments: AttachmentResType[]; + scope?: PublicAttachmentScope; } diff --git a/packages/nocodb/src/modules/jobs/jobs/thumbnail-generator/thumbnail-generator.processor.ts b/packages/nocodb/src/modules/jobs/jobs/thumbnail-generator/thumbnail-generator.processor.ts index 1f1232815d..5206837850 100644 --- a/packages/nocodb/src/modules/jobs/jobs/thumbnail-generator/thumbnail-generator.processor.ts +++ b/packages/nocodb/src/modules/jobs/jobs/thumbnail-generator/thumbnail-generator.processor.ts @@ -4,7 +4,7 @@ import { Logger } from '@nestjs/common'; import slash from 'slash'; import type { IStorageAdapterV2 } from '~/types/nc-plugin'; import type { Job } from 'bull'; -import type { AttachmentResType } from 'nocodb-sdk'; +import type { AttachmentResType, PublicAttachmentScope } from 'nocodb-sdk'; import type { ThumbnailGeneratorJobData } from '~/interface/Jobs'; import NcPluginMgrv2 from '~/helpers/NcPluginMgrv2'; import { getPathFromUrl } from '~/helpers/attachmentHelpers'; @@ -14,12 +14,12 @@ export class ThumbnailGeneratorProcessor { private logger = new Logger(ThumbnailGeneratorProcessor.name); async job(job: Job) { - const { attachments } = job.data; + const { attachments, scope } = job.data; const results = []; for (const attachment of attachments) { - const thumbnail = await this.generateThumbnail(attachment); + const thumbnail = await this.generateThumbnail(attachment, scope); if (!thumbnail) { continue; @@ -38,6 +38,7 @@ export class ThumbnailGeneratorProcessor { private async generateThumbnail( attachment: AttachmentResType, + scope?: PublicAttachmentScope, ): Promise<{ [key: string]: string }> { const sharp = Noco.sharp; @@ -53,6 +54,7 @@ export class ThumbnailGeneratorProcessor { const { file, relativePath } = await this.getFileData( attachment, storageAdapter, + scope, ); const thumbnailPaths = { @@ -119,13 +121,14 @@ export class ThumbnailGeneratorProcessor { private async getFileData( attachment: AttachmentResType, storageAdapter: IStorageAdapterV2, + scope?: PublicAttachmentScope, ): Promise<{ file: Buffer; relativePath: string }> { let relativePath; if (attachment.path) { relativePath = path.join( 'nc', - 'uploads', + scope ? scope : 'uploads', attachment.path.replace(/^download[/\\]/i, ''), ); } else if (attachment.url) { diff --git a/packages/nocodb/src/services/attachments.service.ts b/packages/nocodb/src/services/attachments.service.ts index 0dfe1db816..48dbcc1f53 100644 --- a/packages/nocodb/src/services/attachments.service.ts +++ b/packages/nocodb/src/services/attachments.service.ts @@ -196,6 +196,7 @@ export class AttachmentsService { workspace_id: RootScopes.ROOT, }, attachments: generateThumbnail, + scope: param.scope, }); } @@ -380,6 +381,7 @@ export class AttachmentsService { workspace_id: RootScopes.ROOT, }, attachments: generateThumbnail, + scope: param.scope, }); }