diff --git a/src/common/helper.ts b/src/common/helper.ts index 25ccb758..20134fd0 100644 --- a/src/common/helper.ts +++ b/src/common/helper.ts @@ -23,31 +23,28 @@ export async function solveAsyncProblem Promise true, + (arg) => arg?.commonFileInfo?.fileModelId === modelId, + 1, + timeout, + ); + return fileTransNotifyInfo.filePath; + } async downloadMedia(msgId: string, chatType: ChatType, peerUid: string, elementId: string, thumbPath: string, sourcePath: string, timeout = 1000 * 60 * 2, force: boolean = false) { //logDebug('receive downloadMedia task', msgId, chatType, peerUid, elementId, thumbPath, sourcePath, timeout, force); // 用于下载收到的消息中的图片等 diff --git a/src/core/listeners/NodeIKernelMsgListener.ts b/src/core/listeners/NodeIKernelMsgListener.ts index dcc75fde..0e15e4b8 100644 --- a/src/core/listeners/NodeIKernelMsgListener.ts +++ b/src/core/listeners/NodeIKernelMsgListener.ts @@ -1,5 +1,25 @@ import { ChatType, RawMessage } from '@/core/entities'; - +export interface CommonFileInfo { + bizType: null; + chatType: number; + elemId: string; + favId: null; + fileModelId: string; + fileName: string; + fileSize: string; + md5: string; + md510m: string; + msgId: string; + msgTime: string; + parent: null; + peerUid: string; + picThumbPath: null; + sha: string; + sha3: string; + subId: string; + uuid: string; + [property: string]: any; +} export interface OnRichMediaDownloadCompleteParams { fileModelId: string, msgElementId: string, @@ -15,7 +35,7 @@ export interface OnRichMediaDownloadCompleteParams { totalSize: string, trasferStatus: number, step: number, - commonFileInfo: unknown | null, + commonFileInfo?: CommonFileInfo, fileSrvErrCode: string, clientMsg: string, businessId: number, diff --git a/src/core/services/NodeIKernelRichMediaService.ts b/src/core/services/NodeIKernelRichMediaService.ts index e76761f2..b49bb896 100644 --- a/src/core/services/NodeIKernelRichMediaService.ts +++ b/src/core/services/NodeIKernelRichMediaService.ts @@ -155,7 +155,7 @@ export interface NodeIKernelRichMediaService { }): unknown; //arg3为“” - downloadFileForModelId(peer: Peer, ModelId: string[], arg3: string): unknown; + downloadFileForModelId(peer: Peer, ModelId: string[]): Promise; //第三个参数 Array // this.fileId = ""; diff --git a/src/onebot/action/file/GetFile.ts b/src/onebot/action/file/GetFile.ts index b0502d1d..78915265 100644 --- a/src/onebot/action/file/GetFile.ts +++ b/src/onebot/action/file/GetFile.ts @@ -32,18 +32,18 @@ export class GetFileBase extends BaseAction { const NTQQMsgApi = this.core.apis.MsgApi; const NTQQFileApi = this.core.apis.FileApi; - const contextFile = FileNapCatOneBotUUID.decode(payload.file); + const contextMsgFile = FileNapCatOneBotUUID.decode(payload.file); //接收消息标记模式 - if (contextFile) { - const { peer, msgId, elementId } = contextFile; + if (contextMsgFile) { + const { peer, msgId, elementId } = contextMsgFile; const downloadPath = await NTQQFileApi.downloadMedia(msgId, peer.chatType, peer.peerUid, elementId, '', ''); const mixElement = (await NTQQMsgApi.getMsgsByMsgId(peer, [msgId]))?.msgList .find(msg => msg.msgId === msgId)?.elements.find(e => e.elementId === elementId); - const mixElementInner = mixElement?.videoElement ?? mixElement?.fileElement ?? mixElement?.pttElement ?? mixElement?.picElement ; - if(!mixElementInner) throw new Error('element not found'); + const mixElementInner = mixElement?.videoElement ?? mixElement?.fileElement ?? mixElement?.pttElement ?? mixElement?.picElement; + if (!mixElementInner) throw new Error('element not found'); const fileSize = mixElementInner.fileSize?.toString() || ''; const fileName = mixElementInner.fileName || ''; @@ -65,7 +65,27 @@ export class GetFileBase extends BaseAction { return res; } //群文件模式 - + const contextModelIdFile = FileNapCatOneBotUUID.decodeModelId(payload.file); + if (contextModelIdFile) { + const { peer, modelId } = contextModelIdFile; + const downloadPath = await NTQQFileApi.downloadFileForModelId(peer, modelId); + const res: GetFileResponse = { + file: downloadPath, + url: downloadPath, + file_size: '', + file_name: '', + }; + + if (this.obContext.configLoader.configData.enableLocalFile2Url && downloadPath) { + try { + res.base64 = await fs.readFile(downloadPath, 'base64'); + } catch (e) { + throw new Error('文件下载失败. ' + e); + } + } + return res; + } + //搜索名字模式 const NTSearchNameResult = (await NTQQFileApi.searchfile([payload.file])).resultItems; if (NTSearchNameResult.length !== 0) {