refactor(oidb): replace 3 positional helpers with one named runOidb
bridge-oidb.ts used to expose three thin functions —
makeOidbRequest / sendOidbAndCheck / sendOidbAndDecode — and every
action file repeated the same five-step envelope assembly with long
positional argument lists. Collapse them into one `runOidb(bridge,
call)` taking an OidbCall object: cmd / oidbCmd / subCmd / request
{ schema, value, isUid? } / response? { schema }.
Behavioural contract is preserved:
- No `response`: verify success + gotResponse, peek envelope retCode
iff response data is present (fire-and-check semantics).
- With `response`: require responseData, decode through the base
schema, validate retCode, return the inner body typed as TResp.
Migration touches 51 call sites across 9 source files (bridge-contacts,
actions/{group-file, group-admin, profile, group-message, friend,
interaction, misc}, web-actions/cookies) plus 9 test files that used
to assert on positional `.mock.calls[0]![4]` indices and now read
through `.mock.calls[0]![1].request.value` / `.cmd` / `.oidbCmd`.
Net effect: callers now name what each piece is for, and adding
cross-cutting OIDB behaviour (retry / timeout / per-cmd logging) is a
single-site change inside runOidb instead of a sweep across 9 files.
This commit is contained in:
19 files changed
+637
-549
No files matched your search
@@ -4,7 +4,7 @@
|
||||
// thread the cookies into a qun.qq.com REST endpoint.
|
||||
|
||||
import type { Bridge } from '../bridge';
|
||||
import { sendOidbAndDecode } from '../bridge-oidb';
|
||||
import { runOidb } from '../bridge-oidb';
|
||||
import {
|
||||
OidbClientKeyRespSchema,
|
||||
OidbClientKeyReqSchema,
|
||||
@@ -14,15 +14,12 @@ import {
|
||||
import { RequestUtil } from '../web/request-util';
|
||||
|
||||
export async function forceFetchClientKey(bridge: Bridge) {
|
||||
const resp = await sendOidbAndDecode<any>(
|
||||
bridge,
|
||||
'OidbSvcTrpcTcp.0x102a_1',
|
||||
0x102A,
|
||||
1,
|
||||
{},
|
||||
OidbClientKeyReqSchema,
|
||||
OidbClientKeyRespSchema,
|
||||
);
|
||||
const resp = await runOidb<any>(bridge, {
|
||||
cmd: 'OidbSvcTrpcTcp.0x102a_1',
|
||||
oidbCmd: 0x102A, subCmd: 1,
|
||||
request: { schema: OidbClientKeyReqSchema, value: {} },
|
||||
response: { schema: OidbClientKeyRespSchema },
|
||||
});
|
||||
|
||||
const clientKey = resp?.clientKey || '';
|
||||
// keyIndex falls back to "19" — origin unknown but the value is what
|
||||
@@ -37,15 +34,12 @@ export async function forceFetchClientKey(bridge: Bridge) {
|
||||
}
|
||||
|
||||
export async function getPSkey(bridge: Bridge, domainList: string[]) {
|
||||
const resp = await sendOidbAndDecode<any>(
|
||||
bridge,
|
||||
'OidbSvcTrpcTcp.0x102a_0',
|
||||
0x102A,
|
||||
0,
|
||||
{ domainList },
|
||||
OidbGetPskeyReqSchema,
|
||||
OidbGetPskeyRespSchema,
|
||||
);
|
||||
const resp = await runOidb<any>(bridge, {
|
||||
cmd: 'OidbSvcTrpcTcp.0x102a_0',
|
||||
oidbCmd: 0x102A, subCmd: 0,
|
||||
request: { schema: OidbGetPskeyReqSchema, value: { domainList } },
|
||||
response: { schema: OidbGetPskeyRespSchema },
|
||||
});
|
||||
|
||||
const domainPskeyMap = new Map<string, string>();
|
||||
|
||||
|
||||
Reference in new issue
Block a user