refactor(protocol): dedup NTV2 record/video mediaNode builder in decoder
阶段 3(零行为改动):record(bizType 12/22) 与 video(bizType 11/21) 解码分支里
各写一份、逐字完全相同的 23 行 `mediaNode:{ fileUuid,storeId,uploadTime,ttl,
subType,info:{…} }` 块,抽成共享 helper buildMediaNode(idx, fi),消除这对并行拷贝
的漂移风险(改一处忘另一处)。
- VideoFile / Ptt 两处的 mediaNode 来源变量与 shape 不同,正确保持独立、未误并。
- 逐字提取,行为 byte 级不变:typecheck 干净、protocol 全量 561 全绿;对抗性
Agent byte-diff 确认原两份完全相同、helper body 与之逐字一致。
注:计划中的 poke faceId→subType 字段对齐已主动撤销——poke 不能当消息段发送,
且自身消息回显路径会读 element.subType 使该改动可观测,违反"重构行为不变"。
This commit is contained in:
1 file changed
+36
-46
@@ -3,7 +3,9 @@ import { toHex, toHexUpper } from '@snowluma/common/hex';
|
|||||||
import type { MessageElement } from '../events';
|
import type { MessageElement } from '../events';
|
||||||
import type {
|
import type {
|
||||||
Elem,
|
Elem,
|
||||||
|
FileInfo,
|
||||||
GroupFileExtra,
|
GroupFileExtra,
|
||||||
|
IndexNode,
|
||||||
MentionExtra,
|
MentionExtra,
|
||||||
MsgInfo,
|
MsgInfo,
|
||||||
NotOnlineImage,
|
NotOnlineImage,
|
||||||
@@ -17,6 +19,38 @@ type ElemDecoded = Elem;
|
|||||||
type RichTextDecoded = RichText;
|
type RichTextDecoded = RichText;
|
||||||
export type PushMsgBody = MessageBody;
|
export type PushMsgBody = MessageBody;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build the `mediaNode` re-upload descriptor from an NTV2 IndexNode + FileInfo.
|
||||||
|
* Record and video decode to the byte-identical `{ fileUuid, storeId,
|
||||||
|
* uploadTime, ttl, subType, info:{…} }` shape — share one builder so the two
|
||||||
|
* never drift (add a field to one and forget the other).
|
||||||
|
*/
|
||||||
|
function buildMediaNode(idx: IndexNode, fi: FileInfo): MessageElement['mediaNode'] {
|
||||||
|
return {
|
||||||
|
fileUuid: idx.fileUuid,
|
||||||
|
storeId: idx.storeId,
|
||||||
|
uploadTime: idx.uploadTime,
|
||||||
|
ttl: idx.ttl,
|
||||||
|
subType: idx.subType,
|
||||||
|
info: {
|
||||||
|
fileSize: fi.fileSize,
|
||||||
|
fileHash: fi.fileHash,
|
||||||
|
fileSha1: fi.fileSha1,
|
||||||
|
fileName: fi.fileName,
|
||||||
|
width: fi.width,
|
||||||
|
height: fi.height,
|
||||||
|
time: fi.time,
|
||||||
|
original: fi.original,
|
||||||
|
type: {
|
||||||
|
type: fi.type?.type,
|
||||||
|
picFormat: fi.type?.picFormat,
|
||||||
|
videoFormat: fi.type?.videoFormat,
|
||||||
|
voiceFormat: fi.type?.voiceFormat,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export function decodeRichBody(body: PushMsgBody | undefined, isGroup: boolean): MessageElement[] {
|
export function decodeRichBody(body: PushMsgBody | undefined, isGroup: boolean): MessageElement[] {
|
||||||
const elements: MessageElement[] = [];
|
const elements: MessageElement[] = [];
|
||||||
if (body?.richText) {
|
if (body?.richText) {
|
||||||
@@ -418,29 +452,7 @@ function convertElements(elems: ElemDecoded[]): MessageElement[] {
|
|||||||
md5Hex: fi.fileHash ?? '',
|
md5Hex: fi.fileHash ?? '',
|
||||||
sha1Hex: fi.fileSha1 ?? '',
|
sha1Hex: fi.fileSha1 ?? '',
|
||||||
voiceFormat: fi.type?.voiceFormat ?? 0,
|
voiceFormat: fi.type?.voiceFormat ?? 0,
|
||||||
mediaNode: {
|
mediaNode: buildMediaNode(idx, fi),
|
||||||
fileUuid: idx.fileUuid,
|
|
||||||
storeId: idx.storeId,
|
|
||||||
uploadTime: idx.uploadTime,
|
|
||||||
ttl: idx.ttl,
|
|
||||||
subType: idx.subType,
|
|
||||||
info: {
|
|
||||||
fileSize: fi.fileSize,
|
|
||||||
fileHash: fi.fileHash,
|
|
||||||
fileSha1: fi.fileSha1,
|
|
||||||
fileName: fi.fileName,
|
|
||||||
width: fi.width,
|
|
||||||
height: fi.height,
|
|
||||||
time: fi.time,
|
|
||||||
original: fi.original,
|
|
||||||
type: {
|
|
||||||
type: fi.type?.type,
|
|
||||||
picFormat: fi.type?.picFormat,
|
|
||||||
videoFormat: fi.type?.videoFormat,
|
|
||||||
voiceFormat: fi.type?.voiceFormat,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
} else if (bizType === 11 || bizType === 21) {
|
} else if (bizType === 11 || bizType === 21) {
|
||||||
// Video
|
// Video
|
||||||
@@ -454,29 +466,7 @@ function convertElements(elems: ElemDecoded[]): MessageElement[] {
|
|||||||
md5Hex: fi.fileHash ?? '',
|
md5Hex: fi.fileHash ?? '',
|
||||||
sha1Hex: fi.fileSha1 ?? '',
|
sha1Hex: fi.fileSha1 ?? '',
|
||||||
videoFormat: fi.type?.videoFormat ?? 0,
|
videoFormat: fi.type?.videoFormat ?? 0,
|
||||||
mediaNode: {
|
mediaNode: buildMediaNode(idx, fi),
|
||||||
fileUuid: idx.fileUuid,
|
|
||||||
storeId: idx.storeId,
|
|
||||||
uploadTime: idx.uploadTime,
|
|
||||||
ttl: idx.ttl,
|
|
||||||
subType: idx.subType,
|
|
||||||
info: {
|
|
||||||
fileSize: fi.fileSize,
|
|
||||||
fileHash: fi.fileHash,
|
|
||||||
fileSha1: fi.fileSha1,
|
|
||||||
fileName: fi.fileName,
|
|
||||||
width: fi.width,
|
|
||||||
height: fi.height,
|
|
||||||
time: fi.time,
|
|
||||||
original: fi.original,
|
|
||||||
type: {
|
|
||||||
type: fi.type?.type,
|
|
||||||
picFormat: fi.type?.picFormat,
|
|
||||||
videoFormat: fi.type?.videoFormat,
|
|
||||||
voiceFormat: fi.type?.voiceFormat,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user