feat(onebot): get_qun_album_list (napcat-parity over existing web API)
NapCat's get_qun_album_list calls the kernel AlbumService (trpc, not
statically recoverable). SnowLuma already exposes the same qun_list_album_v2
web API as get_group_album_list (raw array); this adds the NapCat-named
action reshaping it into NapCat's {album_list, attach_info, has_more}
envelope with {album_id, album_name, create_time, pic_num} items. Web
endpoint pulls up to 1000 albums in one shot → attach_info/has_more are
''/false (no cursor); cover_url not returned by this endpoint. Reuses the
existing groupAlbum.list bridge call — no new wire.
This commit is contained in:
2 files changed
+60
No files matched your search
@@ -18,6 +18,36 @@ export const actions = [
|
||||
},
|
||||
}),
|
||||
|
||||
// get_qun_album_list — NapCat-named/shaped variant of get_group_album_list.
|
||||
// NapCat's own impl calls the kernel AlbumService (trpc, not statically
|
||||
// recoverable); we instead reuse the qun_list_album_v2 web API (the same one
|
||||
// get_group_album_list uses) and reshape into NapCat's
|
||||
// {album_list, attach_info, has_more} envelope. The web endpoint fetches up
|
||||
// to 1000 albums in one shot, so attach_info/has_more are ''/false (no cursor
|
||||
// pagination); cover_url isn't returned by this endpoint.
|
||||
groupAction({
|
||||
name: 'get_qun_album_list',
|
||||
readOnly: true,
|
||||
run: async (p, ctx) => {
|
||||
try {
|
||||
const albumList = await ctx.bridge.apis.groupAlbum.list(p.group_id);
|
||||
return okResponse({
|
||||
album_list: albumList.map((a) => ({
|
||||
album_id: a.id,
|
||||
album_name: a.name,
|
||||
create_time: a.createTime,
|
||||
pic_num: a.picNum,
|
||||
})),
|
||||
attach_info: '',
|
||||
has_more: false,
|
||||
});
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : 'failed to get qun album list';
|
||||
return failedResponse(RETCODE.INTERNAL_ERROR, message);
|
||||
}
|
||||
},
|
||||
}),
|
||||
|
||||
groupAction({
|
||||
name: 'upload_image_to_qun_album',
|
||||
params: {
|
||||
|
||||
@@ -961,3 +961,33 @@ describe('extended-actions / TierB ③ share + doubt + robot-option', () => {
|
||||
expect(res).toMatchObject({ status: 'ok' });
|
||||
});
|
||||
});
|
||||
|
||||
// ─── napcat-parity: get_qun_album_list (NapCat-shaped envelope over existing web API) ───
|
||||
// SnowLuma already exposes the qun_list_album_v2 web API as get_group_album_list
|
||||
// (raw array). NapCat's get_qun_album_list wraps it as {album_list, attach_info,
|
||||
// has_more} with {album_id, album_name, create_time, ...} items. We add the
|
||||
// NapCat-named/shaped action reusing the same bridge call.
|
||||
describe('extended-actions / get_qun_album_list', () => {
|
||||
it('maps the album list into the napcat {album_list, attach_info, has_more} envelope', async () => {
|
||||
const list = vi.fn(async () => [
|
||||
{ id: 'a1', name: '相册一', picNum: 5, createTime: 1700000000 },
|
||||
{ id: 'a2', name: '相册二', picNum: 0, createTime: 1700000100 },
|
||||
]);
|
||||
const bridge = fakeBridge({ apis: { groupAlbum: { list } } });
|
||||
const res = await makeHandler(fakeCtx(bridge)).handle('get_qun_album_list', { group_id: 12345 });
|
||||
expect(list).toHaveBeenCalledWith(12345);
|
||||
expect(res.status).toBe('ok');
|
||||
expect(res.data).toMatchObject({ attach_info: '', has_more: false });
|
||||
expect((res.data as any).album_list).toEqual([
|
||||
{ album_id: 'a1', album_name: '相册一', create_time: 1700000000, pic_num: 5 },
|
||||
{ album_id: 'a2', album_name: '相册二', create_time: 1700000100, pic_num: 0 },
|
||||
]);
|
||||
});
|
||||
|
||||
it('surfaces failure as a failed response', async () => {
|
||||
const list = vi.fn(async () => { throw new Error('no pskey'); });
|
||||
const bridge = fakeBridge({ apis: { groupAlbum: { list } } });
|
||||
const res = await makeHandler(fakeCtx(bridge)).handle('get_qun_album_list', { group_id: 1 });
|
||||
expect(res.status).toBe('failed');
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user