fix(backend/DriveService): variationが付いたMIMEを正常にパースできるように (MisskeyIO#942)

This commit is contained in:
まっちゃてぃー。 2025-03-18 03:21:18 +09:00 committed by GitHub
parent d13ec4c5fd
commit 7a94724098
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -146,8 +146,10 @@ export class DriveService {
*/ */
@bindThis @bindThis
private async save(file: MiDriveFile, path: string, name: string, type: string, hash: string, size: number): Promise<MiDriveFile> { private async save(file: MiDriveFile, path: string, name: string, type: string, hash: string, size: number): Promise<MiDriveFile> {
// thunbnail, webpublic を必要なら生成 const fileType = type.split(';')[0];
const alts = await this.generateAlts(path, type, !file.uri);
// thunbnail, webpublic を必要なら生成
const alts = await this.generateAlts(path, fileType, !file.uri);
const meta = await this.metaService.fetch(); const meta = await this.metaService.fetch();
@ -156,17 +158,17 @@ export class DriveService {
let [ext] = (name.match(/\.([a-zA-Z0-9_-]+)$/) ?? ['']); let [ext] = (name.match(/\.([a-zA-Z0-9_-]+)$/) ?? ['']);
if (ext === '') { if (ext === '') {
if (type === 'image/jpeg') ext = '.jpg'; if (fileType === 'image/jpeg') ext = '.jpg';
if (type === 'image/png') ext = '.png'; if (fileType === 'image/png') ext = '.png';
if (type === 'image/webp') ext = '.webp'; if (fileType === 'image/webp') ext = '.webp';
if (type === 'image/avif') ext = '.avif'; if (fileType === 'image/avif') ext = '.avif';
if (type === 'image/apng') ext = '.apng'; if (fileType === 'image/apng') ext = '.apng';
if (type === 'image/vnd.mozilla.apng') ext = '.apng'; if (fileType === 'image/vnd.mozilla.apng') ext = '.apng';
} }
// 拡張子からContent-Typeを設定してそうな挙動を示すオブジェクトストレージ (upcloud?) も存在するので、 // 拡張子からContent-Typeを設定してそうな挙動を示すオブジェクトストレージ (upcloud?) も存在するので、
// 許可されているファイル形式でしかURLに拡張子をつけない // 許可されているファイル形式でしかURLに拡張子をつけない
if (!FILE_TYPE_BROWSERSAFE.includes(type)) { if (!FILE_TYPE_BROWSERSAFE.includes(fileType)) {
ext = ''; ext = '';
} }
@ -373,8 +375,10 @@ export class DriveService {
*/ */
@bindThis @bindThis
private async upload(key: string, stream: fs.ReadStream | Buffer, type: string, ext?: string | null, filename?: string) { private async upload(key: string, stream: fs.ReadStream | Buffer, type: string, ext?: string | null, filename?: string) {
if (type === 'image/apng') type = 'image/png'; const fileType = type.split(';')[0];
if (!FILE_TYPE_BROWSERSAFE.includes(type)) type = 'application/octet-stream';
if (fileType === 'image/apng') type = 'image/png';
if (!FILE_TYPE_BROWSERSAFE.includes(fileType)) type = 'application/octet-stream';
const meta = await this.metaService.fetch(); const meta = await this.metaService.fetch();