feat(onebot): implement collection list retrieval
Replace the get_collection_list placeholder with authenticated, read-only collection retrieval through the existing bridge API. Add strict binary envelope validation, bounded pagination, accurate category filtering, preserved 64-bit identifiers, and explicit ticket, transport, service, and malformed-response failures. Cap item counts, page traversal, response bytes, per-request waits, and the total operation time. Expose the compatible response model through Core, OneBot, the SDK, and the generated MCP catalog. Cover protocol framing, cursor behavior, filtered hasMore semantics, cleanup failures, bridge ticket acquisition, and Action validation with regression tests. Verified with the live test bot without changing native components or adding any collection write behavior.
This commit is contained in:
15 files changed
+1912
-20
No files matched your search
@@ -0,0 +1,28 @@
|
||||
import { GetPskey } from '@snowluma/protocol/oidb-services/web/get-pskey';
|
||||
import {
|
||||
getCollectionList,
|
||||
type CollectionListResult,
|
||||
} from '@snowluma/protocol/web/collection';
|
||||
import type { BridgeContext } from '../bridge-context';
|
||||
|
||||
const COLLECTION_DOMAIN = 'weiyun.com';
|
||||
|
||||
/** Read-only access to the account's QQ collection list. */
|
||||
export class CollectionApi {
|
||||
constructor(private readonly ctx: BridgeContext) {}
|
||||
|
||||
async list(category = 0, count = 50): Promise<CollectionListResult> {
|
||||
const { domainPskeyMap } = await GetPskey.invoke(this.ctx, {
|
||||
domainList: [COLLECTION_DOMAIN],
|
||||
});
|
||||
const pskey = domainPskeyMap.get(COLLECTION_DOMAIN);
|
||||
if (!pskey) throw new Error(`QQ did not return a p_skey for ${COLLECTION_DOMAIN}`);
|
||||
|
||||
return getCollectionList({
|
||||
uin: this.ctx.identity.uin,
|
||||
pskey,
|
||||
category,
|
||||
count,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { BridgeContext } from '../bridge-context';
|
||||
import { CollectionApi } from './collection';
|
||||
import { ContactsApi } from './contacts';
|
||||
import { ExtrasApi } from './extras';
|
||||
import { FlashTransferApi } from './flash-transfer';
|
||||
@@ -15,6 +16,8 @@ import { QzoneApi } from './qzone';
|
||||
import { WebApi } from './web';
|
||||
|
||||
export interface ApiHub {
|
||||
/** Personal QQ collections: authenticated list retrieval and pagination. */
|
||||
readonly collection: CollectionApi;
|
||||
/** Send/recall/markRead operations across c2c + group + c2c-file. */
|
||||
readonly message: MessageApi;
|
||||
/** Friend / group / member roster + user-profile + group-request-list + download-rkey. */
|
||||
@@ -55,6 +58,7 @@ export interface ApiHub {
|
||||
*/
|
||||
export function buildApiHub(ctx: BridgeContext): ApiHub {
|
||||
return {
|
||||
collection: new CollectionApi(ctx),
|
||||
message: new MessageApi(ctx),
|
||||
contacts: new ContactsApi(ctx),
|
||||
groupAdmin: new GroupAdminApi(ctx),
|
||||
@@ -76,6 +80,7 @@ export function buildApiHub(ctx: BridgeContext): ApiHub {
|
||||
// `import type { MessageApi } from '@snowluma/core/.../apis'` for
|
||||
// signature use. Concrete instances always come from `bridge.apis.*`.
|
||||
export { ContactsApi } from './contacts';
|
||||
export { CollectionApi } from './collection';
|
||||
export { ExtrasApi } from './extras';
|
||||
export { ForwardApi } from './forward';
|
||||
export { FriendApi } from './friend';
|
||||
@@ -89,4 +94,3 @@ export { ProfileApi } from './profile';
|
||||
export { QzoneApi } from './qzone';
|
||||
export { FlashTransferApi, type FlashFileInfo } from './flash-transfer';
|
||||
export { WebApi } from './web';
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest';
|
||||
import { GetPskey } from '@snowluma/protocol/oidb-services/web/get-pskey';
|
||||
import * as collectionWeb from '@snowluma/protocol/web/collection';
|
||||
import { CollectionApi } from '../../src/bridge/apis/collection';
|
||||
import { mockBridge } from './_helpers';
|
||||
|
||||
describe('apis/collection', () => {
|
||||
afterEach(() => vi.restoreAllMocks());
|
||||
|
||||
it('obtains a Weiyun p_skey and fetches the collection list', async () => {
|
||||
const bridge = mockBridge();
|
||||
const expected = {
|
||||
errCode: 0 as const,
|
||||
errMsg: '',
|
||||
collectionSearchList: {
|
||||
collectionItemList: [],
|
||||
hasMore: false,
|
||||
bottomTimeStamp: '0',
|
||||
},
|
||||
};
|
||||
const ticketSpy = vi.spyOn(GetPskey, 'invoke').mockResolvedValue({
|
||||
domainPskeyMap: new Map([['weiyun.com', 'weiyun-ticket']]),
|
||||
});
|
||||
const listSpy = vi.spyOn(collectionWeb, 'getCollectionList').mockResolvedValue(expected);
|
||||
|
||||
const result = await new CollectionApi(bridge as never).list(4, 25);
|
||||
|
||||
expect(ticketSpy).toHaveBeenCalledWith(bridge, { domainList: ['weiyun.com'] });
|
||||
expect(listSpy).toHaveBeenCalledWith({
|
||||
uin: '10001',
|
||||
pskey: 'weiyun-ticket',
|
||||
category: 4,
|
||||
count: 25,
|
||||
});
|
||||
expect(result).toBe(expected);
|
||||
});
|
||||
|
||||
it('fails explicitly when QQ does not return a Weiyun p_skey', async () => {
|
||||
const bridge = mockBridge();
|
||||
vi.spyOn(GetPskey, 'invoke').mockResolvedValue({ domainPskeyMap: new Map() });
|
||||
const listSpy = vi.spyOn(collectionWeb, 'getCollectionList');
|
||||
|
||||
await expect(new CollectionApi(bridge as never).list(0, 50))
|
||||
.rejects.toThrow('QQ did not return a p_skey for weiyun.com');
|
||||
expect(listSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user