summaryrefslogtreecommitdiff
path: root/packages/backend/src/core/FileInfoService.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/backend/src/core/FileInfoService.ts')
-rw-r--r--packages/backend/src/core/FileInfoService.ts29
1 files changed, 15 insertions, 14 deletions
diff --git a/packages/backend/src/core/FileInfoService.ts b/packages/backend/src/core/FileInfoService.ts
index b6cae5ea75..d43575b336 100644
--- a/packages/backend/src/core/FileInfoService.ts
+++ b/packages/backend/src/core/FileInfoService.ts
@@ -161,20 +161,20 @@ export class FileInfoService {
private async detectSensitivity(source: string, mime: string, sensitiveThreshold: number, sensitiveThresholdForPorn: number, analyzeVideo: boolean): Promise<[sensitive: boolean, porn: boolean]> {
let sensitive = false;
let porn = false;
-
+
function judgePrediction(result: readonly predictionType[]): [sensitive: boolean, porn: boolean] {
let sensitive = false;
let porn = false;
-
+
if ((result.find(x => x.className === 'Sexy')?.probability ?? 0) > sensitiveThreshold) sensitive = true;
if ((result.find(x => x.className === 'Hentai')?.probability ?? 0) > sensitiveThreshold) sensitive = true;
if ((result.find(x => x.className === 'Porn')?.probability ?? 0) > sensitiveThreshold) sensitive = true;
-
+
if ((result.find(x => x.className === 'Porn')?.probability ?? 0) > sensitiveThresholdForPorn) porn = true;
-
+
return [sensitive, porn];
}
-
+
if ([
'image/jpeg',
'image/png',
@@ -253,10 +253,10 @@ export class FileInfoService {
disposeOutDir();
}
}
-
+
return [sensitive, porn];
}
-
+
private async *asyncIterateFrames(cwd: string, command: FFmpeg.FfmpegCommand): AsyncGenerator<string, void> {
const watcher = new FSWatcher({
cwd,
@@ -295,7 +295,7 @@ export class FileInfoService {
}
}
}
-
+
@bindThis
private exists(path: string): Promise<boolean> {
return fs.promises.access(path).then(() => true, () => false);
@@ -304,11 +304,11 @@ export class FileInfoService {
@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/x-flac') {
+ return 'audio/flac';
}
- if (mime === "audio/vnd.wave") {
- return "audio/wav";
+ if (mime === 'audio/vnd.wave') {
+ return 'audio/wav';
}
return mime;
@@ -355,11 +355,12 @@ export class FileInfoService {
* Check the file is SVG or not
*/
@bindThis
- public async checkSvg(path: string) {
+ public async checkSvg(path: string): Promise<boolean> {
try {
const size = await this.getFileSize(path);
if (size > 1 * 1024 * 1024) return false;
- return isSvg(fs.readFileSync(path));
+ const buffer = await fs.promises.readFile(path);
+ return isSvg(buffer.toString());
} catch {
return false;
}