fix(onebot): sign forward-msg media + pick image rkey by appid (#74)
/get_forward_msg returned raw, rkey-less image/media URLs because getForwardMessage converted forward nodes WITHOUT the URL resolvers the normal receive path (to-message.ts) uses. Wire imageUrlResolver + mediaUrlResolver into it so forwarded images/voice/video get signed download URLs — exactly issue #74 (image url 缺少 rkey). Also derive the image rkey scene from the appid baked into the URL (1406 -> private, 1407 -> group) instead of the carrying message's group/private context, falling back to isGroup only when the URL has no recognised appid. A c2c image forwarded into a group keeps its original c2c appid, so the old isGroup-based pick signed it with the group rkey -> `invalid rkey` on download. Mirrors NapCat's getImageUrlFromParsedUrl; Lagrange/NapCat both reuse one unified converter so this never drifts. Fix the self-contradictory `c2c images` rkey test (its fixture used the group appid 1407) and add cross-tests asserting appid outranks isGroup both ways, plus the no-appid fallback.
This commit is contained in:
3 files changed
+88
-13
No files matched your search
@@ -675,7 +675,16 @@ export async function getForwardMessage(
|
||||
for (const node of nodes) {
|
||||
const isGroup = node.messageType === 'group' || (node.groupId !== undefined && node.groupId > 0);
|
||||
const sessionId = isGroup ? (node.groupId ?? 0) : node.userUin;
|
||||
const segments = await elementsToOneBotSegments(node.elements, isGroup, sessionId);
|
||||
// Route forward nodes through the SAME resolver-equipped conversion the
|
||||
// normal receive path uses (to-message.ts). Without the image/media URL
|
||||
// resolvers the segments come back with raw, rkey-less download URLs —
|
||||
// exactly issue #74 (`/get_forward_msg` image url 缺少 rkey). Image rkey
|
||||
// re-signing is scene-aware via the appid in the URL (see instance-rkey).
|
||||
const segments = await elementsToOneBotSegments(
|
||||
node.elements, isGroup, sessionId,
|
||||
ref.converterCtx.imageUrlResolver,
|
||||
ref.converterCtx.mediaUrlResolver,
|
||||
);
|
||||
|
||||
const sender: JsonObject = {
|
||||
user_id: node.userUin,
|
||||
|
||||
Reference in new issue
Block a user