summaryrefslogtreecommitdiff
path: root/packages/backend/src/core/FileInfoService.ts
diff options
context:
space:
mode:
authorsyuilo <4439005+syuilo@users.noreply.github.com>2025-05-24 14:28:49 +0900
committersyuilo <4439005+syuilo@users.noreply.github.com>2025-05-24 14:28:49 +0900
commit4fcb80bcf22f044193856e5394bebaf2c3a9af96 (patch)
tree27c11afdf8a098683fa1819677adb894005c26cc /packages/backend/src/core/FileInfoService.ts
parentUpdate CHANGELOG.md (diff)
downloadmisskey-4fcb80bcf22f044193856e5394bebaf2c3a9af96.tar.gz
misskey-4fcb80bcf22f044193856e5394bebaf2c3a9af96.tar.bz2
misskey-4fcb80bcf22f044193856e5394bebaf2c3a9af96.zip
enhance(backend): ファイル種別が判定できない場合、拡張子を参照するように
Diffstat (limited to 'packages/backend/src/core/FileInfoService.ts')
-rw-r--r--packages/backend/src/core/FileInfoService.ts33
1 files changed, 27 insertions, 6 deletions
diff --git a/packages/backend/src/core/FileInfoService.ts b/packages/backend/src/core/FileInfoService.ts
index a295e81920..6250d4d3a1 100644
--- a/packages/backend/src/core/FileInfoService.ts
+++ b/packages/backend/src/core/FileInfoService.ts
@@ -64,6 +64,7 @@ export class FileInfoService {
*/
@bindThis
public async getFileInfo(path: string, opts: {
+ fileName?: string | null;
skipSensitiveDetection: boolean;
sensitiveThreshold?: number;
sensitiveThresholdForPorn?: number;
@@ -76,6 +77,26 @@ export class FileInfoService {
let type = await this.detectType(path);
+ if (type.mime === TYPE_OCTET_STREAM.mime && opts.fileName != null) {
+ const ext = opts.fileName.split('.').pop();
+ if (ext === 'txt') {
+ type = {
+ mime: 'text/plain',
+ ext: 'txt',
+ };
+ } else if (ext === 'csv') {
+ type = {
+ mime: 'text/csv',
+ ext: 'csv',
+ };
+ } else if (ext === 'json') {
+ type = {
+ mime: 'application/json',
+ ext: 'json',
+ };
+ }
+ }
+
// image dimensions
let width: number | undefined;
let height: number | undefined;
@@ -438,12 +459,12 @@ export class FileInfoService {
*/
@bindThis
private async detectImageSize(path: string): Promise<{
- width: number;
- height: number;
- wUnits: string;
- hUnits: string;
- orientation?: number;
-}> {
+ width: number;
+ height: number;
+ wUnits: string;
+ hUnits: string;
+ orientation?: number;
+ }> {
const readable = fs.createReadStream(path);
const imageSize = await probeImageSize(readable);
readable.destroy();