Feat: 发送图文ark卡片 (#355)
* feat(onebot): implement send tuwen ark * test: add unit tests for send_ark action * test(onebot): update canonical action docs count expectation to 191 * refactor(protocol,onebot): update 0xdc2_34 ark implementation and test coverage - Rename action send_ark -> send_tuwen_ark to distinguish from structmsg and contact-share arks. - Clarify SSO command mapping (OidbSvcTrpcTcp.0xdc2_34) and default param behavior in comments/docs. - Adjust peerType, field3, and previewUrl to pb_optional to preserve 0/empty values during proton encoding. - Update OneBot handler, tests, and auto-generated MCP tool catalog specs. * style(protocol): fix indentation in rich-body-decoder tests
This commit is contained in:
1 parent
62256ee816
commit
8fbddf67bf
11 files changed
+734
-137
No files matched your search
@@ -21,6 +21,7 @@ import { FetchUserProfile } from '@snowluma/protocol/oidb-services/contacts/fetc
|
||||
import { FetchUserProfileByUid } from '@snowluma/protocol/oidb-services/contacts/fetch-user-profile-by-uid';
|
||||
import { GetBuddyRecommendArk } from '@snowluma/protocol/oidb-services/contacts/get-buddy-recommend-ark';
|
||||
import { GetGroupRecommendArk } from '@snowluma/protocol/oidb-services/contacts/get-group-recommend-ark';
|
||||
import { SendTuwenArk, type SendTuwenArkParams } from '@snowluma/protocol/oidb-services/contacts/send-tuwen-ark';
|
||||
import { SetFriendCategory } from '@snowluma/protocol/oidb-services/contacts/set-friend-category';
|
||||
import { toHex } from '@snowluma/common/hex';
|
||||
import { createLogger } from '@snowluma/common/logger';
|
||||
@@ -137,6 +138,11 @@ export class ContactsApi {
|
||||
return GetGroupRecommendArk.invoke(this.ctx, { groupId });
|
||||
}
|
||||
|
||||
/** Send a custom 图文 ark card to a C2C peer or group (0xdc2_34). */
|
||||
sendTuwenArk(params: SendTuwenArkParams): Promise<void> {
|
||||
return SendTuwenArk.invoke(this.ctx, params);
|
||||
}
|
||||
|
||||
private async fetchFriendRoster(): Promise<FriendRoster> {
|
||||
const entries: FriendListPageEntry[] = [];
|
||||
const categories = new Map<number, FriendListPageCategory>();
|
||||
|
||||
@@ -9434,6 +9434,120 @@
|
||||
},
|
||||
"category": "空间"
|
||||
},
|
||||
{
|
||||
"name": "send_tuwen_ark",
|
||||
"aliases": [],
|
||||
"summary": "发送图文 Ark 卡片(私聊/群聊)",
|
||||
"returns": "null",
|
||||
"returnsSchema": {
|
||||
"type": "null"
|
||||
},
|
||||
"readOnly": false,
|
||||
"params": [
|
||||
{
|
||||
"name": "user_id",
|
||||
"type": "uint",
|
||||
"required": false,
|
||||
"role": "user_id",
|
||||
"schema": {
|
||||
"type": "integer",
|
||||
"minimum": 1
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "group_id",
|
||||
"type": "uint",
|
||||
"required": false,
|
||||
"role": "group_id",
|
||||
"schema": {
|
||||
"type": "integer",
|
||||
"minimum": 1
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "title",
|
||||
"type": "string",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "desc",
|
||||
"type": "string",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "summary",
|
||||
"type": "string",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
},
|
||||
"default": "[分享]"
|
||||
},
|
||||
{
|
||||
"name": "preview_url",
|
||||
"type": "string",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
},
|
||||
"default": "https://tangram-1251316161.file.myqcloud.com/files/20210721/e50a8e37e08f29bf1ffc7466e1950690.png"
|
||||
},
|
||||
{
|
||||
"name": "jump_url",
|
||||
"type": "string",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"invariants": [],
|
||||
"inputSchema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"user_id": {
|
||||
"type": "integer",
|
||||
"minimum": 1,
|
||||
"x-role": "user_id"
|
||||
},
|
||||
"group_id": {
|
||||
"type": "integer",
|
||||
"minimum": 1,
|
||||
"x-role": "group_id"
|
||||
},
|
||||
"title": {
|
||||
"type": "string"
|
||||
},
|
||||
"desc": {
|
||||
"type": "string"
|
||||
},
|
||||
"summary": {
|
||||
"type": "string",
|
||||
"default": "[分享]"
|
||||
},
|
||||
"preview_url": {
|
||||
"type": "string",
|
||||
"default": "https://tangram-1251316161.file.myqcloud.com/files/20210721/e50a8e37e08f29bf1ffc7466e1950690.png"
|
||||
},
|
||||
"jump_url": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"title",
|
||||
"desc",
|
||||
"jump_url"
|
||||
],
|
||||
"additionalProperties": true
|
||||
},
|
||||
"category": "扩展"
|
||||
},
|
||||
{
|
||||
"name": "set_diy_online_status",
|
||||
"aliases": [],
|
||||
|
||||
@@ -9437,6 +9437,120 @@ export const ACTIONS: CatalogAction[] = [
|
||||
},
|
||||
"category": "空间"
|
||||
},
|
||||
{
|
||||
"name": "send_tuwen_ark",
|
||||
"aliases": [],
|
||||
"summary": "发送图文 Ark 卡片(私聊/群聊)",
|
||||
"returns": "null",
|
||||
"returnsSchema": {
|
||||
"type": "null"
|
||||
},
|
||||
"readOnly": false,
|
||||
"params": [
|
||||
{
|
||||
"name": "user_id",
|
||||
"type": "uint",
|
||||
"required": false,
|
||||
"role": "user_id",
|
||||
"schema": {
|
||||
"type": "integer",
|
||||
"minimum": 1
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "group_id",
|
||||
"type": "uint",
|
||||
"required": false,
|
||||
"role": "group_id",
|
||||
"schema": {
|
||||
"type": "integer",
|
||||
"minimum": 1
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "title",
|
||||
"type": "string",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "desc",
|
||||
"type": "string",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "summary",
|
||||
"type": "string",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
},
|
||||
"default": "[分享]"
|
||||
},
|
||||
{
|
||||
"name": "preview_url",
|
||||
"type": "string",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
},
|
||||
"default": "https://tangram-1251316161.file.myqcloud.com/files/20210721/e50a8e37e08f29bf1ffc7466e1950690.png"
|
||||
},
|
||||
{
|
||||
"name": "jump_url",
|
||||
"type": "string",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"invariants": [],
|
||||
"inputSchema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"user_id": {
|
||||
"type": "integer",
|
||||
"minimum": 1,
|
||||
"x-role": "user_id"
|
||||
},
|
||||
"group_id": {
|
||||
"type": "integer",
|
||||
"minimum": 1,
|
||||
"x-role": "group_id"
|
||||
},
|
||||
"title": {
|
||||
"type": "string"
|
||||
},
|
||||
"desc": {
|
||||
"type": "string"
|
||||
},
|
||||
"summary": {
|
||||
"type": "string",
|
||||
"default": "[分享]"
|
||||
},
|
||||
"preview_url": {
|
||||
"type": "string",
|
||||
"default": "https://tangram-1251316161.file.myqcloud.com/files/20210721/e50a8e37e08f29bf1ffc7466e1950690.png"
|
||||
},
|
||||
"jump_url": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"title",
|
||||
"desc",
|
||||
"jump_url"
|
||||
],
|
||||
"additionalProperties": true
|
||||
},
|
||||
"category": "扩展"
|
||||
},
|
||||
{
|
||||
"name": "set_diy_online_status",
|
||||
"aliases": [],
|
||||
|
||||
@@ -1739,6 +1739,55 @@ export const actions = [
|
||||
},
|
||||
}),
|
||||
|
||||
// send_tuwen_ark — send a custom 图文 (URL-share) ark card to a C2C peer or group (0xdc2_34).
|
||||
// targetId at AppInfo[11] and Meta[2]; Meta.peerType: 0=C2C, 1=group.
|
||||
// 与 send_ark_share 的区别:send_ark_share 只获取推荐联系人 JSON 不发送;
|
||||
// 与 send_msg share/json 的区别:后者发送 structmsg 图文卡且有 message_id,
|
||||
// 本 action 发送固定图文 ark 模板,返回 null(无法用于撤回/设精华)。
|
||||
defineAction({
|
||||
name: 'send_tuwen_ark',
|
||||
summary: '发送图文 Ark 卡片(私聊/群聊)',
|
||||
readOnly: false,
|
||||
returns: 'null',
|
||||
returnsSchema: { type: 'null' },
|
||||
params: {
|
||||
user_id: f.userId().optional(),
|
||||
group_id: f.groupId().optional(),
|
||||
title: f.string(),
|
||||
desc: f.string(),
|
||||
summary: f.string().default('[分享]'),
|
||||
preview_url: f.string().default('https://tangram-1251316161.file.myqcloud.com/files/20210721/e50a8e37e08f29bf1ffc7466e1950690.png'),
|
||||
jump_url: f.string(),
|
||||
},
|
||||
run: async (p, ctx) => {
|
||||
if (p.group_id) {
|
||||
await ctx.bridge.apis.contacts.sendTuwenArk({
|
||||
targetId: p.group_id,
|
||||
peerType: 1,
|
||||
title: p.title,
|
||||
desc: p.desc,
|
||||
summary: p.summary,
|
||||
previewUrl: p.preview_url,
|
||||
jumpUrl: p.jump_url,
|
||||
});
|
||||
return okResponse(null);
|
||||
}
|
||||
if (p.user_id) {
|
||||
await ctx.bridge.apis.contacts.sendTuwenArk({
|
||||
targetId: p.user_id,
|
||||
peerType: 0,
|
||||
title: p.title,
|
||||
desc: p.desc,
|
||||
summary: p.summary,
|
||||
previewUrl: p.preview_url,
|
||||
jumpUrl: p.jump_url,
|
||||
});
|
||||
return okResponse(null);
|
||||
}
|
||||
return failedResponse(RETCODE.BAD_REQUEST, 'user_id or group_id is required');
|
||||
},
|
||||
}),
|
||||
|
||||
// share_group_ex / send_group_ark_share — group-only Ark share. NapCat uses
|
||||
// a distinct kernel API (getArkJsonGroupShare) we did NOT RE; we route to
|
||||
// the fully-RE'd group recommend-contact ark (0x8b7_5), the closest
|
||||
|
||||
@@ -2065,6 +2065,84 @@ describe('extended-actions / TierB ③ share + doubt + robot-option', () => {
|
||||
});
|
||||
});
|
||||
|
||||
// ─── TierB ③: send_ark (图文 Ark 卡片, OIDB 0xdc2_34) ───
|
||||
|
||||
describe('extended-actions / send_tuwen_ark', () => {
|
||||
const arkParams = {
|
||||
title: '标题',
|
||||
desc: '描述',
|
||||
jump_url: 'https://example.com',
|
||||
};
|
||||
|
||||
it('routes to group when group_id is given (peerType=1)', async () => {
|
||||
const sendTuwenArk = vi.fn(async () => {});
|
||||
const bridge = fakeBridge({ apis: { contacts: { sendTuwenArk } } });
|
||||
const res = await makeHandler(fakeCtx(bridge)).handle('send_tuwen_ark', {
|
||||
group_id: 12345,
|
||||
...arkParams,
|
||||
});
|
||||
expect(res).toMatchObject({ status: 'ok', retcode: 0, data: null });
|
||||
expect(sendTuwenArk).toHaveBeenCalledWith({
|
||||
targetId: 12345,
|
||||
peerType: 1,
|
||||
title: '标题',
|
||||
desc: '描述',
|
||||
summary: '[分享]',
|
||||
previewUrl: 'https://tangram-1251316161.file.myqcloud.com/files/20210721/e50a8e37e08f29bf1ffc7466e1950690.png',
|
||||
jumpUrl: 'https://example.com',
|
||||
});
|
||||
});
|
||||
|
||||
it('routes to C2C when user_id is given (peerType=0)', async () => {
|
||||
const sendTuwenArk = vi.fn(async () => {});
|
||||
const bridge = fakeBridge({ apis: { contacts: { sendTuwenArk } } });
|
||||
const res = await makeHandler(fakeCtx(bridge)).handle('send_tuwen_ark', {
|
||||
user_id: 10001,
|
||||
...arkParams,
|
||||
});
|
||||
expect(res).toMatchObject({ status: 'ok', retcode: 0, data: null });
|
||||
expect(sendTuwenArk).toHaveBeenCalledWith({
|
||||
targetId: 10001,
|
||||
peerType: 0,
|
||||
title: '标题',
|
||||
desc: '描述',
|
||||
summary: '[分享]',
|
||||
previewUrl: 'https://tangram-1251316161.file.myqcloud.com/files/20210721/e50a8e37e08f29bf1ffc7466e1950690.png',
|
||||
jumpUrl: 'https://example.com',
|
||||
});
|
||||
});
|
||||
|
||||
it('prefers group_id over user_id when both are supplied', async () => {
|
||||
const sendTuwenArk = vi.fn(async () => {});
|
||||
const bridge = fakeBridge({ apis: { contacts: { sendTuwenArk } } });
|
||||
const res = await makeHandler(fakeCtx(bridge)).handle('send_tuwen_ark', {
|
||||
group_id: 12345,
|
||||
user_id: 10001,
|
||||
...arkParams,
|
||||
});
|
||||
expect(res).toMatchObject({ status: 'ok' });
|
||||
expect(sendTuwenArk).toHaveBeenCalledWith(expect.objectContaining({ peerType: 1, targetId: 12345 }));
|
||||
});
|
||||
|
||||
it('rejects when neither user_id nor group_id is given', async () => {
|
||||
const sendTuwenArk = vi.fn();
|
||||
const bridge = fakeBridge({ apis: { contacts: { sendTuwenArk } } });
|
||||
const res = await makeHandler(fakeCtx(bridge)).handle('send_tuwen_ark', { ...arkParams });
|
||||
expect(res).toMatchObject({ status: 'failed', retcode: 1400 });
|
||||
expect(sendTuwenArk).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('surfaces bridge errors as action_failed', async () => {
|
||||
const sendTuwenArk = vi.fn(async () => { throw new Error('oidb 0xdc2 rejected'); });
|
||||
const bridge = fakeBridge({ apis: { contacts: { sendTuwenArk } } });
|
||||
const res = await makeHandler(fakeCtx(bridge)).handle('send_tuwen_ark', {
|
||||
group_id: 12345,
|
||||
...arkParams,
|
||||
});
|
||||
expect(res).toMatchObject({ status: 'failed', retcode: 100, wording: 'oidb 0xdc2 rejected' });
|
||||
});
|
||||
});
|
||||
|
||||
// ─── napcat-parity: get_qun_album_list (QQ NT AlbumService) ───
|
||||
describe('extended-actions / get_group_album_list', () => {
|
||||
it('returns the cover and last-upload metadata from the core facade', async () => {
|
||||
|
||||
@@ -27,7 +27,7 @@ function createControlPort(): {
|
||||
messages: MessageStoreMigrationWorkerMessage[];
|
||||
send(message: unknown): void;
|
||||
listenerCount(): number;
|
||||
} {
|
||||
} {
|
||||
const messages: MessageStoreMigrationWorkerMessage[] = [];
|
||||
const events = new EventEmitter();
|
||||
return {
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
// reads {1:bussness_error_code, 5:ark_json}.
|
||||
// Both return a server-built ark JSON string (the share card payload).
|
||||
|
||||
import type { pb, uint_32 } from '@snowluma/proton';
|
||||
import type { pb, pb_optional, uint_32 } from '@snowluma/proton';
|
||||
|
||||
export interface OidbBuddyRecommendArkReq {
|
||||
uin?: pb<1, uint_32>;
|
||||
@@ -28,3 +28,43 @@ export interface OidbGroupRecommendArkResp {
|
||||
errCode?: pb<1, uint_32>;
|
||||
arkJson?: pb<5, string>;
|
||||
}
|
||||
|
||||
// 0xdc2_34 — send a custom 图文 (URL-share) ark card to a C2C peer or group.
|
||||
// Field layout RE'd from QQ Android 9.3.25 captures. Default SSO: OidbSvcTrpcTcp.0xdc2_34.
|
||||
// appId = 100446242 is fixed for this ark type.
|
||||
// targetId (UIN or group_id) appears at AppInfo[11] AND Meta[2].
|
||||
// Meta.peerType: 0 = C2C, 1 = group.
|
||||
// peerType, field3, and previewUrl are pb_optional — proton preserves 0/empty on wire.
|
||||
export interface Oidb0xdc2CardField5 {
|
||||
field1?: pb<1, uint_32>;
|
||||
}
|
||||
|
||||
export interface Oidb0xdc2CardContent {
|
||||
flag?: pb<1, uint_32>;
|
||||
title?: pb<10, string>;
|
||||
desc?: pb<11, string>;
|
||||
summary?: pb<12, string>;
|
||||
jumpUrl?: pb<13, string>;
|
||||
previewUrl?: pb_optional<14, string>;
|
||||
}
|
||||
|
||||
export interface Oidb0xdc2AppInfo {
|
||||
appId?: pb<1, uint_32>;
|
||||
field2?: pb<2, uint_32>;
|
||||
field3?: pb_optional<3, uint_32>;
|
||||
field5?: pb<5, Oidb0xdc2CardField5>;
|
||||
targetId?: pb<11, uint_32>;
|
||||
content?: pb<12, Oidb0xdc2CardContent>;
|
||||
}
|
||||
|
||||
export interface Oidb0xdc2Meta {
|
||||
peerType?: pb_optional<1, uint_32>;
|
||||
targetId?: pb<2, uint_32>;
|
||||
}
|
||||
|
||||
export interface Oidb0xdc2_34Req {
|
||||
appInfo?: pb<1, Oidb0xdc2AppInfo>;
|
||||
meta?: pb<2, Oidb0xdc2Meta>;
|
||||
}
|
||||
|
||||
export interface Oidb0xdc2_34Resp {}
|
||||
@@ -0,0 +1,67 @@
|
||||
// 0xdc2_34 — send a custom 图文 (URL-share) ark card to a C2C peer or group.
|
||||
// RE'd from QQ Android 9.3.25 captures. Default SSO: OidbSvcTrpcTcp.0xdc2_34.
|
||||
// Fixed fields: appId = 100446242, field2 = 1, field3 = 0, field5 = {1:1}
|
||||
// targetId appears at AppInfo[11] and Meta[2]; Meta.peerType: 0=C2C, 1=group.
|
||||
// peerType, field3, and previewUrl are pb_optional — proton preserves 0/empty on wire.
|
||||
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type {
|
||||
Oidb0xdc2_34Req,
|
||||
Oidb0xdc2_34Resp,
|
||||
} from '@snowluma/proto-defs/oidb-actions/contact-ark';
|
||||
import { invokeOidb, type OidbSender } from '../../oidb-service';
|
||||
|
||||
const TUWEN_ARK_APPID = 100446242;
|
||||
|
||||
export type SendTuwenArkParams = {
|
||||
targetId: number;
|
||||
peerType: 0 | 1;
|
||||
title: string;
|
||||
desc: string;
|
||||
summary: string;
|
||||
jumpUrl: string;
|
||||
previewUrl: string;
|
||||
};
|
||||
|
||||
export namespace SendTuwenArk {
|
||||
export const command = 0xDC2;
|
||||
export const subCommand = 34;
|
||||
export const uinForm = false;
|
||||
|
||||
export type Params = SendTuwenArkParams;
|
||||
export type Deps = OidbSender;
|
||||
|
||||
export const serialize = (_ctx: Deps, p: Params): Oidb0xdc2_34Req => ({
|
||||
appInfo: {
|
||||
appId: TUWEN_ARK_APPID,
|
||||
field2: 1,
|
||||
field3: 0,
|
||||
field5: { field1: 1 },
|
||||
targetId: p.targetId,
|
||||
content: {
|
||||
flag: 1,
|
||||
title: p.title,
|
||||
desc: p.desc,
|
||||
summary: p.summary,
|
||||
jumpUrl: p.jumpUrl,
|
||||
previewUrl: p.previewUrl,
|
||||
},
|
||||
},
|
||||
meta: {
|
||||
peerType: p.peerType,
|
||||
targetId: p.targetId,
|
||||
},
|
||||
});
|
||||
|
||||
export const deserialize = (_ctx: Deps, _body: Oidb0xdc2_34Resp): void => undefined;
|
||||
|
||||
export const encode = (env: OidbBase<Oidb0xdc2_34Req>): Uint8Array =>
|
||||
protobuf_encode<OidbBase<Oidb0xdc2_34Req>>(env);
|
||||
|
||||
export const decode = (bytes: Uint8Array): OidbBase<Oidb0xdc2_34Resp> =>
|
||||
protobuf_decode<OidbBase<Oidb0xdc2_34Resp>>(bytes);
|
||||
|
||||
export const invoke = (deps: Deps, params: Params): Promise<void> =>
|
||||
invokeOidb(deps, SendTuwenArk, params);
|
||||
}
|
||||
@@ -923,153 +923,153 @@ describe('decodeRichBody / unknown wire element observability', () => {
|
||||
}));
|
||||
});
|
||||
|
||||
function ntImageElem(fileName: string): Elem {
|
||||
const msgInfo: MsgInfo = {
|
||||
msgInfoBody: [{
|
||||
index: {
|
||||
info: {
|
||||
fileSize: 10711,
|
||||
fileHash: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
|
||||
fileSha1: 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb',
|
||||
fileName,
|
||||
width: 1080,
|
||||
height: 1080,
|
||||
type: { picFormat: 1001 },
|
||||
function ntImageElem(fileName: string): Elem {
|
||||
const msgInfo: MsgInfo = {
|
||||
msgInfoBody: [{
|
||||
index: {
|
||||
info: {
|
||||
fileSize: 10711,
|
||||
fileHash: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
|
||||
fileSha1: 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb',
|
||||
fileName,
|
||||
width: 1080,
|
||||
height: 1080,
|
||||
type: { picFormat: 1001 },
|
||||
},
|
||||
},
|
||||
picture: {
|
||||
urlPath: '/download?appid=1407&fileid=EhRgood',
|
||||
domain: 'multimedia.nt.qq.com.cn',
|
||||
ext: { originalParameter: '&rkey=good' },
|
||||
},
|
||||
}],
|
||||
extBizInfo: { pic: { bizType: 0, textSummary: '[图片]' } },
|
||||
};
|
||||
return {
|
||||
commonElem: {
|
||||
serviceType: 48,
|
||||
businessType: 20,
|
||||
pbElem: protobuf_encode<MsgInfo>(msgInfo),
|
||||
},
|
||||
picture: {
|
||||
urlPath: '/download?appid=1407&fileid=EhRgood',
|
||||
domain: 'multimedia.nt.qq.com.cn',
|
||||
ext: { originalParameter: '&rkey=good' },
|
||||
};
|
||||
}
|
||||
|
||||
function customFaceElem(filePath: string, origUrl: string, md5: Uint8Array): Elem {
|
||||
return {
|
||||
customFace: {
|
||||
filePath,
|
||||
origUrl,
|
||||
md5,
|
||||
size: 10711,
|
||||
width: 1080,
|
||||
height: 1080,
|
||||
},
|
||||
}],
|
||||
extBizInfo: { pic: { bizType: 0, textSummary: '[图片]' } },
|
||||
};
|
||||
return {
|
||||
commonElem: {
|
||||
serviceType: 48,
|
||||
businessType: 20,
|
||||
pbElem: protobuf_encode<MsgInfo>(msgInfo),
|
||||
},
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function customFaceElem(filePath: string, origUrl: string, md5: Uint8Array): Elem {
|
||||
return {
|
||||
customFace: {
|
||||
filePath,
|
||||
origUrl,
|
||||
md5,
|
||||
size: 10711,
|
||||
width: 1080,
|
||||
height: 1080,
|
||||
},
|
||||
};
|
||||
}
|
||||
describe('decodeRichBody / NT image compatibility siblings (#389)', () => {
|
||||
const fileName = 'bcc7bbcc76a1a9d940c57346a5d223e8.png';
|
||||
const otherMd5 = Uint8Array.from({ length: 16 }, (_, i) => i + 1);
|
||||
|
||||
describe('decodeRichBody / NT image compatibility siblings (#389)', () => {
|
||||
const fileName = 'bcc7bbcc76a1a9d940c57346a5d223e8.png';
|
||||
const otherMd5 = Uint8Array.from({ length: 16 }, (_, i) => i + 1);
|
||||
it('keeps the NT image and drops the query-only customFace sibling', () => {
|
||||
const out = decodeRichBody({
|
||||
richText: {
|
||||
elems: [
|
||||
ntImageElem(fileName),
|
||||
customFaceElem(fileName, '&rkey=xxx&spec=0', otherMd5),
|
||||
],
|
||||
},
|
||||
}, true);
|
||||
|
||||
it('keeps the NT image and drops the query-only customFace sibling', () => {
|
||||
const out = decodeRichBody({
|
||||
richText: {
|
||||
elems: [
|
||||
ntImageElem(fileName),
|
||||
customFaceElem(fileName, '&rkey=xxx&spec=0', otherMd5),
|
||||
],
|
||||
},
|
||||
}, true);
|
||||
expect(out).toHaveLength(1);
|
||||
expect(out[0]).toMatchObject({
|
||||
type: 'image',
|
||||
fileId: fileName,
|
||||
imageUrl: 'https://multimedia.nt.qq.com.cn/download?appid=1407&fileid=EhRgood&rkey=good',
|
||||
picFormat: 1001,
|
||||
});
|
||||
});
|
||||
|
||||
expect(out).toHaveLength(1);
|
||||
expect(out[0]).toMatchObject({
|
||||
type: 'image',
|
||||
fileId: fileName,
|
||||
imageUrl: 'https://multimedia.nt.qq.com.cn/download?appid=1407&fileid=EhRgood&rkey=good',
|
||||
picFormat: 1001,
|
||||
it('drops a same-file customFace even when its legacy URL is well-formed', () => {
|
||||
const out = decodeRichBody({
|
||||
richText: {
|
||||
elems: [
|
||||
ntImageElem(fileName),
|
||||
customFaceElem(fileName, '/gchatpic_new/0/0-0-AABB/0', otherMd5),
|
||||
],
|
||||
},
|
||||
}, true);
|
||||
|
||||
expect(out).toEqual([
|
||||
expect.objectContaining({ type: 'image', fileId: fileName, picFormat: 1001 }),
|
||||
]);
|
||||
});
|
||||
|
||||
it('keeps a standalone customFace with a usable download path', () => {
|
||||
const out = decodeRichBody({
|
||||
richText: {
|
||||
elems: [customFaceElem(fileName, '/gchatpic_new/0/0-0-AABB/0', otherMd5)],
|
||||
},
|
||||
}, true);
|
||||
|
||||
expect(out).toEqual([{
|
||||
type: 'image',
|
||||
imageUrl: 'http://gchat.qpic.cn/gchatpic_new/0/0-0-AABB/0',
|
||||
fileId: fileName,
|
||||
fileSize: 10711,
|
||||
width: 1080,
|
||||
height: 1080,
|
||||
subType: 0,
|
||||
summary: '[图片]',
|
||||
md5Hex: '0102030405060708090A0B0C0D0E0F10',
|
||||
}]);
|
||||
});
|
||||
|
||||
it('drops a standalone customFace whose URL cannot be fetched', () => {
|
||||
const out = decodeRichBody({
|
||||
richText: {
|
||||
elems: [customFaceElem(fileName, '&rkey=xxx&spec=0', otherMd5)],
|
||||
},
|
||||
}, true);
|
||||
|
||||
expect(out).toEqual([]);
|
||||
});
|
||||
|
||||
it('keeps two distinct pictures', () => {
|
||||
const second = 'other.png';
|
||||
const out = decodeRichBody({
|
||||
richText: {
|
||||
elems: [
|
||||
ntImageElem(fileName),
|
||||
customFaceElem(second, '/gchatpic_new/0/0-0-CCDD/0', otherMd5),
|
||||
],
|
||||
},
|
||||
}, true);
|
||||
|
||||
expect(out.map((el) => el.type === 'image' ? el.fileId : el.type)).toEqual([
|
||||
fileName,
|
||||
second,
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
it('drops a same-file customFace even when its legacy URL is well-formed', () => {
|
||||
const out = decodeRichBody({
|
||||
richText: {
|
||||
elems: [
|
||||
ntImageElem(fileName),
|
||||
customFaceElem(fileName, '/gchatpic_new/0/0-0-AABB/0', otherMd5),
|
||||
],
|
||||
},
|
||||
}, true);
|
||||
describe('makeImageUrl', () => {
|
||||
it('prefixes NT paths that already include a download path', () => {
|
||||
expect(makeImageUrl('/download?appid=1407&fileid=abc&rkey=x'))
|
||||
.toBe('https://multimedia.nt.qq.com.cn/download?appid=1407&fileid=abc&rkey=x');
|
||||
});
|
||||
|
||||
expect(out).toEqual([
|
||||
expect.objectContaining({ type: 'image', fileId: fileName, picFormat: 1001 }),
|
||||
]);
|
||||
it('does not glue the NT host onto a query fragment (#389)', () => {
|
||||
expect(makeImageUrl('&rkey=xxx&spec=0')).toBe('');
|
||||
expect(makeImageUrl('rkey=xxx&spec=0')).toBe('');
|
||||
});
|
||||
|
||||
it('prefixes legacy gchat paths', () => {
|
||||
expect(makeImageUrl('/gchatpic_new/0/0-0-AABB/0'))
|
||||
.toBe('http://gchat.qpic.cn/gchatpic_new/0/0-0-AABB/0');
|
||||
});
|
||||
});
|
||||
|
||||
it('keeps a standalone customFace with a usable download path', () => {
|
||||
const out = decodeRichBody({
|
||||
richText: {
|
||||
elems: [customFaceElem(fileName, '/gchatpic_new/0/0-0-AABB/0', otherMd5)],
|
||||
},
|
||||
}, true);
|
||||
|
||||
expect(out).toEqual([{
|
||||
type: 'image',
|
||||
imageUrl: 'http://gchat.qpic.cn/gchatpic_new/0/0-0-AABB/0',
|
||||
fileId: fileName,
|
||||
fileSize: 10711,
|
||||
width: 1080,
|
||||
height: 1080,
|
||||
subType: 0,
|
||||
summary: '[图片]',
|
||||
md5Hex: '0102030405060708090A0B0C0D0E0F10',
|
||||
}]);
|
||||
});
|
||||
|
||||
it('drops a standalone customFace whose URL cannot be fetched', () => {
|
||||
const out = decodeRichBody({
|
||||
richText: {
|
||||
elems: [customFaceElem(fileName, '&rkey=xxx&spec=0', otherMd5)],
|
||||
},
|
||||
}, true);
|
||||
|
||||
expect(out).toEqual([]);
|
||||
});
|
||||
|
||||
it('keeps two distinct pictures', () => {
|
||||
const second = 'other.png';
|
||||
const out = decodeRichBody({
|
||||
richText: {
|
||||
elems: [
|
||||
ntImageElem(fileName),
|
||||
customFaceElem(second, '/gchatpic_new/0/0-0-CCDD/0', otherMd5),
|
||||
],
|
||||
},
|
||||
}, true);
|
||||
|
||||
expect(out.map((el) => el.type === 'image' ? el.fileId : el.type)).toEqual([
|
||||
fileName,
|
||||
second,
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('makeImageUrl', () => {
|
||||
it('prefixes NT paths that already include a download path', () => {
|
||||
expect(makeImageUrl('/download?appid=1407&fileid=abc&rkey=x'))
|
||||
.toBe('https://multimedia.nt.qq.com.cn/download?appid=1407&fileid=abc&rkey=x');
|
||||
});
|
||||
|
||||
it('does not glue the NT host onto a query fragment (#389)', () => {
|
||||
expect(makeImageUrl('&rkey=xxx&spec=0')).toBe('');
|
||||
expect(makeImageUrl('rkey=xxx&spec=0')).toBe('');
|
||||
});
|
||||
|
||||
it('prefixes legacy gchat paths', () => {
|
||||
expect(makeImageUrl('/gchatpic_new/0/0-0-AABB/0'))
|
||||
.toBe('http://gchat.qpic.cn/gchatpic_new/0/0-0-AABB/0');
|
||||
});
|
||||
});
|
||||
|
||||
it('bounds retained card output across the entire message', () => {
|
||||
const previousLevel = getLogLevel();
|
||||
const captured: Array<{ scope: string; message: string }> = [];
|
||||
|
||||
@@ -3,7 +3,6 @@ import {
|
||||
protobuf_encode,
|
||||
type pb,
|
||||
type pb_repeated,
|
||||
type string,
|
||||
type uint_32,
|
||||
} from '@snowluma/proton';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
@@ -0,0 +1,130 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { protobuf_encode } from '@snowluma/proton';
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type { Oidb0xdc2_34Resp } from '@snowluma/proto-defs/oidb-actions/contact-ark';
|
||||
import type { SendPacketResult } from '@snowluma/common/packet-sender';
|
||||
import { SendTuwenArk } from '../../../src/oidb-services/contacts/send-tuwen-ark';
|
||||
import { env, v, s, m } from '../_pb-oracle';
|
||||
|
||||
function makeSender() {
|
||||
const respEnv: OidbBase<Oidb0xdc2_34Resp> = { command: 0xDC2, subCommand: 34, body: {} };
|
||||
const r: SendPacketResult = {
|
||||
success: true, gotResponse: true, errorCode: 0, errorMessage: '',
|
||||
responseData: Buffer.from(protobuf_encode<OidbBase<Oidb0xdc2_34Resp>>(respEnv)),
|
||||
};
|
||||
return { sendRawPacket: vi.fn(async () => r) };
|
||||
}
|
||||
|
||||
describe('SendTuwenArk namespace', () => {
|
||||
it('declares command 0xdc2 sub 34, SSO: OidbSvcTrpcTcp.0xdc2_34', () => {
|
||||
expect(SendTuwenArk.command).toBe(0xDC2);
|
||||
expect(SendTuwenArk.subCommand).toBe(34);
|
||||
expect(SendTuwenArk.uinForm).toBe(false);
|
||||
});
|
||||
|
||||
it('serializes fixed appId=100446242, field2=1, field3=0, field5={1:1}', () => {
|
||||
const out = SendTuwenArk.serialize({} as any, {
|
||||
targetId: 12345,
|
||||
peerType: 1,
|
||||
title: 'T',
|
||||
desc: 'D',
|
||||
summary: 'S',
|
||||
jumpUrl: 'https://example.com',
|
||||
previewUrl: '',
|
||||
});
|
||||
expect(out.appInfo).toMatchObject({
|
||||
appId: 100446242,
|
||||
field2: 1,
|
||||
field3: 0,
|
||||
field5: { field1: 1 },
|
||||
targetId: 12345,
|
||||
});
|
||||
});
|
||||
|
||||
it('byte-oracle: C2C (peerType=0) — peerType omitted on wire, field3=0 present, previewUrl present', async () => {
|
||||
const sender = makeSender();
|
||||
await SendTuwenArk.invoke(sender, {
|
||||
targetId: 2863253201,
|
||||
peerType: 0,
|
||||
title: 'QQ开放平台',
|
||||
desc: 'QQ小程序是连接广轻用户的新方式,覆盖8亿新生代活跃网民。轻便快捷的开发模式,将能在QQ内被轻松获取和传播',
|
||||
summary: '[分享] QQ开放平台',
|
||||
jumpUrl: 'https://q.qq.com/r',
|
||||
previewUrl: 'https://tangram-1251316161.file.myqcloud.com/files/20210721/e50a8e37e08f29bf1ffc7466e1950690.png',
|
||||
});
|
||||
|
||||
const [cmd, bytes] = sender.sendRawPacket.mock.calls[0]!;
|
||||
expect(cmd).toBe('OidbSvcTrpcTcp.0xdc2_34');
|
||||
|
||||
// AppInfo embedding: field5={1:1}, content={1:1, 10:title, 11:desc, 12:summary, 13:jumpUrl, 14:previewUrl}, then appId/field2/field3/targetId
|
||||
const field5 = m(5, [...v(1, 1)]);
|
||||
const content = m(12, [
|
||||
...v(1, 1),
|
||||
...s(10, 'QQ开放平台'),
|
||||
...s(11, 'QQ小程序是连接广轻用户的新方式,覆盖8亿新生代活跃网民。轻便快捷的开发模式,将能在QQ内被轻松获取和传播'),
|
||||
...s(12, '[分享] QQ开放平台'),
|
||||
...s(13, 'https://q.qq.com/r'),
|
||||
...s(14, 'https://tangram-1251316161.file.myqcloud.com/files/20210721/e50a8e37e08f29bf1ffc7466e1950690.png'),
|
||||
]);
|
||||
const appInfo = m(1, [
|
||||
...v(1, 100446242),
|
||||
...v(2, 1),
|
||||
...v(3, 0), // field3=0 is present in wire (pb_optional preserves zero as expected)
|
||||
...field5,
|
||||
...v(11, 2863253201),
|
||||
...content,
|
||||
]);
|
||||
// Meta: peerType=0 is present in wire (pb_optional preserves zero as expected)
|
||||
const meta = m(2, [
|
||||
...v(1, 0),
|
||||
...v(2, 2863253201),
|
||||
]);
|
||||
const body = [...appInfo, ...meta];
|
||||
expect(Buffer.from(bytes).toString('hex')).toBe(env(0xDC2, 34, body, false));
|
||||
});
|
||||
|
||||
it('byte-oracle: group (peerType=1) — peerType present, field3=0 present, empty previewUrl present', async () => {
|
||||
const sender = makeSender();
|
||||
await SendTuwenArk.invoke(sender, {
|
||||
targetId: 123456789,
|
||||
peerType: 1,
|
||||
title: '测试标题',
|
||||
desc: '测试描述',
|
||||
summary: '测试摘要',
|
||||
jumpUrl: 'https://example.com/jump',
|
||||
previewUrl: '',
|
||||
});
|
||||
|
||||
const [cmd, bytes] = sender.sendRawPacket.mock.calls[0]!;
|
||||
expect(cmd).toBe('OidbSvcTrpcTcp.0xdc2_34');
|
||||
|
||||
const field5 = m(5, [...v(1, 1)]);
|
||||
const content = m(12, [
|
||||
...v(1, 1),
|
||||
...s(10, '测试标题'),
|
||||
...s(11, '测试描述'),
|
||||
...s(12, '测试摘要'),
|
||||
...s(13, 'https://example.com/jump'),
|
||||
...s(14, ''), // previewUrl='' is present in wire (pb_optional preserves empty string as expected)
|
||||
]);
|
||||
const appInfo = m(1, [
|
||||
...v(1, 100446242),
|
||||
...v(2, 1),
|
||||
...v(3, 0), // field3=0 is present
|
||||
...field5,
|
||||
...v(11, 123456789),
|
||||
...content,
|
||||
]);
|
||||
// Meta: peerType=1 present
|
||||
const meta = m(2, [
|
||||
...v(1, 1),
|
||||
...v(2, 123456789),
|
||||
]);
|
||||
const body = [...appInfo, ...meta];
|
||||
expect(Buffer.from(bytes).toString('hex')).toBe(env(0xDC2, 34, body, false));
|
||||
});
|
||||
|
||||
it('deserialize returns undefined (void response)', () => {
|
||||
expect(SendTuwenArk.deserialize({} as any, {})).toBeUndefined();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user