summaryrefslogtreecommitdiff
path: root/packages/backend/src/core/FileInfoService.ts
diff options
context:
space:
mode:
authorYuriha <121590760+yuriha-chan@users.noreply.github.com>2023-04-26 02:17:58 +0900
committerGitHub <noreply@github.com>2023-04-26 02:17:58 +0900
commita986203b38db243147590498bae82c53517d1c70 (patch)
tree1365a72a203c96cd556eef4f2909b711472ce7d7 /packages/backend/src/core/FileInfoService.ts
parentfix (diff)
downloadmisskey-a986203b38db243147590498bae82c53517d1c70.tar.gz
misskey-a986203b38db243147590498bae82c53517d1c70.tar.bz2
misskey-a986203b38db243147590498bae82c53517d1c70.zip
[fix] .wav .flac ファイルを再生可能にする (#10686)
* .wav .flac ファイルを再生可能にする file-typeにより判定されたMIME TypeをHTML5 Audio/Video要素に認識されるものに書き換える * fix typecheck error * frontend側の FILE_TYPE_BROWSERSAFEも更新 * Update packages/backend/src/core/FileInfoService.ts * :v: * 後方互換を確保 * add tests * update changelog.md --------- Co-authored-by: tamaina <tamaina@hotmail.co.jp>
Diffstat (limited to 'packages/backend/src/core/FileInfoService.ts')
-rw-r--r--packages/backend/src/core/FileInfoService.ts25
1 files changed, 19 insertions, 6 deletions
diff --git a/packages/backend/src/core/FileInfoService.ts b/packages/backend/src/core/FileInfoService.ts
index e39b134b7e..b6cae5ea75 100644
--- a/packages/backend/src/core/FileInfoService.ts
+++ b/packages/backend/src/core/FileInfoService.ts
@@ -5,7 +5,7 @@ import * as stream from 'node:stream';
import * as util from 'node:util';
import { Injectable } from '@nestjs/common';
import { FSWatcher } from 'chokidar';
-import { fileTypeFromFile } from 'file-type';
+import * as fileType from 'file-type';
import FFmpeg from 'fluent-ffmpeg';
import isSvg from 'is-svg';
import probeImageSize from 'probe-image-size';
@@ -301,21 +301,34 @@ export class FileInfoService {
return fs.promises.access(path).then(() => true, () => false);
}
+ @bindThis
+ public 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;
+ }
+
/**
* Detect MIME Type and extension
*/
@bindThis
public async detectType(path: string): Promise<{
- mime: string;
- ext: string | null;
-}> {
+ mime: string;
+ ext: string | null;
+ }> {
// Check 0 byte
const fileSize = await this.getFileSize(path);
if (fileSize === 0) {
return TYPE_OCTET_STREAM;
}
- const type = await fileTypeFromFile(path);
+ const type = await fileType.fileTypeFromFile(path);
if (type) {
// XMLはSVGかもしれない
@@ -324,7 +337,7 @@ export class FileInfoService {
}
return {
- mime: type.mime,
+ mime: this.fixMime(type.mime),
ext: type.ext,
};
}