refactor(oidb): migrate web.ts OIDB cmds to namespaces
2 OIDB cmds moved (the only OIDB calls in this file — the rest are
HTTP cookie / qun.qq.com / qzone web requests):
- ForceFetchClientKey (0x102A_1) — used by ptlogin2 jump flow to
swap clientKey → cookie jar
- GetPskey (0x102A_0) — p_skey fallback when ptlogin2
omits it
The private `forceFetchClientKeyInner` / `getPSkey` helpers in
WebApi are now one-line forwarders into the namespaces. Facade
methods (`getCookies`, `getCsrfToken`, `getCredentials`, etc.) and
all HTTP-only cmds untouched.
12 new namespace-level tests covering deserialize edge cases
(empty server response, missing fields, dropped invalid items)
and e2e wire routing.
Verification:
- typecheck green
- @snowluma/bridge: 20 files / 165 tests
- @snowluma/core: 302 tests
Wire bytes unchanged.
This commit is contained in:
6 files changed
+233
-44
No files matched your search
@@ -0,0 +1,44 @@
|
||||
// 0x102A_1 — fetch a fresh `clientKey` (consumed by the ptlogin2 jump
|
||||
// URL flow that swaps it for cookie-jar entries on qq.com subdomains).
|
||||
//
|
||||
// The server's `keyIndex` field is occasionally empty in the wild;
|
||||
// every NapCat-derived implementation falls back to the literal "19"
|
||||
// in that case — origin unknown but the value works.
|
||||
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type { OidbClientKeyReq, OidbClientKeyResp } from '@snowluma/proto-defs/oidb-actions/base';
|
||||
import { invokeOidb, type OidbSender } from '../../oidb-service';
|
||||
|
||||
export interface ClientKeyInfo {
|
||||
clientKey: string;
|
||||
keyIndex: string;
|
||||
expireTime: string;
|
||||
}
|
||||
|
||||
export namespace ForceFetchClientKey {
|
||||
export const command = 0x102A;
|
||||
export const subCommand = 1;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
||||
export interface Params {}
|
||||
|
||||
export type Deps = OidbSender;
|
||||
|
||||
export const serialize = (_: Params): OidbClientKeyReq => ({});
|
||||
|
||||
export const deserialize = (body: OidbClientKeyResp): ClientKeyInfo => ({
|
||||
clientKey: body.clientKey || '',
|
||||
keyIndex: String(body.keyIndex || '19'),
|
||||
expireTime: String(body.expireTime || '1800'),
|
||||
});
|
||||
|
||||
export const encode = (env: OidbBase<OidbClientKeyReq>): Uint8Array =>
|
||||
protobuf_encode<OidbBase<OidbClientKeyReq>>(env);
|
||||
|
||||
export const decode = (bytes: Uint8Array): OidbBase<OidbClientKeyResp> =>
|
||||
protobuf_decode<OidbBase<OidbClientKeyResp>>(bytes);
|
||||
|
||||
export const invoke = (deps: Deps): Promise<ClientKeyInfo> =>
|
||||
invokeOidb(deps, ForceFetchClientKey, {});
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
// 0x102A_0 — request p_skey cookies for a list of qq.com subdomains.
|
||||
// Used as the fallback when ptlogin2 jump doesn't emit a p_skey on
|
||||
// the cookie set (intermittent server behaviour).
|
||||
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type { OidbGetPskeyReq, OidbGetPskeyResp } from '@snowluma/proto-defs/oidb-actions/base';
|
||||
import { invokeOidb, type OidbSender } from '../../oidb-service';
|
||||
|
||||
export namespace GetPskey {
|
||||
export const command = 0x102A;
|
||||
export const subCommand = 0;
|
||||
|
||||
export interface Params {
|
||||
domainList: string[];
|
||||
}
|
||||
|
||||
export interface Result {
|
||||
domainPskeyMap: Map<string, string>;
|
||||
}
|
||||
|
||||
export type Deps = OidbSender;
|
||||
|
||||
export const serialize = (p: Params): OidbGetPskeyReq => ({
|
||||
domainList: p.domainList,
|
||||
});
|
||||
|
||||
export const deserialize = (body: OidbGetPskeyResp): Result => {
|
||||
const domainPskeyMap = new Map<string, string>();
|
||||
if (body.pskeyItems && Array.isArray(body.pskeyItems)) {
|
||||
for (const item of body.pskeyItems) {
|
||||
if (item.domain && item.pskey) {
|
||||
domainPskeyMap.set(item.domain, item.pskey);
|
||||
}
|
||||
}
|
||||
}
|
||||
return { domainPskeyMap };
|
||||
};
|
||||
|
||||
export const encode = (env: OidbBase<OidbGetPskeyReq>): Uint8Array =>
|
||||
protobuf_encode<OidbBase<OidbGetPskeyReq>>(env);
|
||||
|
||||
export const decode = (bytes: Uint8Array): OidbBase<OidbGetPskeyResp> =>
|
||||
protobuf_decode<OidbBase<OidbGetPskeyResp>>(bytes);
|
||||
|
||||
export const invoke = (deps: Deps, params: Params): Promise<Result> =>
|
||||
invokeOidb(deps, GetPskey, params);
|
||||
}
|
||||
Reference in new issue
Block a user