fix(qzone): read real t1_tid/t1_time publish fields — was false-throwing every success

Adversarial review (verdict NEEDS-FIXES, CRITICAL): emotion_cgi_publish_v6's
success envelope names the new feed id `t1_tid` and post time `t1_time`
(a STRING), NOT `tid`/`now`. So every successful publish hit the
'缺少 tid' guard and was reported as a failure (risking caller-retry
duplicate 说说). The tests passed only because they mocked the wrong field
names — they codified the bug.

- Read t1_tid (primary) with tid as a defensive fallback; t1_time||now
  via Number() (t1_time is a string on the wire). Verified against the
  Go reference lib starim00/AnimeAPI EmotionPublishVo.
- Added who=1 to the form body (both working references send it).
- Tests now encode the real contract (t1_tid/t1_time string), plus a
  tid/now fallback case and a no-feed-id throw case.
This commit is contained in:
DrSmoothl committed 2026-06-20 01:44:50 +08:00
1 parent 9f2eb37232
commit 9e21c3a7ef
2 files changed
+30 -11

No files matched your search

+12 -4
View File
@@ -311,9 +311,13 @@ interface RawPublishResponse {
code?: number;
subcode?: number;
message?: string;
/** Published feed id on success. */
// The publish_v6 SUCCESS envelope names the new feed id `t1_tid` and the
// post time `t1_time` (the latter arrives as a STRING). `tid`/`now` are
// kept as defensive fallbacks for alternate client builds, but `t1_tid`
// is the real primary — reading `tid` alone false-throws on every success.
t1_tid?: string;
t1_time?: string;
tid?: string;
/** Post timestamp (unix seconds) on success. */
now?: number;
}
@@ -363,6 +367,7 @@ export async function publishQzoneMsg(
ver: '1',
ugc_right: '1',
to_sign: '0',
who: '1',
hostuin: hostUin,
code_version: '1',
format: 'json',
@@ -379,10 +384,13 @@ export async function publishQzoneMsg(
log.warn('publishQzoneMsg: non-zero code (uin=%s) code=%d msg=%s', hostUin, data.code, data.message);
throw new Error(`qzone publish failed: code=${data.code} ${data.message ?? ''}`.trim());
}
if (!data.tid) {
const tid = data.t1_tid ?? data.tid;
if (!tid) {
log.warn('publishQzoneMsg: no tid in response (uin=%s) — publish likely rejected', hostUin);
throw new Error('发表说说失败:响应缺少 tid');
}
return { tid: String(data.tid), time: Number(data.now ?? 0) };
// t1_time is a string on the wire; Number() coerces it (and the `now`
// numeric fallback) uniformly.
return { tid: String(tid), time: Number(data.t1_time ?? data.now ?? 0) };
}