fix: getfile

This commit is contained in:
手瓜一十雪 2024-08-29 20:14:20 +08:00
parent a598266a6e
commit a2fa085d5f
4 changed files with 12 additions and 17 deletions

View File

@ -51,7 +51,7 @@ export class FileNapCatOneBotUUID {
msgId: string, msgId: string,
elementId: string elementId: string
} { } {
if (!uuid.startsWith('NapCatOneBot-File-')) return undefined; if (!uuid.startsWith('NapCatOneBot-MsgFile-')) return undefined;
const data = uuid.split('-'); const data = uuid.split('-');
if (data.length !== 6) return undefined; if (data.length !== 6) return undefined;
const [, , chatType, peerUid, msgId, elementId] = data; const [, , chatType, peerUid, msgId, elementId] = data;

View File

@ -356,17 +356,15 @@ export class NTQQFileApi {
if (msg.msgList.length === 0) { if (msg.msgList.length === 0) {
return fileTransNotifyInfo.filePath; return fileTransNotifyInfo.filePath;
} }
//获取原始消息 const mixElement = msg.msgList.find((msg) => msg.msgId === msgId)?.elements.find((e) => e.elementId === elementId);
const FileElements = msg?.msgList[0]?.elements?.find(e => e.elementId === elementId); const mixElementInner = mixElement?.videoElement ?? mixElement?.fileElement ?? mixElement?.pttElement ?? mixElement?.picElement;
if (!FileElements) { let realPath = mixElementInner?.filePath;
//失败则就乱来 Todo if (!realPath) {
return fileTransNotifyInfo.filePath; let picThumbPath: Map<number, string> = (mixElementInner as any)?.picThumbPath;
let picThumbPathList = Array.from(picThumbPath.values());
if (picThumbPathList.length > 0) realPath = picThumbPathList[0];
} }
//从原始消息获取文件路径 return realPath;
return FileElements?.fileElement?.filePath ??
FileElements?.pttElement?.filePath ??
FileElements?.videoElement?.filePath ??
FileElements?.picElement?.sourcePath;
} }
async getImageSize(filePath: string): Promise<ISizeCalculationResult | undefined> { async getImageSize(filePath: string): Promise<ISizeCalculationResult | undefined> {

View File

@ -593,6 +593,7 @@ export const IMAGE_HTTP_HOST_NT = 'https://multimedia.nt.qq.com.cn';
export interface PicElement { export interface PicElement {
md5HexStr?: string; md5HexStr?: string;
filePath?: string;
fileSize: number | string;//number fileSize: number | string;//number
picWidth: number; picWidth: number;
picHeight: number; picHeight: number;

View File

@ -33,20 +33,16 @@ export class GetFileBase extends BaseAction<GetFilePayload, GetFileResponse> {
const NTQQFileApi = this.core.apis.FileApi; const NTQQFileApi = this.core.apis.FileApi;
const contextMsgFile = FileNapCatOneBotUUID.decode(payload.file); const contextMsgFile = FileNapCatOneBotUUID.decode(payload.file);
//接收消息标记模式 //接收消息标记模式
if (contextMsgFile) { if (contextMsgFile) {
const { peer, msgId, elementId } = contextMsgFile; const { peer, msgId, elementId } = contextMsgFile;
const downloadPath = await NTQQFileApi.downloadMedia(msgId, peer.chatType, peer.peerUid, elementId, '', ''); const downloadPath = await NTQQFileApi.downloadMedia(msgId, peer.chatType, peer.peerUid, elementId, '', '');
const mixElement = (await NTQQMsgApi.getMsgsByMsgId(peer, [msgId]))?.msgList const mixElement = (await NTQQMsgApi.getMsgsByMsgId(peer, [msgId]))?.msgList
.find(msg => msg.msgId === msgId)?.elements.find(e => e.elementId === elementId); .find(msg => msg.msgId === msgId)?.elements.find(e => e.elementId === elementId);
const mixElementInner = mixElement?.videoElement ?? mixElement?.fileElement ?? mixElement?.pttElement ?? mixElement?.picElement; const mixElementInner = mixElement?.videoElement ?? mixElement?.fileElement ?? mixElement?.pttElement ?? mixElement?.picElement;
if (!mixElementInner) throw new Error('element not found'); if (!mixElementInner) throw new Error('element not found');
const fileSize = mixElementInner.fileSize?.toString() ?? '';
const fileSize = mixElementInner.fileSize?.toString() || ''; const fileName = mixElementInner.fileName ?? '';
const fileName = mixElementInner.fileName || '';
const res: GetFileResponse = { const res: GetFileResponse = {
file: downloadPath, file: downloadPath,