fix(protocol): preserve sent media for message history

Keep media sent by the bot available for later history and forwarding,
including messages without a server echo.

Fixes #462
This commit is contained in:
DrSmoothl committed 2026-10-04 14:00:03 +08:00
1 parent 3068d3ef60
commit d86e0fc7b5
6 files changed
+51 -5

No files matched your search

@@ -182,5 +182,12 @@ export async function uploadImageMsgInfo(
label: 'image',
});
return finalizeMediaMsgInfo(upload, pic);
const encoded = finalizeMediaMsgInfo(upload, pic);
// Retain successful upload metadata for the caller's self-sent history.
Object.assign(element, {
md5Hex: image.md5Hex, sha1Hex: image.sha1Hex, fileSize: image.fileSize,
fileName: image.fileName, width: image.width, height: image.height,
picFormat: image.picFormat, subType: image.subType, summary: image.summary,
});
return encoded;
}
+8 -1
View File
@@ -240,7 +240,14 @@ export async function uploadPttMsgInfo(
});
mergePttWaveform(upload, ptt.waveform);
return finalizeMediaMsgInfo(upload);
const encoded = finalizeMediaMsgInfo(upload);
const mediaNode = upload.msgInfo?.msgInfoBody?.[0]?.index;
Object.assign(element, {
md5Hex: ptt.md5Hex, sha1Hex: ptt.sha1Hex, fileSize: ptt.fileSize,
fileName: ptt.fileName, duration: ptt.duration, voiceFormat: ptt.voiceFormat,
fileId: mediaNode?.fileUuid, mediaNode,
});
return encoded;
} finally {
for (const fn of ptt.cleanups) {
try { fn(); } catch { /* best-effort cleanup */ }
@@ -437,7 +437,14 @@ export async function uploadVideoMsgInfo(
});
log.debug('video upload completed: md5=%s scene=%s', video.md5Hex, isGroup ? 'group' : 'c2c');
return finalizeMediaMsgInfo(upload);
const encoded = finalizeMediaMsgInfo(upload);
const mediaNode = upload.msgInfo?.msgInfoBody?.[0]?.index;
Object.assign(element, {
md5Hex: video.md5Hex, sha1Hex: video.sha1Hex, fileSize: video.fileSize,
fileName: 'nya.mp4', duration: video.duration, width: video.width, height: video.height, videoFormat: 0,
fileId: mediaNode?.fileUuid, mediaNode,
});
return encoded;
} finally {
await video.cleanup();
}