From 4d75dc9ae35c32ab4b4083772bb477ce18f041c3 Mon Sep 17 00:00:00 2001 From: DrSmoothl <1787882683@qq.com> Date: Sat, 20 Jun 2026 01:52:47 +0800 Subject: [PATCH] fix(qzone): delete_v6 uses format=fs, drop bogus json param, harden success check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adversarial review (NEEDS-FIXES) — two wrong-constant defects (same family as the publish t1_tid bug) + a destructive-write hardening: - format=json → format=fs. Every working reference (silica-github/ qq_zone_delete, zhihu, daimagongfang) uses fs for the delete CGI; the tests re-codified the wrong value. - Removed the invented json=1 body param (no source includes it); test now asserts it's absent. - Also throw on a non-zero subcode (not just code), and documented that the code/subcode success signal is EXTRAPOLATED from sibling CGIs pending a live capture (public delete impls only check HTTP 2xx). Added subcode-throw and code-absent-resolves tests to lock the branch. --- packages/protocol/src/web/qzone.ts | 16 ++++++++++++++-- packages/protocol/tests/web/qzone.test.ts | 19 +++++++++++++++++-- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/packages/protocol/src/web/qzone.ts b/packages/protocol/src/web/qzone.ts index 6241cc54..74d6de0c 100644 --- a/packages/protocol/src/web/qzone.ts +++ b/packages/protocol/src/web/qzone.ts @@ -428,13 +428,15 @@ export async function deleteQzoneMsg( const bkn = getBknFromCookie(cookieObject); const url = `https://h5.qzone.qq.com/proxy/domain/taotao.qzone.qq.com/cgi-bin/emotion_cgi_delete_v6?g_tk=${bkn}`; + // The canonical delete request uses `format=fs` (NOT json) and the exact + // param set below — confirmed across the silica-github/qq_zone_delete + // working script and community docs. const body = new URLSearchParams({ hostuin: hostUin, tid, t1_source: '1', code_version: '1', - format: 'json', - json: '1', + format: 'fs', qzreferrer: `https://user.qzone.qq.com/${hostUin}`, }).toString(); @@ -444,8 +446,18 @@ export async function deleteQzoneMsg( }); const data = parseQzoneJson(text); + // Success signal: delete has no positive payload, so we throw on a + // non-zero code OR sub-code. NOTE: that `code`/`subcode` is delete's + // success field is EXTRAPOLATED from the sibling CGIs (publish/msglist) + // — public delete impls only check HTTP 2xx — so this is pending a live + // capture to confirm the exact failure envelope (same posture as the + // other helpers in this file). if (typeof data.code === 'number' && data.code !== 0) { log.warn('deleteQzoneMsg: non-zero code (uin=%s tid=%s) code=%d msg=%s', hostUin, tid, data.code, data.message); throw new Error(`qzone delete failed: code=${data.code} ${data.message ?? ''}`.trim()); } + if (typeof data.subcode === 'number' && data.subcode !== 0) { + log.warn('deleteQzoneMsg: non-zero subcode (uin=%s tid=%s) subcode=%d msg=%s', hostUin, tid, data.subcode, data.message); + throw new Error(`qzone delete failed: subcode=${data.subcode} ${data.message ?? ''}`.trim()); + } } diff --git a/packages/protocol/tests/web/qzone.test.ts b/packages/protocol/tests/web/qzone.test.ts index 8fca7d2c..94501550 100644 --- a/packages/protocol/tests/web/qzone.test.ts +++ b/packages/protocol/tests/web/qzone.test.ts @@ -247,7 +247,10 @@ describe('qzone / publishQzoneMsg (HTTP layer)', () => { describe('qzone / deleteQzoneMsg (HTTP layer)', () => { afterEach(() => vi.restoreAllMocks()); - it('POSTs the tid form body to the proxied delete CGI and resolves on code 0', async () => { + it('POSTs the tid form body (format=fs) to the proxied delete CGI and resolves on code 0', async () => { + // NB: the success-body shape is a guess extrapolated from sibling CGIs — + // no public delete impl parses the response — so this mock pins our + // success contract, not a verified server envelope (see helper comment). const spy = vi.spyOn(RequestUtil, 'HttpGetText').mockResolvedValue('{"code":0,"subcode":0,"message":""}'); await expect(deleteQzoneMsg(cookies, '10000', 'TID123')).resolves.toBeUndefined(); @@ -263,7 +266,9 @@ describe('qzone / deleteQzoneMsg (HTTP layer)', () => { const form = new URLSearchParams(body as string); expect(form.get('tid')).toBe('TID123'); expect(form.get('hostuin')).toBe('10000'); - expect(form.get('format')).toBe('json'); + // delete_v6 wants format=fs (NOT json), per the working community script + expect(form.get('format')).toBe('fs'); + expect(form.get('json')).toBeNull(); // no bogus json param }); it('rejects an empty tid before any request', async () => { @@ -276,4 +281,14 @@ describe('qzone / deleteQzoneMsg (HTTP layer)', () => { vi.spyOn(RequestUtil, 'HttpGetText').mockResolvedValue('{"code":-4001,"message":"no permission"}'); await expect(deleteQzoneMsg(cookies, '10000', 'TID123')).rejects.toThrow('code=-4001'); }); + + it('throws on a non-zero subcode even when code is 0', async () => { + vi.spyOn(RequestUtil, 'HttpGetText').mockResolvedValue('{"code":0,"subcode":-12,"message":"sub error"}'); + await expect(deleteQzoneMsg(cookies, '10000', 'TID123')).rejects.toThrow('subcode=-12'); + }); + + it('resolves when neither code nor subcode is present (extrapolated success branch)', async () => { + vi.spyOn(RequestUtil, 'HttpGetText').mockResolvedValue('{"message":""}'); + await expect(deleteQzoneMsg(cookies, '10000', 'TID123')).resolves.toBeUndefined(); + }); });