From 7627c43deee3ef952b072b35cd5d2dc32eae48f7 Mon Sep 17 00:00:00 2001 From: tamaina Date: Thu, 20 Jan 2022 03:05:52 +0900 Subject: [PATCH] send-drive-file svg as png (#8107) --- packages/backend/src/server/file/send-drive-file.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/backend/src/server/file/send-drive-file.ts b/packages/backend/src/server/file/send-drive-file.ts index 7bfc36e25a..f3c6c518fa 100644 --- a/packages/backend/src/server/file/send-drive-file.ts +++ b/packages/backend/src/server/file/send-drive-file.ts @@ -11,7 +11,7 @@ import { DriveFiles } from '@/models/index'; import { InternalStorage } from '@/services/drive/internal-storage'; import { downloadUrl } from '@/misc/download-url'; import { detectType } from '@/misc/get-file-info'; -import { convertToJpeg, convertToPngOrJpeg } from '@/services/drive/image-processor'; +import { convertToJpeg, convertToPng, convertToPngOrJpeg } from '@/services/drive/image-processor'; import { GenerateVideoThumbnail } from '@/services/drive/generate-video-thumbnail'; import { StatusError } from '@/misc/fetch'; import { FILE_TYPE_BROWSERSAFE } from '@/const'; @@ -67,13 +67,19 @@ export default async function(ctx: Koa.Context) { if (isThumbnail) { if (['image/jpeg', 'image/webp'].includes(mime)) { return await convertToJpeg(path, 498, 280); - } else if (['image/png'].includes(mime)) { + } else if (['image/png', 'image/svg+xml'].includes(mime)) { return await convertToPngOrJpeg(path, 498, 280); } else if (mime.startsWith('video/')) { return await GenerateVideoThumbnail(path); } } + if (isWebpublic) { + if (['image/svg+xml'].includes(mime)) { + return await convertToPng(path, 2048, 2048); + } + } + return { data: fs.readFileSync(path), ext,