Skip to content

Commit

Permalink
ビデオプレイヤーの差し替え (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
nacika-ins authored Sep 19, 2024
2 parents a55dc3b + f4cd8d8 commit dbf47e9
Show file tree
Hide file tree
Showing 22 changed files with 2,298 additions and 1,146 deletions.
5 changes: 5 additions & 0 deletions packages/backend/src/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,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',
];
Expand Down
25 changes: 19 additions & 6 deletions packages/backend/src/core/FileInfoService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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かもしれない
Expand All @@ -324,7 +337,7 @@ export class FileInfoService {
}

return {
mime: type.mime,
mime: this.fixMime(type.mime),
ext: type.ext,
};
}
Expand Down
9 changes: 9 additions & 0 deletions packages/backend/src/misc/fastify-hook-handlers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type { onRequestHookHandler } from 'fastify';

export const handleRequestRedirectToOmitSearch: onRequestHookHandler = (request, reply, done) => {
const index = request.url.indexOf('?');
if (~index) {
reply.redirect(301, request.url.slice(0, index));
}
done();
};
Loading

0 comments on commit dbf47e9

Please sign in to comment.