feat(protocol): favorite emoji fetch/delete/add via Faceroam.OpReq + highway (#107)
* feat(protocol): fetch/delete favorite emoji via Faceroam.OpReq
First non-OIDB services in oidb-services/ — Faceroam.OpReq is a trpc
service, so these bypass invokeOidb and call sendRawPacket directly.
- proto-defs: reuse FaceroamOpReq/Inner/Resp, add field5 + FaceroamOpBody
- protocol: oidb-services/emoji/{shared,fetch-fav-list,delete-fav-emoji}
- core: EmojiApi facade + ApiHub registration
- onebot: fetch_fav_emoji_list + delete_fav_emoji actions
Request wire matches 9.9.26-44343 captures byte-for-byte; fetch response
decode + delete verified end-to-end against a live account.
* feat(protocol): add favorite emoji via BDHExpressionRoam + highway HTTP upload
Flow: BDHExpressionRoam (apply upload, get token) -> highway frame
(PicUp.DataUp commandId=9, serviceTicket = BDHExpressionRoam token) ->
HTTP POST httpconn?htcmd=0x6FF0087 -> fetch refresh.
- proto-defs: BDHExpressionRoamReq/Resp + FavEmojiHighwayHead types
- protocol: oidb-services/emoji/add-fav-emoji (fetchHighwaySession +
BDHExpressionRoam + packHighwayFrame + HTTP POST)
- core: EmojiApi.addFavEmoji facade (reuses loadBinarySource)
- onebot: add_fav_emoji action
- mcp: regenerate catalog
End-to-end verified: new emoji_id appears in fetch list after upload.
* refactor(emoji): reuse fetchCustomFace for fetch_fav_emoji_list
Address review: Faceroam.OpReq had two call sites (profile.fetchCustomFace
+ the new FetchFavList service). Drop the duplicate service —
fetch_fav_emoji_list now reuses ProfileApi.fetchCustomFace and extracts
emoji_id from the returned image URL (qq_expression/<uin>/<id>/0).
delete/add unchanged (independent protocols).
* refactor: align custom-face naming with NapCat
Address review: 'fav_emoji' vs existing 'custom_face' named the same
thing two ways. Rename across the stack to match NapCat's custom_face:
- services: oidb-services/emoji/* -> oidb-services/custom-face/*
(DeleteFavEmoji -> DeleteCustomFace, AddFavEmoji -> AddCustomFace)
- facade: EmojiApi dropped; delete/add moved to ProfileApi
(deleteCustomFace / addCustomFace), next to fetchCustomFace
- actions: fetch_fav_emoji_list -> fetch_custom_face_ids,
delete_fav_emoji -> delete_custom_face, add_fav_emoji -> add_custom_face
- package.json subpaths + catalog regenerated
* refactor(onebot): merge fetch_custom_face_ids into fetch_custom_face
Per review: merge fetch_custom_face_ids back into fetch_custom_face
with a return_type param ('url' default / 'id'). One action, one service,
no separate id-only variant.
This commit is contained in:
1 parent
e3a04858b4
commit
552238fd04
9 files changed
+631
-21
No files matched your search
@@ -0,0 +1,121 @@
|
||||
// Faceroam add — 添加收藏表情(custom face):BDHExpressionRoam 申请 → highway HTTP 上传。
|
||||
//
|
||||
// 走的是 trpc service "ImgStore.BDHExpressionRoam"(不是 OIDB),申请上传
|
||||
// 拿到 token,然后把图片数据打成 highway 帧用 HTTP POST 发到
|
||||
// httpconn?htcmd=0x6FF0087。上传节点 host:port 复用 fetchHighwaySession
|
||||
// (0x6ff_501)的 serverInfos,端口 80。
|
||||
//
|
||||
// head segHead.serviceTicket = BDHExpressionRoam 响应 token(不是 sigSession,
|
||||
// 端到端验证过)。head field5 (82B) 抓包见过但非必需,不填也能上传。
|
||||
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type {
|
||||
BDHExpressionRoamReq,
|
||||
BDHExpressionRoamResp,
|
||||
FavEmojiHighwayHead,
|
||||
} from '@snowluma/proto-defs/oidb-actions/base';
|
||||
import type { BridgeContext } from '../../bridge-context';
|
||||
import { fetchHighwaySession } from '../../highway/highway-client';
|
||||
import { computeMd5, packHighwayFrame } from '../../highway/utils';
|
||||
|
||||
export namespace AddCustomFace {
|
||||
const BDH_SERVICE = 'ImgStore.BDHExpressionRoam';
|
||||
|
||||
export interface Params {
|
||||
uin: string;
|
||||
imageBytes: Uint8Array;
|
||||
}
|
||||
|
||||
// fetchHighwaySession 需要 sendRawPacket + identity,所以 Deps 比纯 OidbSender 多 identity。
|
||||
export type Deps = Pick<BridgeContext, 'sendRawPacket' | 'identity'>;
|
||||
|
||||
function md5Hex(md5: Uint8Array): string {
|
||||
let s = '';
|
||||
for (const b of md5) s += b.toString(16).padStart(2, '0');
|
||||
return s;
|
||||
}
|
||||
|
||||
export async function invoke(deps: Deps, params: Params): Promise<string> {
|
||||
const { uin, imageBytes } = params;
|
||||
const md5 = computeMd5(imageBytes);
|
||||
const emojiId = `${uin}_0_0_0_${md5Hex(md5).toUpperCase()}_0_0`;
|
||||
|
||||
// 1. fetchHighwaySession 拿上传节点 host:port(复用 SnowLuma highway-client)
|
||||
const session = await fetchHighwaySession(deps as unknown as BridgeContext);
|
||||
const host = session.host;
|
||||
const port = session.port;
|
||||
|
||||
// 2. BDHExpressionRoam 申请上传 token
|
||||
const reqBody = protobuf_encode<BDHExpressionRoamReq>({
|
||||
field1: 3,
|
||||
field2: 1,
|
||||
inner: {
|
||||
field1: 0,
|
||||
uin: BigInt(uin),
|
||||
field3: 0,
|
||||
md5,
|
||||
filesize: imageBytes.length,
|
||||
field7: 2,
|
||||
field8: 0,
|
||||
field9: 1,
|
||||
ver: '1.0.0',
|
||||
field16: 1,
|
||||
},
|
||||
field7: 9,
|
||||
tail: { inner: { field1: 0, field2: 0, field3: '0' }, field2: 1 },
|
||||
});
|
||||
const result = await deps.sendRawPacket(BDH_SERVICE, reqBody);
|
||||
if (!result.gotResponse) throw new Error(result.errorMessage || 'BDHExpressionRoam: no response');
|
||||
if (!result.success) throw new Error(result.errorMessage || 'BDHExpressionRoam: send failed');
|
||||
const resp = protobuf_decode<BDHExpressionRoamResp>(result.responseData ?? new Uint8Array(0));
|
||||
const token = resp.inner?.token;
|
||||
if (!token) throw new Error('BDHExpressionRoam: response missing token (field8)');
|
||||
|
||||
// 3. 构造 highway head。serviceTicket = BDHExpressionRoam token。
|
||||
const head = protobuf_encode<FavEmojiHighwayHead>({
|
||||
baseHead: {
|
||||
version: 1,
|
||||
uin,
|
||||
command: 'PicUp.DataUp',
|
||||
seq: 1,
|
||||
retryTimes: 0,
|
||||
filesize: BigInt(imageBytes.length),
|
||||
dataFlag: 16,
|
||||
commandId: 9,
|
||||
},
|
||||
segHead: {
|
||||
serviceId: 0,
|
||||
filesize: BigInt(imageBytes.length),
|
||||
dataOffset: 0n,
|
||||
dataLength: BigInt(imageBytes.length),
|
||||
serviceTicket: token,
|
||||
md5,
|
||||
fileMd5: md5,
|
||||
},
|
||||
emojiIdWrap: { emojiId },
|
||||
field4: 0,
|
||||
field8: 9,
|
||||
// field5 (82B) 抓包见过但非必需,不填
|
||||
});
|
||||
|
||||
// 4. highway 帧(复用 SnowLuma packHighwayFrame,结构和抓包一致)
|
||||
const frame = packHighwayFrame(head, imageBytes);
|
||||
|
||||
// 5. HTTP POST 上传。端口用 fetchHighwaySession 的 port(抓包确认 httpconn 端口 80)。
|
||||
const url = `http://${host}:${port}/cgi-bin/httpconn?htcmd=0x6FF0087&uin=${uin}`;
|
||||
const httpResp = await fetch(url, {
|
||||
method: 'POST',
|
||||
body: frame,
|
||||
headers: {
|
||||
Accept: '*/*',
|
||||
Connection: 'Keep-Alive',
|
||||
'User-Agent': 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2)',
|
||||
'Cache-Control': 'no-cache',
|
||||
Pragma: 'no-cache',
|
||||
},
|
||||
});
|
||||
if (!httpResp.ok) throw new Error(`highway upload failed: HTTP ${httpResp.status}`);
|
||||
|
||||
return emojiId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
// Faceroam.OpReq opType=2 — 删除一个收藏表情(custom face)。
|
||||
//
|
||||
// 和 fetch 同一个 trpc service,区别在 field3=2、inner 不带 qqVersion、
|
||||
// 业务体 field5 塞 emoji_id(即 custom face id)。id 格式是
|
||||
// `<uin 段>_0_0_0_<MD5>_0_0`,直接用 fetch 响应里解析出来的值回传即可,
|
||||
// 不用自己拼。field2 同样是当前账号 UIN。
|
||||
//
|
||||
// 请求 wire 同样对齐 9.9.26-44343 抓包(单测样本)。响应暂时只看
|
||||
// success / errorCode,业务字段等需要时再解。
|
||||
|
||||
import { protobuf_encode } from '@snowluma/proton';
|
||||
import type { FaceroamOpReq } from '@snowluma/proto-defs/oidb-actions/base';
|
||||
import type { OidbSender } from '../../oidb-service';
|
||||
import { FACEROAM_SERVICE, makeInner } from './shared';
|
||||
|
||||
export namespace DeleteCustomFace {
|
||||
export interface Params {
|
||||
/** 当前账号 UIN,写入 field2。 */
|
||||
uin: string;
|
||||
/** 形如 `<UIN>_0_0_0_<MD5>_0_0`,来自 fetch 响应。 */
|
||||
emojiId: string;
|
||||
}
|
||||
|
||||
export type Deps = OidbSender;
|
||||
|
||||
export const serialize = (_ctx: Deps, p: Params): FaceroamOpReq => ({
|
||||
inner: makeInner(false),
|
||||
uin: BigInt(p.uin),
|
||||
field3: 2,
|
||||
body: { emojiId: p.emojiId },
|
||||
});
|
||||
|
||||
export const encode = (req: FaceroamOpReq): Uint8Array =>
|
||||
protobuf_encode<FaceroamOpReq>(req);
|
||||
|
||||
export async function invoke(deps: Deps, params: Params): Promise<void> {
|
||||
const body = encode(serialize(deps, params));
|
||||
const result = await deps.sendRawPacket(FACEROAM_SERVICE, body);
|
||||
if (!result.gotResponse) throw new Error(result.errorMessage || 'Faceroam.OpReq delete: no response');
|
||||
if (!result.success) throw new Error(result.errorMessage || 'Faceroam.OpReq delete: send failed');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// Faceroam.OpReq 共用的常量与请求 inner 构造。
|
||||
//
|
||||
// 放在 custom-face/ 目录而不是上一层 oidb-services/shared.ts,因为这些值
|
||||
// 只有 Faceroam 这一族操作要用——那边存的是所有 OIDB namespace 共享
|
||||
// 的 toInt / ensureRetCodeZero 那一类小工具,混进去会让无关 service 也
|
||||
// 看到 Faceroam 的版本号字符串。
|
||||
|
||||
import type { FaceroamOpReqInner } from '@snowluma/proto-defs/oidb-actions/base';
|
||||
|
||||
/** trpc service 名,sendRawPacket 的第一个参数。 */
|
||||
export const FACEROAM_SERVICE = 'Faceroam.OpReq';
|
||||
|
||||
// 客户端版本标识。直接硬编码抓包看到的值——QQ 不同小版本之间这部分
|
||||
// 理论上会变,但 Faceroam 服务端对版本号并不敏感,先按当前目标版本写死,
|
||||
// 真出问题再从 identity 里取。
|
||||
const CLIENT_VERSION = '10.0.26200';
|
||||
const CLIENT_BUILD = '9.9.26-44343';
|
||||
|
||||
/**
|
||||
* 构造请求 inner(field1 客户端环境)。fetch 带 qqVersion,delete 不带——
|
||||
* 这不是随手写的,是 wire dump 里两者 inner 长度差 14 字节的直接来源。
|
||||
*/
|
||||
export function makeInner(withQqVersion: boolean): FaceroamOpReqInner {
|
||||
const inner: FaceroamOpReqInner = { field1: 1, osVersion: CLIENT_VERSION };
|
||||
if (withQqVersion) inner.qqVersion = CLIENT_BUILD;
|
||||
return inner;
|
||||
}
|
||||
Reference in new issue
Block a user