|
|
@ -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) { |
|
|
|