fix(video): fall back to portrait dims on fast-upload group video

The width/height=0 → 文件已过期 fix only covered the normal upload path, which
ffprobes real dimensions. The fast-upload (fingerprint / forward) path has no
bytes to probe and takes dimensions from cached metadata, which is 0 when the
source video arrived on the wire without dimensions (e.g. forwarded from another
client that itself sent 0x0). Re-forwarding such a video to a group then shipped
0x0 and the receiver rendered a stale "expired" placeholder.

videoPayloadFromFingerprint now substitutes a neutral 720x1280 portrait when a
dimension is absent or zero (|| not ??, so a cached 0 is replaced too). Real
cached dimensions always win; c2c is unaffected (the wire builder forces 0 there
regardless). A forwarded dimensionless video now renders and plays instead of
showing 文件已过期; verified on-target by forwarding a zeroed-dim video.
This commit is contained in:
DrSmoothl committed 2026-07-05 15:39:35 +08:00
1 parent 0e6e2ec51d
commit ac20956076
2 files changed
+32 -2

No files matched your search

@@ -123,6 +123,23 @@ describe('video-upload', () => {
expect((c2cInfo[0] as any).fileInfo.height).toBe(0);
});
it('[#145] fast-upload with 0x0 dims (e.g. forwarding a dimensionless video) falls back to portrait for group', async () => {
// A forwarded video whose cached dims are 0 must NOT ship 0x0 to a group
// (→ 文件已过期). videoPayloadFromFingerprint substitutes a neutral 720x1280
// portrait; c2c stays 0 (server rejects non-zero there).
const noDims = { ...FINGERPRINT, width: 0, height: 0 } as any;
await uploadVideoMsgInfo({} as any, true, 12345, noDims);
const groupInfo = vi.mocked(pipeline.runNtv2Upload).mock.calls[0]![0].uploadInfo;
expect((groupInfo[0] as any).fileInfo.width).toBe(720);
expect((groupInfo[0] as any).fileInfo.height).toBe(1280);
vi.mocked(pipeline.runNtv2Upload).mockClear();
await uploadVideoMsgInfo({} as any, false, 'recipient-uid', noDims);
const c2cInfo = vi.mocked(pipeline.runNtv2Upload).mock.calls[0]![0].uploadInfo;
expect((c2cInfo[0] as any).fileInfo.width).toBe(0);
expect((c2cInfo[0] as any).fileInfo.height).toBe(0);
});
it('main video carries the real `time` (duration in seconds) — regression: was 0', async () => {
// NTV2 server bakes the `time` field into the resulting MsgInfo
// bytes that ride along as `commonElem.pbElem`; the receiver
+15 -2
View File
@@ -43,6 +43,17 @@ export const GROUP_VIDEO_THUMB_CMD_ID = 1006;
// costs ~1.5 GiB+ of process memory.
export const MAX_VIDEO_SIZE = 1536 * 1024 * 1024;
const SHA1_STREAM_BLOCK_SIZE = 1024 * 1024;
// [#145] A group video whose MsgInfo carries width/height=0 makes QQ-NT
// receivers fail to lay out the tile and render 文件已过期 even though the
// resource is fresh. The normal upload path ffprobes real dimensions, but the
// fast-upload (fingerprint / forward) path has no bytes to probe and relies on
// cached dims — which are 0 when the source video arrived on the wire with no
// dimensions (e.g. forwarded from another bot that itself sent 0x0). Fall back
// to a neutral portrait aspect so a forwarded video at least renders and plays
// (thumbnail is already a fallback on this path); real cached dims always win.
const FAST_UPLOAD_FALLBACK_WIDTH = 720;
const FAST_UPLOAD_FALLBACK_HEIGHT = 1280;
const SHA1_BLOCK_SIZE = 64;
export function getVideoSourceSize(element: MessageElement): number | null {
@@ -117,8 +128,10 @@ function videoPayloadFromFingerprint(element: MessageElement): VideoPayload {
sha1Hex: element.sha1Hex ?? '',
fileName: element.fileName || `${element.md5Hex ?? 'video'}.mp4`,
fileSize: element.fileSize ?? 0,
width: element.width ?? 0,
height: element.height ?? 0,
// `|| fallback` (not `??`): a cached-but-zero dimension must be replaced too,
// else a group forward ships 0x0 and the receiver shows 文件已过期 (#145).
width: element.width || FAST_UPLOAD_FALLBACK_WIDTH,
height: element.height || FAST_UPLOAD_FALLBACK_HEIGHT,
duration: element.duration ?? 1,
videoFormat: element.videoFormat ?? 0,
thumb: makeFallbackThumb(),