feat: support node id in fake forward (with auto download richMedia in reference message)

This commit is contained in:
pk5ls20 2024-10-27 06:50:59 +08:00
parent 0be6effc32
commit 9f07b07c82
No known key found for this signature in database
GPG Key ID: 6370ED7A169F493A
2 changed files with 25 additions and 0 deletions

View File

@ -6,6 +6,7 @@ import {
Peer,
PicElement,
PicType,
RawMessage,
SendFileElement,
SendPicElement,
SendPttElement,
@ -267,6 +268,29 @@ export class NTQQFileApi {
return fileTransNotifyInfo.filePath;
}
async downloadRawMsgMedia(msg: RawMessage[]) {
const res = await Promise.all(msg.map(m =>
this.downloadMedia(m.msgId, m.chatType, m.peerUid, m.elements[0].elementId, '', '', 1000 * 60 * 2, true)
));
msg.forEach((m, index) => {
const element = m.elements[0];
switch (element.elementType) {
case ElementType.PIC:
element.picElement!.sourcePath = res[index];
break;
case ElementType.VIDEO:
element.videoElement!.filePath = res[index];
break;
case ElementType.PTT:
element.pttElement!.filePath = res[index];
break;
case ElementType.FILE:
element.fileElement!.filePath = res[index];
break;
}
});
}
async downloadMedia(msgId: string, chatType: ChatType, peerUid: string, elementId: string, thumbPath: string, sourcePath: string, timeout = 1000 * 60 * 2, force: boolean = false) {
// 用于下载收到的消息中的图片等
if (sourcePath && fs.existsSync(sourcePath)) {

View File

@ -203,6 +203,7 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
}
const msg = (await this.core.apis.MsgApi.getMsgsByMsgId(nodeMsg.Peer, [nodeMsg.MsgId])).msgList[0];
logger.logDebug(`handleForwardedNodesPacket[PureRaw] 开始转换 ${JSON.stringify(msg)}`);
await this.core.apis.FileApi.downloadRawMsgMedia([msg]);
const transformedMsg = this.core.apis.PacketApi.packetSession?.packer.packetConverter.rawMsgToPacketMsg(msg);
logger.logDebug(`handleForwardedNodesPacket[PureRaw] 转换为 ${JSON.stringify(transformedMsg)}`);
packetMsg.push(transformedMsg!);