diff --git a/src/common/helper.ts b/src/common/helper.ts index 20134fd0..bc80626d 100644 --- a/src/common/helper.ts +++ b/src/common/helper.ts @@ -51,7 +51,7 @@ export class FileNapCatOneBotUUID { msgId: string, elementId: string } { - if (!uuid.startsWith('NapCatOneBot-File-')) return undefined; + if (!uuid.startsWith('NapCatOneBot-MsgFile-')) return undefined; const data = uuid.split('-'); if (data.length !== 6) return undefined; const [, , chatType, peerUid, msgId, elementId] = data; diff --git a/src/core/apis/file.ts b/src/core/apis/file.ts index 7f8a06d1..816e223f 100644 --- a/src/core/apis/file.ts +++ b/src/core/apis/file.ts @@ -356,17 +356,15 @@ export class NTQQFileApi { if (msg.msgList.length === 0) { return fileTransNotifyInfo.filePath; } - //获取原始消息 - const FileElements = msg?.msgList[0]?.elements?.find(e => e.elementId === elementId); - if (!FileElements) { - //失败则就乱来 Todo - return fileTransNotifyInfo.filePath; + const mixElement = msg.msgList.find((msg) => msg.msgId === msgId)?.elements.find((e) => e.elementId === elementId); + const mixElementInner = mixElement?.videoElement ?? mixElement?.fileElement ?? mixElement?.pttElement ?? mixElement?.picElement; + let realPath = mixElementInner?.filePath; + if (!realPath) { + let picThumbPath: Map = (mixElementInner as any)?.picThumbPath; + let picThumbPathList = Array.from(picThumbPath.values()); + if (picThumbPathList.length > 0) realPath = picThumbPathList[0]; } - //从原始消息获取文件路径 - return FileElements?.fileElement?.filePath ?? - FileElements?.pttElement?.filePath ?? - FileElements?.videoElement?.filePath ?? - FileElements?.picElement?.sourcePath; + return realPath; } async getImageSize(filePath: string): Promise { diff --git a/src/core/entities/msg.ts b/src/core/entities/msg.ts index 0168c81f..40e4a292 100644 --- a/src/core/entities/msg.ts +++ b/src/core/entities/msg.ts @@ -593,6 +593,7 @@ export const IMAGE_HTTP_HOST_NT = 'https://multimedia.nt.qq.com.cn'; export interface PicElement { md5HexStr?: string; + filePath?: string; fileSize: number | string;//number picWidth: number; picHeight: number; diff --git a/src/onebot/action/file/GetFile.ts b/src/onebot/action/file/GetFile.ts index 78915265..0e0b62f7 100644 --- a/src/onebot/action/file/GetFile.ts +++ b/src/onebot/action/file/GetFile.ts @@ -33,20 +33,16 @@ export class GetFileBase extends BaseAction { const NTQQFileApi = this.core.apis.FileApi; const contextMsgFile = FileNapCatOneBotUUID.decode(payload.file); - //接收消息标记模式 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 fileSize = mixElementInner.fileSize?.toString() || ''; - const fileName = mixElementInner.fileName || ''; + const fileSize = mixElementInner.fileSize?.toString() ?? ''; + const fileName = mixElementInner.fileName ?? ''; const res: GetFileResponse = { file: downloadPath,