refactor(protocol): compose group-file URLs in the OIDB namespaces
Move retCode checks and URL assembly into GetGroupFileUrl, GetPrivateFileUrl, and ListGroupFilesPage so GroupFileApi only loops pages and resolves display names.
This commit is contained in:
9 files changed
+104
-82
No files matched your search
@@ -34,12 +34,18 @@ describe('GetGroupFileUrl namespace', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('returns the download sub-message verbatim (URL composition lives on the facade)', async () => {
|
||||
const deps = makeDeps({ download: { downloadDns: 'cdn', downloadUrl: new Uint8Array([0x01]) } as any });
|
||||
const out = await GetGroupFileUrl.invoke(deps, { groupId: 1, fileId: 'f', busId: 102 });
|
||||
expect(out.downloadDns).toBe('cdn');
|
||||
// proton round-trips bytes through a Node Buffer; assert the byte values, not the wrapper class.
|
||||
expect(Array.from(out.downloadUrl ?? new Uint8Array())).toEqual([0x01]);
|
||||
it('composes the https ftn_handler URL and checks download.retCode', async () => {
|
||||
const deps = makeDeps({ download: { downloadDns: 'cdn', downloadUrl: new Uint8Array([0x01, 0x02]) } as any });
|
||||
await expect(GetGroupFileUrl.invoke(deps, { groupId: 1, fileId: 'fid-xyz', busId: 102 }))
|
||||
.resolves.toBe('https://cdn/ftn_handler/0102/?fname=fid-xyz');
|
||||
});
|
||||
|
||||
it('throws when download.retCode is non-zero', async () => {
|
||||
const deps = makeDeps({
|
||||
download: { retCode: 1, retMsg: 'denied', downloadDns: 'cdn', downloadUrl: new Uint8Array([1]) } as any,
|
||||
});
|
||||
await expect(GetGroupFileUrl.invoke(deps, { groupId: 1, fileId: 'f', busId: 102 }))
|
||||
.rejects.toThrow(/group file url failed: code=1/);
|
||||
});
|
||||
|
||||
it('throws when the download sub-message is missing', async () => {
|
||||
@@ -47,4 +53,12 @@ describe('GetGroupFileUrl namespace', () => {
|
||||
await expect(GetGroupFileUrl.invoke(deps, { groupId: 1, fileId: 'f', busId: 102 }))
|
||||
.rejects.toThrow(/url response missing/);
|
||||
});
|
||||
|
||||
it('falls back to downloadIp when downloadDns is empty', async () => {
|
||||
const deps = makeDeps({
|
||||
download: { downloadIp: '1.2.3.4', downloadUrl: new Uint8Array([0xab]) } as any,
|
||||
});
|
||||
await expect(GetGroupFileUrl.invoke(deps, { groupId: 1, fileId: 'fid', busId: 102 }))
|
||||
.resolves.toBe('https://1.2.3.4/ftn_handler/AB/?fname=fid');
|
||||
});
|
||||
});
|
||||
@@ -43,14 +43,12 @@ describe('GetPrivateFileUrl namespace', () => {
|
||||
expect(env.body?.field99999).toEqual(new Uint8Array([0xC0, 0x85, 0x2C, 0x01]));
|
||||
});
|
||||
|
||||
it('returns the result sub-message verbatim', async () => {
|
||||
it('composes the http download URL', async () => {
|
||||
const deps = makeDeps({
|
||||
body: { result: { server: 'srv', port: 8080, url: '/path' } } as any,
|
||||
});
|
||||
const out = await GetPrivateFileUrl.invoke(deps, { selfUid: 's', fileId: 'f', fileHash: 'h' });
|
||||
expect(out.server).toBe('srv');
|
||||
expect(out.port).toBe(8080);
|
||||
expect(out.url).toBe('/path');
|
||||
await expect(GetPrivateFileUrl.invoke(deps, { selfUid: 's', fileId: 'f', fileHash: 'h' }))
|
||||
.resolves.toBe('http://srv:8080/path&isthumb=0');
|
||||
});
|
||||
|
||||
it('throws when result is missing', async () => {
|
||||
@@ -58,4 +56,12 @@ describe('GetPrivateFileUrl namespace', () => {
|
||||
await expect(GetPrivateFileUrl.invoke(deps, { selfUid: 's', fileId: 'f', fileHash: 'h' }))
|
||||
.rejects.toThrow(/private file url response invalid/);
|
||||
});
|
||||
|
||||
it('throws when server/port/url is incomplete', async () => {
|
||||
const deps = makeDeps({
|
||||
body: { result: { server: 'srv', port: 0, url: '/path' } } as any,
|
||||
});
|
||||
await expect(GetPrivateFileUrl.invoke(deps, { selfUid: 's', fileId: 'f', fileHash: 'h' }))
|
||||
.rejects.toThrow(/private file url response invalid/);
|
||||
});
|
||||
});
|
||||
@@ -68,15 +68,23 @@ describe('ListGroupFilesPage namespace', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('returns the list body so the facade can walk items / isEnd', async () => {
|
||||
it('returns items and isEnd after checking list.retCode', async () => {
|
||||
const deps = makeDeps({
|
||||
list: { isEnd: false, items: [{ type: 1 }] } as any,
|
||||
});
|
||||
const out = await ListGroupFilesPage.invoke(deps, {
|
||||
groupId: 1, targetDirectory: '/', startIndex: 0, pageSize: 10,
|
||||
});
|
||||
expect(out?.isEnd ?? false).toBe(false);
|
||||
expect(out?.items).toHaveLength(1);
|
||||
expect(out).toEqual({ items: [expect.objectContaining({ type: 1 })], isEnd: false });
|
||||
});
|
||||
|
||||
it('throws when list.retCode is non-zero', async () => {
|
||||
const deps = makeDeps({
|
||||
list: { retCode: 2, retMsg: 'busy', isEnd: true, items: [] } as any,
|
||||
});
|
||||
await expect(ListGroupFilesPage.invoke(deps, {
|
||||
groupId: 1, targetDirectory: '/', startIndex: 0, pageSize: 10,
|
||||
})).rejects.toThrow(/group file list failed: code=2/);
|
||||
});
|
||||
|
||||
it('decodes the folder last-upload metadata from the QQ wire fields', async () => {
|
||||
|
||||
Reference in new issue
Block a user