Browse Source

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

pull/9722/head
Ramesh Mane 6 days 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 '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,
)

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 { WorkspaceIconType } from '#imports'
import 'emoji-mart-vue-fast/css/emoji-mart.css'
import { PublicAttachmentScope } from 'nocodb-sdk'
interface Props {
icon: string | Record<string, any>
@ -104,6 +105,7 @@ const imageCropperData = ref({
},
uploadConfig: {
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';
export const JOBS_QUEUE = 'jobs';
@ -161,4 +161,5 @@ export interface DataExportJobData extends JobData {
export interface ThumbnailGeneratorJobData extends JobData {
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 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<ThumbnailGeneratorJobData>) {
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) {

2
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,
});
}

Loading…
Cancel
Save