This commit is contained in:
tamaina
2023-05-10 13:17:35 +00:00
parent 6bf5fbd794
commit 0e79a81f3d
6 changed files with 215 additions and 177 deletions

View File

@ -36,6 +36,11 @@ export const FILE_TYPE_BROWSERSAFE = [
'audio/webm',
'audio/aac',
// see https://github.com/misskey-dev/misskey/pull/10686
'audio/flac',
'audio/wav',
// backward compatibility
'audio/x-flac',
'audio/vnd.wave',
];

View File

@ -1,5 +1,6 @@
import fs from 'node:fs';
import { fileTypeFromFile } from 'file-type';
import type fileType from 'file-type';
import isSvg from 'is-svg';
import { promisify } from 'node:util';
@ -39,7 +40,7 @@ export async function detectType(path: string): Promise<{
}
return {
mime: type.mime,
mime: fixMime(type.mime),
ext: type.ext,
};
}
@ -71,3 +72,15 @@ const dictionary = {
};
export const isMimeImage = (mime: string, type: keyof typeof dictionary): boolean => dictionary[type].includes(mime);
function fixMime(mime: string | fileType.MimeType): string {
// see https://github.com/misskey-dev/misskey/pull/10686
if (mime === "audio/x-flac") {
return "audio/flac";
}
if (mime === "audio/vnd.wave") {
return "audio/wav";
}
return mime;
}