From 30abe5bbc07a40af50cf5ace5781174d93f2144f Mon Sep 17 00:00:00 2001 From: Max Bischof Date: Thu, 2 Nov 2023 15:57:59 +0100 Subject: [PATCH] Generate preview for pdf --- .../files-storage/interface/preview-input-mime-types.enum.ts | 1 + .../infra/preview-generator/preview-generator.service.ts | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/apps/server/src/modules/files-storage/interface/preview-input-mime-types.enum.ts b/apps/server/src/modules/files-storage/interface/preview-input-mime-types.enum.ts index 495096c8359..20c24b65fd1 100644 --- a/apps/server/src/modules/files-storage/interface/preview-input-mime-types.enum.ts +++ b/apps/server/src/modules/files-storage/interface/preview-input-mime-types.enum.ts @@ -8,4 +8,5 @@ export enum PreviewInputMimeTypes { IMAGE_HEIF = 'image/heif', IMAGE_TIFF = 'image/tiff', IMAGE_WEBP = 'image/webp', + APPLICATION_PDF = 'application/pdf', } diff --git a/apps/server/src/shared/infra/preview-generator/preview-generator.service.ts b/apps/server/src/shared/infra/preview-generator/preview-generator.service.ts index 72dac25f076..a12fed2517d 100644 --- a/apps/server/src/shared/infra/preview-generator/preview-generator.service.ts +++ b/apps/server/src/shared/infra/preview-generator/preview-generator.service.ts @@ -1,6 +1,7 @@ import { Injectable } from '@nestjs/common'; import { GetFile, S3ClientAdapter } from '@shared/infra/s3-client'; import { Logger } from '@src/core/logger'; +import { PreviewInputMimeTypes } from '@src/modules/files-storage/interface'; import { subClass } from 'gm'; import { PassThrough } from 'stream'; import { PreviewFileOptions, PreviewOptions, PreviewResponseMessage } from './interface'; @@ -45,6 +46,10 @@ export class PreviewGeneratorService { const preview = this.imageMagick(original.data); + if (original.contentType === PreviewInputMimeTypes.APPLICATION_PDF) { + preview.selectFrame(0); + } + if (width) { preview.resize(width, undefined, '>'); }