mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2024-11-21 09:36:35 +00:00
fix: getfile
This commit is contained in:
parent
a598266a6e
commit
a2fa085d5f
@ -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;
|
||||
|
@ -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<number, string> = (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<ISizeCalculationResult | undefined> {
|
||||
|
@ -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;
|
||||
|
@ -33,20 +33,16 @@ export class GetFileBase extends BaseAction<GetFilePayload, GetFileResponse> {
|
||||
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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user