From 9ab776d53a8e5a97cc9b153518f50a55f6cccd8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=8B=E7=93=9C=E4=B8=80=E5=8D=81=E9=9B=AA?= Date: Wed, 19 Mar 2025 11:54:29 +0800 Subject: [PATCH 1/4] fix: moduleResolution --- src/core/apis/file.ts | 2 +- tsconfig.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/apis/file.ts b/src/core/apis/file.ts index d28d64d1..2a02e031 100644 --- a/src/core/apis/file.ts +++ b/src/core/apis/file.ts @@ -26,7 +26,7 @@ import { SendMessageContext } from '@/onebot/api'; import { getFileTypeForSendType } from '../helper/msg'; import { FFmpegService } from '@/common/ffmpeg'; import { rkeyDataType } from '../types/file'; -import { imageSizeFromFile } from 'image-size/dist/fromFile' +import { imageSizeFromFile } from 'image-size/fromFile' export class NTQQFileApi { context: InstanceContext; diff --git a/tsconfig.json b/tsconfig.json index 8e2fcaed..6f209645 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,7 +9,7 @@ "DOM.Iterable" ], "skipLibCheck": true, - "moduleResolution": "Node", + "moduleResolution": "bundler", "experimentalDecorators": true, "allowImportingTsExtensions": false, "allowSyntheticDefaultImports": true, From 129b67b751c57c02f68ceb52ad25abadaf8d6d4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=8B=E7=93=9C=E4=B8=80=E5=8D=81=E9=9B=AA?= Date: Wed, 19 Mar 2025 11:57:55 +0800 Subject: [PATCH 2/4] Revert "chore(deps-dev): bump image-size from 1.2.0 to 2.0.1" This reverts commit e3feb6a73c82523864cb2a1b6092077d6ff1164e. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index aed0c71a..e72a4e99 100644 --- a/package.json +++ b/package.json @@ -51,7 +51,7 @@ "fast-xml-parser": "^4.3.6", "file-type": "^20.0.0", "globals": "^16.0.0", - "image-size": "^2.0.1", + "image-size": "^1.1.1", "json5": "^2.2.3", "multer": "^1.4.5-lts.1", "typescript": "^5.3.3", From dce4eedf7df1282eaf3535de5f51f4cd7c67e5f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=8B=E7=93=9C=E4=B8=80=E5=8D=81=E9=9B=AA?= Date: Wed, 19 Mar 2025 11:58:16 +0800 Subject: [PATCH 3/4] Revert "fix: moduleResolution" This reverts commit 9ab776d53a8e5a97cc9b153518f50a55f6cccd8a. --- src/core/apis/file.ts | 2 +- tsconfig.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/apis/file.ts b/src/core/apis/file.ts index 2a02e031..d28d64d1 100644 --- a/src/core/apis/file.ts +++ b/src/core/apis/file.ts @@ -26,7 +26,7 @@ import { SendMessageContext } from '@/onebot/api'; import { getFileTypeForSendType } from '../helper/msg'; import { FFmpegService } from '@/common/ffmpeg'; import { rkeyDataType } from '../types/file'; -import { imageSizeFromFile } from 'image-size/fromFile' +import { imageSizeFromFile } from 'image-size/dist/fromFile' export class NTQQFileApi { context: InstanceContext; diff --git a/tsconfig.json b/tsconfig.json index 6f209645..8e2fcaed 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,7 +9,7 @@ "DOM.Iterable" ], "skipLibCheck": true, - "moduleResolution": "bundler", + "moduleResolution": "Node", "experimentalDecorators": true, "allowImportingTsExtensions": false, "allowSyntheticDefaultImports": true, From 4ab751696b3e78ad2bb3c2c0fa49e4b202810833 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=8B=E7=93=9C=E4=B8=80=E5=8D=81=E9=9B=AA?= Date: Wed, 19 Mar 2025 11:58:19 +0800 Subject: [PATCH 4/4] Revert "fix: image size" This reverts commit 2759a34d96b741cc5733728e4146d0d02995932a. --- src/core/apis/file.ts | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/src/core/apis/file.ts b/src/core/apis/file.ts index d28d64d1..f058a15a 100644 --- a/src/core/apis/file.ts +++ b/src/core/apis/file.ts @@ -17,6 +17,8 @@ import fs from 'fs'; import fsPromises from 'fs/promises'; import { InstanceContext, NapCatCore, SearchResultItem } from '@/core'; import { fileTypeFromFile } from 'file-type'; +import imageSize from 'image-size'; +import { ISizeCalculationResult } from 'image-size/dist/types/interface'; import { RkeyManager } from '@/core/helper/rkey'; import { calculateFileMD5 } from '@/common/file'; import pathLib from 'node:path'; @@ -26,7 +28,6 @@ import { SendMessageContext } from '@/onebot/api'; import { getFileTypeForSendType } from '../helper/msg'; import { FFmpegService } from '@/common/ffmpeg'; import { rkeyDataType } from '../types/file'; -import { imageSizeFromFile } from 'image-size/dist/fromFile' export class NTQQFileApi { context: InstanceContext; @@ -43,7 +44,7 @@ export class NTQQFileApi { 'https://ss.xingzhige.com/music_card/rkey', // 国内 'https://secret-service.bietiaop.com/rkeys',//国内 ], - this.context.logger + this.context.logger ); } @@ -136,7 +137,7 @@ export class NTQQFileApi { if (fileSize === 0) { throw new Error('文件异常,大小为0'); } - const imageSize = await imageSizeFromFile(picPath); + const imageSize = await this.core.apis.FileApi.getImageSize(picPath); context.deleteAfterSentFiles.push(path); return { elementType: ElementType.PIC, @@ -300,18 +301,18 @@ export class NTQQFileApi { element.elementType === ElementType.FILE ) { switch (element.elementType) { - case ElementType.PIC: + case ElementType.PIC: element.picElement!.sourcePath = elementResults?.[elementIndex] ?? ''; - break; - case ElementType.VIDEO: + break; + case ElementType.VIDEO: element.videoElement!.filePath = elementResults?.[elementIndex] ?? ''; - break; - case ElementType.PTT: + break; + case ElementType.PTT: element.pttElement!.filePath = elementResults?.[elementIndex] ?? ''; - break; - case ElementType.FILE: + break; + case ElementType.FILE: element.fileElement!.filePath = elementResults?.[elementIndex] ?? ''; - break; + break; } elementIndex++; } @@ -355,6 +356,20 @@ export class NTQQFileApi { return completeRetData.filePath; } + async getImageSize(filePath: string): Promise { + return new Promise((resolve, reject) => { + imageSize(filePath, (err: Error | null, dimensions) => { + if (err) { + reject(new Error(err.message)); + } else if (!dimensions) { + reject(new Error('获取图片尺寸失败')); + } else { + resolve(dimensions); + } + }); + }); + } + async searchForFile(keys: string[]): Promise { const randomResultId = 100000 + Math.floor(Math.random() * 10000); let searchId = 0;