Browse Source

fix(nocodb): thumbnail generate issue on new public path scope

pull/9722/head
Ramesh Mane 1 week ago
parent
commit
08cbfd5c72
  1. 4
      packages/nc-gui/components/general/ImageCropper.vue
  2. 2
      packages/nc-gui/components/general/WorkspaceIconSelector.vue
  3. 3
      packages/nocodb/src/interface/Jobs.ts
  4. 11
      packages/nocodb/src/modules/jobs/jobs/thumbnail-generator/thumbnail-generator.processor.ts
  5. 2
      packages/nocodb/src/services/attachments.service.ts

4
packages/nc-gui/components/general/ImageCropper.vue

@ -2,7 +2,7 @@
import { Cropper } from 'vue-advanced-cropper' import { Cropper } from 'vue-advanced-cropper'
import 'vue-advanced-cropper/dist/style.css' import 'vue-advanced-cropper/dist/style.css'
import 'vue-advanced-cropper/dist/theme.classic.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' import type { ImageCropperConfig } from '#imports'
interface Props { interface Props {
@ -14,6 +14,7 @@ interface Props {
cropperConfig: ImageCropperConfig cropperConfig: ImageCropperConfig
uploadConfig?: { uploadConfig?: {
path?: string path?: string
scope?: PublicAttachmentScope
} }
showCropper: boolean showCropper: boolean
} }
@ -47,6 +48,7 @@ const handleUploadImage = async (fileToUpload: AttachmentReqType[]) => {
const uploadResult = await api.storage.uploadByUrl( const uploadResult = await api.storage.uploadByUrl(
{ {
path: uploadConfig?.path as string, path: uploadConfig?.path as string,
scope: uploadConfig?.scope,
}, },
fileToUpload, fileToUpload,
) )

2
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 { EmojiIndex, Picker } from 'emoji-mart-vue-fast/src'
import { WorkspaceIconType } from '#imports' import { WorkspaceIconType } from '#imports'
import 'emoji-mart-vue-fast/css/emoji-mart.css' import 'emoji-mart-vue-fast/css/emoji-mart.css'
import { PublicAttachmentScope } from 'nocodb-sdk'
interface Props { interface Props {
icon: string | Record<string, any> icon: string | Record<string, any>
@ -104,6 +105,7 @@ const imageCropperData = ref({
}, },
uploadConfig: { uploadConfig: {
path: [NOCO, 'workspace', currentWorkspace.value?.id, 'icon'].join('/'), path: [NOCO, 'workspace', currentWorkspace.value?.id, 'icon'].join('/'),
scope: PublicAttachmentScope.WORKSPACEPICS,
}, },
}) })

3
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'; import type { NcContext, NcRequest } from '~/interface/config';
export const JOBS_QUEUE = 'jobs'; export const JOBS_QUEUE = 'jobs';
@ -161,4 +161,5 @@ export interface DataExportJobData extends JobData {
export interface ThumbnailGeneratorJobData extends JobData { export interface ThumbnailGeneratorJobData extends JobData {
attachments: AttachmentResType[]; attachments: AttachmentResType[];
scope?: PublicAttachmentScope;
} }

11
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 slash from 'slash';
import type { IStorageAdapterV2 } from '~/types/nc-plugin'; import type { IStorageAdapterV2 } from '~/types/nc-plugin';
import type { Job } from 'bull'; 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 type { ThumbnailGeneratorJobData } from '~/interface/Jobs';
import NcPluginMgrv2 from '~/helpers/NcPluginMgrv2'; import NcPluginMgrv2 from '~/helpers/NcPluginMgrv2';
import { getPathFromUrl } from '~/helpers/attachmentHelpers'; import { getPathFromUrl } from '~/helpers/attachmentHelpers';
@ -14,12 +14,12 @@ export class ThumbnailGeneratorProcessor {
private logger = new Logger(ThumbnailGeneratorProcessor.name); private logger = new Logger(ThumbnailGeneratorProcessor.name);
async job(job: Job<ThumbnailGeneratorJobData>) { async job(job: Job<ThumbnailGeneratorJobData>) {
const { attachments } = job.data; const { attachments, scope } = job.data;
const results = []; const results = [];
for (const attachment of attachments) { for (const attachment of attachments) {
const thumbnail = await this.generateThumbnail(attachment); const thumbnail = await this.generateThumbnail(attachment, scope);
if (!thumbnail) { if (!thumbnail) {
continue; continue;
@ -38,6 +38,7 @@ export class ThumbnailGeneratorProcessor {
private async generateThumbnail( private async generateThumbnail(
attachment: AttachmentResType, attachment: AttachmentResType,
scope?: PublicAttachmentScope,
): Promise<{ [key: string]: string }> { ): Promise<{ [key: string]: string }> {
const sharp = Noco.sharp; const sharp = Noco.sharp;
@ -53,6 +54,7 @@ export class ThumbnailGeneratorProcessor {
const { file, relativePath } = await this.getFileData( const { file, relativePath } = await this.getFileData(
attachment, attachment,
storageAdapter, storageAdapter,
scope,
); );
const thumbnailPaths = { const thumbnailPaths = {
@ -119,13 +121,14 @@ export class ThumbnailGeneratorProcessor {
private async getFileData( private async getFileData(
attachment: AttachmentResType, attachment: AttachmentResType,
storageAdapter: IStorageAdapterV2, storageAdapter: IStorageAdapterV2,
scope?: PublicAttachmentScope,
): Promise<{ file: Buffer; relativePath: string }> { ): Promise<{ file: Buffer; relativePath: string }> {
let relativePath; let relativePath;
if (attachment.path) { if (attachment.path) {
relativePath = path.join( relativePath = path.join(
'nc', 'nc',
'uploads', scope ? scope : 'uploads',
attachment.path.replace(/^download[/\\]/i, ''), attachment.path.replace(/^download[/\\]/i, ''),
); );
} else if (attachment.url) { } else if (attachment.url) {

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

@ -196,6 +196,7 @@ export class AttachmentsService {
workspace_id: RootScopes.ROOT, workspace_id: RootScopes.ROOT,
}, },
attachments: generateThumbnail, attachments: generateThumbnail,
scope: param.scope,
}); });
} }
@ -380,6 +381,7 @@ export class AttachmentsService {
workspace_id: RootScopes.ROOT, workspace_id: RootScopes.ROOT,
}, },
attachments: generateThumbnail, attachments: generateThumbnail,
scope: param.scope,
}); });
} }

Loading…
Cancel
Save