From 7a947240981e757cc4cb45a77ef48d5e3f9e835c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=BE=E3=81=A3=E3=81=A1=E3=82=83=E3=81=A6=E3=81=83?= =?UTF-8?q?=E3=83=BC=E3=80=82?= <56515516+mattyatea@users.noreply.github.com> Date: Tue, 18 Mar 2025 03:21:18 +0900 Subject: [PATCH] =?UTF-8?q?fix(backend/DriveService):=20variation=E3=81=8C?= =?UTF-8?q?=E4=BB=98=E3=81=84=E3=81=9FMIME=E3=82=92=E6=AD=A3=E5=B8=B8?= =?UTF-8?q?=E3=81=AB=E3=83=91=E3=83=BC=E3=82=B9=E3=81=A7=E3=81=8D=E3=82=8B?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AB=20(MisskeyIO#942)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/backend/src/core/DriveService.ts | 26 +++++++++++++---------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/packages/backend/src/core/DriveService.ts b/packages/backend/src/core/DriveService.ts index a68fc25ab..a1d06a1d8 100644 --- a/packages/backend/src/core/DriveService.ts +++ b/packages/backend/src/core/DriveService.ts @@ -146,8 +146,10 @@ export class DriveService { */ @bindThis private async save(file: MiDriveFile, path: string, name: string, type: string, hash: string, size: number): Promise { - // thunbnail, webpublic を必要なら生成 - const alts = await this.generateAlts(path, type, !file.uri); + const fileType = type.split(';')[0]; + + // thunbnail, webpublic を必要なら生成 + const alts = await this.generateAlts(path, fileType, !file.uri); const meta = await this.metaService.fetch(); @@ -156,17 +158,17 @@ export class DriveService { let [ext] = (name.match(/\.([a-zA-Z0-9_-]+)$/) ?? ['']); if (ext === '') { - if (type === 'image/jpeg') ext = '.jpg'; - if (type === 'image/png') ext = '.png'; - if (type === 'image/webp') ext = '.webp'; - if (type === 'image/avif') ext = '.avif'; - if (type === 'image/apng') ext = '.apng'; - if (type === 'image/vnd.mozilla.apng') ext = '.apng'; + if (fileType === 'image/jpeg') ext = '.jpg'; + if (fileType === 'image/png') ext = '.png'; + if (fileType === 'image/webp') ext = '.webp'; + if (fileType === 'image/avif') ext = '.avif'; + if (fileType === 'image/apng') ext = '.apng'; + if (fileType === 'image/vnd.mozilla.apng') ext = '.apng'; } // 拡張子からContent-Typeを設定してそうな挙動を示すオブジェクトストレージ (upcloud?) も存在するので、 // 許可されているファイル形式でしかURLに拡張子をつけない - if (!FILE_TYPE_BROWSERSAFE.includes(type)) { + if (!FILE_TYPE_BROWSERSAFE.includes(fileType)) { ext = ''; } @@ -373,8 +375,10 @@ export class DriveService { */ @bindThis private async upload(key: string, stream: fs.ReadStream | Buffer, type: string, ext?: string | null, filename?: string) { - if (type === 'image/apng') type = 'image/png'; - if (!FILE_TYPE_BROWSERSAFE.includes(type)) type = 'application/octet-stream'; + const fileType = type.split(';')[0]; + + if (fileType === 'image/apng') type = 'image/png'; + if (!FILE_TYPE_BROWSERSAFE.includes(fileType)) type = 'application/octet-stream'; const meta = await this.metaService.fetch();