refactor(protocol): keep custom-face list encoding with delete
Profile still turns ids into image URLs and slices the count. Asking for ids no longer round-trips through those URLs.
This commit is contained in:
7 files changed
+280
-37
No files matched your search
@@ -0,0 +1,44 @@
|
||||
// Faceroam.OpReq opType=1 — 拉取当前账号的收藏表情 id 列表。
|
||||
//
|
||||
// 和 delete 同一个 trpc service,区别在 field3=1、inner 带 qqVersion、
|
||||
// 并置 field6=1。响应 item.faceIds 是完整列表;截条数由调用方做。
|
||||
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type { FaceroamOpReq, FaceroamOpResp } from '@snowluma/proto-defs/oidb-actions/base';
|
||||
import type { OidbSender } from '../../oidb-service';
|
||||
import { FACEROAM_SERVICE, makeInner } from './shared';
|
||||
|
||||
export namespace FetchCustomFaceList {
|
||||
export interface Params {
|
||||
/** 当前账号 UIN,写入 field2。 */
|
||||
uin: string;
|
||||
}
|
||||
|
||||
export type Deps = OidbSender;
|
||||
|
||||
export const serialize = (_ctx: Deps, p: Params): FaceroamOpReq => ({
|
||||
inner: makeInner(true),
|
||||
uin: BigInt(p.uin),
|
||||
field3: 1,
|
||||
field6: 1,
|
||||
});
|
||||
|
||||
export const encode = (req: FaceroamOpReq): Uint8Array =>
|
||||
protobuf_encode<FaceroamOpReq>(req);
|
||||
|
||||
export const decode = (bytes: Uint8Array): FaceroamOpResp =>
|
||||
protobuf_decode<FaceroamOpResp>(bytes);
|
||||
|
||||
export async function invoke(deps: Deps, params: Params): Promise<string[]> {
|
||||
const body = encode(serialize(deps, params));
|
||||
const result = await deps.sendRawPacket(FACEROAM_SERVICE, body);
|
||||
if (!result.success || !result.gotResponse || !result.responseData) {
|
||||
throw new Error(result.errorMessage || 'fetch custom face failed');
|
||||
}
|
||||
const resp = decode(result.responseData);
|
||||
if (!resp || (resp.retCode ?? 0) !== 0) {
|
||||
throw new Error(`fetch custom face error: ${resp?.message || 'unknown'}`);
|
||||
}
|
||||
return resp.item?.faceIds || [];
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,8 @@ export const FACEROAM_SERVICE = 'Faceroam.OpReq';
|
||||
// 真出问题再从 identity 里取。
|
||||
/** osVersion 字符串,Faceroam inner 与 0x902e 业务体 f2 共用。 */
|
||||
export const CLIENT_VERSION = '10.0.26200';
|
||||
const CLIENT_BUILD = '9.9.26-44343';
|
||||
/** qqVersion on the Faceroam list inner. Keep the value list already sends. Delete omits this field. */
|
||||
const LIST_QQ_VERSION = '9.9.28-46928';
|
||||
|
||||
/**
|
||||
* 构造请求 inner(field1 客户端环境)。fetch 带 qqVersion,delete 不带——
|
||||
@@ -23,6 +24,6 @@ const CLIENT_BUILD = '9.9.26-44343';
|
||||
*/
|
||||
export function makeInner(withQqVersion: boolean): FaceroamOpReqInner {
|
||||
const inner: FaceroamOpReqInner = { field1: 1, osVersion: CLIENT_VERSION };
|
||||
if (withQqVersion) inner.qqVersion = CLIENT_BUILD;
|
||||
if (withQqVersion) inner.qqVersion = LIST_QQ_VERSION;
|
||||
return inner;
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { protobuf_encode } from '@snowluma/proton';
|
||||
import type { SendPacketResult } from '@snowluma/common/packet-sender';
|
||||
import type { FaceroamOpReq, FaceroamOpResp } from '@snowluma/proto-defs/oidb-actions/base';
|
||||
|
||||
import { FetchCustomFaceList } from '../../../src/oidb-services/custom-face/fetch-custom-face-list';
|
||||
|
||||
const SAMPLE_UIN = '10001';
|
||||
const EMOJI_A = '10001_0_0_0_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA_0_0';
|
||||
const EMOJI_B = '10001_0_0_0_BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB_0_0';
|
||||
|
||||
function encodeLegacyList(uin: string): Uint8Array {
|
||||
return protobuf_encode<FaceroamOpReq>({
|
||||
inner: { field1: 1, osVersion: '10.0.26200', qqVersion: '9.9.28-46928' },
|
||||
uin: BigInt(uin),
|
||||
field3: 1,
|
||||
field6: 1,
|
||||
});
|
||||
}
|
||||
|
||||
function makeSender(opts: {
|
||||
faces?: FaceroamOpResp;
|
||||
success?: boolean;
|
||||
gotResponse?: boolean;
|
||||
errorMessage?: string;
|
||||
responseData?: Uint8Array | null;
|
||||
} = {}) {
|
||||
const result: SendPacketResult = {
|
||||
success: opts.success ?? true,
|
||||
gotResponse: opts.gotResponse ?? true,
|
||||
errorCode: 0,
|
||||
errorMessage: opts.errorMessage ?? '',
|
||||
responseData: opts.responseData !== undefined
|
||||
? opts.responseData
|
||||
: Buffer.from(protobuf_encode<FaceroamOpResp>(
|
||||
opts.faces ?? { retCode: 0, item: { faceIds: [EMOJI_A, EMOJI_B] } },
|
||||
)),
|
||||
};
|
||||
return { sendRawPacket: vi.fn(async () => result) };
|
||||
}
|
||||
|
||||
describe('FetchCustomFaceList namespace', () => {
|
||||
describe('serialize + encode', () => {
|
||||
it('keeps the list request bytes the ProfileApi fetch already sent', () => {
|
||||
const req = FetchCustomFaceList.serialize({} as any, { uin: SAMPLE_UIN });
|
||||
const hex = Buffer.from(FetchCustomFaceList.encode(req)).toString('hex');
|
||||
expect(hex).toBe(Buffer.from(encodeLegacyList(SAMPLE_UIN)).toString('hex'));
|
||||
});
|
||||
|
||||
it('sends qqVersion on inner and sets field3=1 / field6=1', () => {
|
||||
const req = FetchCustomFaceList.serialize({} as any, { uin: SAMPLE_UIN });
|
||||
expect(req.inner?.qqVersion).toBe('9.9.28-46928');
|
||||
expect(req.inner?.osVersion).toBe('10.0.26200');
|
||||
expect(req.field3).toBe(1);
|
||||
expect(req.field6).toBe(1);
|
||||
expect(req.body).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('invoke', () => {
|
||||
it('routes through "Faceroam.OpReq" and returns the id list', async () => {
|
||||
const sender = makeSender();
|
||||
await expect(FetchCustomFaceList.invoke(sender, { uin: SAMPLE_UIN })).resolves.toEqual([
|
||||
EMOJI_A,
|
||||
EMOJI_B,
|
||||
]);
|
||||
expect(sender.sendRawPacket.mock.calls[0]![0]).toBe('Faceroam.OpReq');
|
||||
const [, body] = sender.sendRawPacket.mock.calls[0]!;
|
||||
expect(Buffer.from(body as Uint8Array).toString('hex')).toBe(
|
||||
Buffer.from(encodeLegacyList(SAMPLE_UIN)).toString('hex'),
|
||||
);
|
||||
});
|
||||
|
||||
it('returns an empty list when the item is missing', async () => {
|
||||
const sender = makeSender({ faces: { retCode: 0 } });
|
||||
await expect(FetchCustomFaceList.invoke(sender, { uin: SAMPLE_UIN })).resolves.toEqual([]);
|
||||
});
|
||||
|
||||
it('throws when the sender reports no response', async () => {
|
||||
const sender = makeSender({
|
||||
success: false,
|
||||
gotResponse: false,
|
||||
errorMessage: 'timeout',
|
||||
responseData: null,
|
||||
});
|
||||
await expect(FetchCustomFaceList.invoke(sender, { uin: SAMPLE_UIN })).rejects.toThrow(/timeout/);
|
||||
});
|
||||
|
||||
it('throws when the Faceroam retCode is non-zero', async () => {
|
||||
const sender = makeSender({ faces: { retCode: 1, message: 'denied' } });
|
||||
await expect(FetchCustomFaceList.invoke(sender, { uin: SAMPLE_UIN })).rejects.toThrow(
|
||||
/fetch custom face error: denied/,
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user