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:
DrSmoothl committed 2026-08-29 23:58:56 +08:00
1 parent 9cdbcb0299
commit 117335166f
7 files changed
+280 -37

No files matched your search

+2 -7
View File
@@ -1266,15 +1266,10 @@ export const actions = [
return_type: f.string().default('url'),
},
run: async (p, ctx) => {
const urls = await ctx.bridge.apis.profile.fetchCustomFace(p.count);
if (p.return_type === 'id') {
const emojiIds = urls.map((url) => {
const m = /\/qq_expression\/[^/]+\/([^/]+)\//.exec(url);
return m ? m[1] : '';
}).filter(Boolean);
return okResponse(emojiIds);
return okResponse(await ctx.bridge.apis.profile.fetchCustomFaceIds(p.count));
}
return okResponse(urls);
return okResponse(await ctx.bridge.apis.profile.fetchCustomFace(p.count));
},
}),
@@ -61,6 +61,7 @@ const APIS_ROUTING: Record<string, [string, string]> = {
setAvatar: ['profile', 'setAvatar'],
setGroupAvatar: ['profile', 'setGroupAvatar'],
fetchCustomFace: ['profile', 'fetchCustomFace'],
fetchCustomFaceIds: ['profile', 'fetchCustomFaceIds'],
fetchCustomFaceDetails: ['profile', 'fetchCustomFaceDetails'],
getProfileLike: ['profile', 'getLike'],
getUnidirectionalFriendList: ['profile', 'getUnidirectionalFriendList'],
@@ -1486,6 +1487,45 @@ describe('extended-actions / set_group_portrait', () => {
});
});
describe('extended-actions / fetch_custom_face', () => {
it('return_type=id uses the id list directly', async () => {
const fetchCustomFaceIds = vi.fn(async () => [
'10001_0_0_0_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA_0_0',
'10001_0_0_0_BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB_0_0',
]);
const fetchCustomFace = vi.fn();
const bridge = fakeBridge({ fetchCustomFaceIds, fetchCustomFace });
const response = await makeHandler(fakeCtx(bridge)).handle('fetch_custom_face', {
count: '2',
return_type: 'id',
});
expect(fetchCustomFaceIds).toHaveBeenCalledWith(2);
expect(fetchCustomFace).not.toHaveBeenCalled();
expect(response).toMatchObject({
status: 'ok',
data: [
'10001_0_0_0_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA_0_0',
'10001_0_0_0_BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB_0_0',
],
});
});
it('default return_type uses image urls', async () => {
const url = 'https://p.qpic.cn/qq_expression/10001/id/0';
const fetchCustomFace = vi.fn(async () => [url]);
const fetchCustomFaceIds = vi.fn();
const bridge = fakeBridge({ fetchCustomFace, fetchCustomFaceIds });
const response = await makeHandler(fakeCtx(bridge)).handle('fetch_custom_face', { count: '1' });
expect(fetchCustomFace).toHaveBeenCalledWith(1);
expect(fetchCustomFaceIds).not.toHaveBeenCalled();
expect(response).toMatchObject({ status: 'ok', data: [url] });
});
});
describe('extended-actions / fetch_custom_face_detail', () => {
it('returns real packet-backed fields with SnowLuma and NapCat resource aliases', async () => {
const fetchCustomFaceDetails = vi.fn(async () => [{