refactor(oidb): migrate group-file.ts OIDB cmds to namespaces
Splits the 16 OIDB cmds from GroupFileApi into self-contained
namespaces under @snowluma/bridge/oidb-services/group-file/. Adds
@snowluma/bridge/oidb-services/shared with `toInt` / `ensureRetCodeZero`
helpers so namespaces can validate sub-responses without an
@snowluma/core dependency.
Boundaries:
- Single-OIDB methods (publish / getCount / list-page / *url /
delete / move / *folder) become one-line forwarders.
- 3-stage methods (`upload` / `uploadPrivate`) keep their
orchestration on the facade — OIDB preflight goes through the
new namespace, but highway PUT + publish/sendC2cFile + upload-
cache bookkeeping stay where they are.
- `list` keeps its pagination loop on the facade; the page-fetch
namespace is one call.
- The NTV2-rich-media URL fetchers (group/private × ptt/video)
share a deserialize helper (`parseNtv2DownloadUrl`) so all four
namespaces only differ in their scene block.
Wire-byte equivalence preserved. The 0x6D6 family shares one
OidbGroupFileReq envelope; each namespace populates a different
slot (file / download / delete / move) and proton monomorphizes
per call site as before.
This commit is contained in:
37 files changed
+1900
-564
No files matched your search
@@ -0,0 +1,40 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type {
|
||||
OidbGroupFileFolderReq, OidbGroupFileFolderResp,
|
||||
} from '@snowluma/proto-defs/oidb-actions/group-file';
|
||||
import type { SendPacketResult } from '@snowluma/common/packet-sender';
|
||||
|
||||
import { CreateGroupFolder } from '../../../src/oidb-services/group-file/create-group-folder';
|
||||
|
||||
function makeDeps(body?: OidbGroupFileFolderResp) {
|
||||
const responseData = body !== undefined
|
||||
? Buffer.from(protobuf_encode<OidbBase<OidbGroupFileFolderResp>>({ body }))
|
||||
: Buffer.alloc(0);
|
||||
const r: SendPacketResult = { success: true, gotResponse: true, errorCode: 0, errorMessage: '', responseData };
|
||||
return { sendRawPacket: vi.fn(async () => r) };
|
||||
}
|
||||
|
||||
describe('CreateGroupFolder namespace', () => {
|
||||
it('declares 0x6D7_0 with uinForm=true', () => {
|
||||
expect(CreateGroupFolder.command).toBe(0x6D7);
|
||||
expect(CreateGroupFolder.subCommand).toBe(0);
|
||||
expect(CreateGroupFolder.uinForm).toBe(true);
|
||||
});
|
||||
|
||||
it('packages create.{groupUin, rootDirectory, folderName}', async () => {
|
||||
const deps = makeDeps({ create: {} as any });
|
||||
await CreateGroupFolder.invoke(deps, { groupId: 12345, parentId: '/', folderName: 'docs' });
|
||||
const env = protobuf_decode<OidbBase<OidbGroupFileFolderReq>>(deps.sendRawPacket.mock.calls[0]![1]);
|
||||
expect(env.body?.create).toMatchObject({
|
||||
groupUin: 12345, rootDirectory: '/', folderName: 'docs',
|
||||
});
|
||||
});
|
||||
|
||||
it('throws on retcode != 0 (note: lower-case retcode in this proto)', async () => {
|
||||
const deps = makeDeps({ create: { retcode: 7, retMsg: 'denied' } as any });
|
||||
await expect(CreateGroupFolder.invoke(deps, { groupId: 1, parentId: '/', folderName: 'f' }))
|
||||
.rejects.toThrow(/code=7/);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,46 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type {
|
||||
OidbGroupFileReq, OidbGroupFileResp,
|
||||
} from '@snowluma/proto-defs/oidb-actions/group-file';
|
||||
import type { SendPacketResult } from '@snowluma/common/packet-sender';
|
||||
|
||||
import { DeleteGroupFile } from '../../../src/oidb-services/group-file/delete-group-file';
|
||||
|
||||
function makeDeps(body?: OidbGroupFileResp) {
|
||||
const responseData = body !== undefined
|
||||
? Buffer.from(protobuf_encode<OidbBase<OidbGroupFileResp>>({ body }))
|
||||
: Buffer.alloc(0);
|
||||
const r: SendPacketResult = { success: true, gotResponse: true, errorCode: 0, errorMessage: '', responseData };
|
||||
return { sendRawPacket: vi.fn(async () => r) };
|
||||
}
|
||||
|
||||
describe('DeleteGroupFile namespace', () => {
|
||||
it('declares 0x6D6_3 with uinForm=true', () => {
|
||||
expect(DeleteGroupFile.command).toBe(0x6D6);
|
||||
expect(DeleteGroupFile.subCommand).toBe(3);
|
||||
expect(DeleteGroupFile.uinForm).toBe(true);
|
||||
});
|
||||
|
||||
it('packages busId=102 and routes to 0x6d6_3', async () => {
|
||||
const deps = makeDeps({ delete: {} as any });
|
||||
await DeleteGroupFile.invoke(deps, { groupId: 12345, fileId: 'fid' });
|
||||
const [wire, bytes] = deps.sendRawPacket.mock.calls[0]!;
|
||||
expect(wire).toBe('OidbSvcTrpcTcp.0x6d6_3');
|
||||
const env = protobuf_decode<OidbBase<OidbGroupFileReq>>(bytes);
|
||||
expect(env.body?.delete).toMatchObject({ groupUin: 12345, busId: 102, fileId: 'fid' });
|
||||
});
|
||||
|
||||
it('throws on missing delete sub-message', async () => {
|
||||
const deps = makeDeps({});
|
||||
await expect(DeleteGroupFile.invoke(deps, { groupId: 1, fileId: 'f' }))
|
||||
.rejects.toThrow(/delete response missing/);
|
||||
});
|
||||
|
||||
it('throws on non-zero retCode', async () => {
|
||||
const deps = makeDeps({ delete: { retCode: 5, retMsg: 'no perms' } as any });
|
||||
await expect(DeleteGroupFile.invoke(deps, { groupId: 1, fileId: 'f' }))
|
||||
.rejects.toThrow(/code=5/);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,38 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type {
|
||||
OidbGroupFileFolderReq, OidbGroupFileFolderResp,
|
||||
} from '@snowluma/proto-defs/oidb-actions/group-file';
|
||||
import type { SendPacketResult } from '@snowluma/common/packet-sender';
|
||||
|
||||
import { DeleteGroupFolder } from '../../../src/oidb-services/group-file/delete-group-folder';
|
||||
|
||||
function makeDeps(body?: OidbGroupFileFolderResp) {
|
||||
const responseData = body !== undefined
|
||||
? Buffer.from(protobuf_encode<OidbBase<OidbGroupFileFolderResp>>({ body }))
|
||||
: Buffer.alloc(0);
|
||||
const r: SendPacketResult = { success: true, gotResponse: true, errorCode: 0, errorMessage: '', responseData };
|
||||
return { sendRawPacket: vi.fn(async () => r) };
|
||||
}
|
||||
|
||||
describe('DeleteGroupFolder namespace', () => {
|
||||
it('declares 0x6D7_1 with uinForm=true', () => {
|
||||
expect(DeleteGroupFolder.command).toBe(0x6D7);
|
||||
expect(DeleteGroupFolder.subCommand).toBe(1);
|
||||
expect(DeleteGroupFolder.uinForm).toBe(true);
|
||||
});
|
||||
|
||||
it('packages delete.{groupUin, folderId}', async () => {
|
||||
const deps = makeDeps({ delete: {} as any });
|
||||
await DeleteGroupFolder.invoke(deps, { groupId: 12345, folderId: 'fid' });
|
||||
const env = protobuf_decode<OidbBase<OidbGroupFileFolderReq>>(deps.sendRawPacket.mock.calls[0]![1]);
|
||||
expect(env.body?.delete).toMatchObject({ groupUin: 12345, folderId: 'fid' });
|
||||
});
|
||||
|
||||
it('throws on missing delete sub-message', async () => {
|
||||
const deps = makeDeps({});
|
||||
await expect(DeleteGroupFolder.invoke(deps, { groupId: 1, folderId: 'f' }))
|
||||
.rejects.toThrow(/folder delete response missing/);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,45 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type {
|
||||
OidbGroupFileCountViewReq, OidbGroupFileCountViewResp,
|
||||
} from '@snowluma/proto-defs/oidb-actions/group-file';
|
||||
import type { SendPacketResult } from '@snowluma/common/packet-sender';
|
||||
|
||||
import { GetGroupFileCount } from '../../../src/oidb-services/group-file/get-group-file-count';
|
||||
|
||||
function makeDeps(body?: OidbGroupFileCountViewResp) {
|
||||
const responseData = body !== undefined
|
||||
? Buffer.from(protobuf_encode<OidbBase<OidbGroupFileCountViewResp>>({ body }))
|
||||
: Buffer.alloc(0);
|
||||
const r: SendPacketResult = { success: true, gotResponse: true, errorCode: 0, errorMessage: '', responseData };
|
||||
return { sendRawPacket: vi.fn(async () => r) };
|
||||
}
|
||||
|
||||
describe('GetGroupFileCount namespace', () => {
|
||||
it('declares 0x6D8_3', () => {
|
||||
expect(GetGroupFileCount.command).toBe(0x6D8);
|
||||
expect(GetGroupFileCount.subCommand).toBe(3);
|
||||
});
|
||||
|
||||
it('routes to 0x6d8_3 with groupUin + appId=7 + busId=0', async () => {
|
||||
const deps = makeDeps({ count: { fileCount: 1, maxCount: 100 } });
|
||||
await GetGroupFileCount.invoke(deps, { groupId: 12345 });
|
||||
const [wire, bytes] = deps.sendRawPacket.mock.calls[0]!;
|
||||
expect(wire).toBe('OidbSvcTrpcTcp.0x6d8_3');
|
||||
const env = protobuf_decode<OidbBase<OidbGroupFileCountViewReq>>(bytes);
|
||||
expect(env.body?.count).toMatchObject({ groupUin: 12345, appId: 7 });
|
||||
});
|
||||
|
||||
it('decodes both counters as plain numbers', async () => {
|
||||
const deps = makeDeps({ count: { fileCount: 42, maxCount: 1000 } });
|
||||
const out = await GetGroupFileCount.invoke(deps, { groupId: 1 });
|
||||
expect(out).toEqual({ fileCount: 42, maxCount: 1000 });
|
||||
});
|
||||
|
||||
it('falls back to maxCount=10000 when the server elides it', async () => {
|
||||
const deps = makeDeps({ count: {} });
|
||||
const out = await GetGroupFileCount.invoke(deps, { groupId: 1 });
|
||||
expect(out).toEqual({ fileCount: 0, maxCount: 10000 });
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,50 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type {
|
||||
OidbGroupFileReq, OidbGroupFileResp,
|
||||
} from '@snowluma/proto-defs/oidb-actions/group-file';
|
||||
import type { SendPacketResult } from '@snowluma/common/packet-sender';
|
||||
|
||||
import { GetGroupFileUrl } from '../../../src/oidb-services/group-file/get-group-file-url';
|
||||
|
||||
function makeDeps(body?: OidbGroupFileResp) {
|
||||
const responseData = body !== undefined
|
||||
? Buffer.from(protobuf_encode<OidbBase<OidbGroupFileResp>>({ body }))
|
||||
: Buffer.alloc(0);
|
||||
const r: SendPacketResult = { success: true, gotResponse: true, errorCode: 0, errorMessage: '', responseData };
|
||||
return { sendRawPacket: vi.fn(async () => r) };
|
||||
}
|
||||
|
||||
describe('GetGroupFileUrl namespace', () => {
|
||||
it('declares 0x6D6_2 with uinForm=true', () => {
|
||||
expect(GetGroupFileUrl.command).toBe(0x6D6);
|
||||
expect(GetGroupFileUrl.subCommand).toBe(2);
|
||||
expect(GetGroupFileUrl.uinForm).toBe(true);
|
||||
});
|
||||
|
||||
it('packages the download slot with the supplied busId', async () => {
|
||||
const deps = makeDeps({ download: { downloadDns: 'cdn', downloadUrl: new Uint8Array([1, 2]) } as any });
|
||||
await GetGroupFileUrl.invoke(deps, { groupId: 12345, fileId: 'fid', busId: 102 });
|
||||
const [wire, bytes] = deps.sendRawPacket.mock.calls[0]!;
|
||||
expect(wire).toBe('OidbSvcTrpcTcp.0x6d6_2');
|
||||
const env = protobuf_decode<OidbBase<OidbGroupFileReq>>(bytes);
|
||||
expect(env.body?.download).toMatchObject({
|
||||
groupUin: 12345, appId: 7, busId: 102, fileId: 'fid',
|
||||
});
|
||||
});
|
||||
|
||||
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('throws when the download sub-message is missing', async () => {
|
||||
const deps = makeDeps({});
|
||||
await expect(GetGroupFileUrl.invoke(deps, { groupId: 1, fileId: 'f', busId: 102 }))
|
||||
.rejects.toThrow(/url response missing/);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,51 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type { NTV2RichMediaReq, NTV2RichMediaResp } from '@snowluma/proto-defs/oidb-actions/media';
|
||||
import type { SendPacketResult } from '@snowluma/common/packet-sender';
|
||||
|
||||
import { GetGroupPttUrl } from '../../../src/oidb-services/group-file/get-group-ptt-url';
|
||||
|
||||
function makeDeps(body?: NTV2RichMediaResp) {
|
||||
const responseData = body !== undefined
|
||||
? Buffer.from(protobuf_encode<OidbBase<NTV2RichMediaResp>>({ body }))
|
||||
: Buffer.alloc(0);
|
||||
const r: SendPacketResult = { success: true, gotResponse: true, errorCode: 0, errorMessage: '', responseData };
|
||||
return { sendRawPacket: vi.fn(async () => r) };
|
||||
}
|
||||
|
||||
describe('GetGroupPttUrl namespace', () => {
|
||||
it('declares 0x126E_200 with uinForm=true', () => {
|
||||
expect(GetGroupPttUrl.command).toBe(0x126E);
|
||||
expect(GetGroupPttUrl.subCommand).toBe(200);
|
||||
expect(GetGroupPttUrl.uinForm).toBe(true);
|
||||
});
|
||||
|
||||
it('emits scene{requestType=1, businessType=3, sceneType=2, group.groupUin}', async () => {
|
||||
const deps = makeDeps({
|
||||
respHead: { retCode: 0 },
|
||||
download: { info: { domain: 'd', urlPath: '/p' }, rKeyParam: '?rk' },
|
||||
} as any);
|
||||
await GetGroupPttUrl.invoke(deps, { groupId: 12345, node: { fileUuid: 'uuid' } });
|
||||
const env = protobuf_decode<OidbBase<NTV2RichMediaReq>>(deps.sendRawPacket.mock.calls[0]![1]);
|
||||
expect(env.body?.reqHead?.scene).toMatchObject({
|
||||
requestType: 1, businessType: 3, sceneType: 2,
|
||||
group: { groupUin: 12345 },
|
||||
});
|
||||
});
|
||||
|
||||
it('composes the https://domain<path><rkey> URL', async () => {
|
||||
const deps = makeDeps({
|
||||
respHead: { retCode: 0 },
|
||||
download: { info: { domain: 'cdn.qq', urlPath: '/x' }, rKeyParam: '?r=1' },
|
||||
} as any);
|
||||
const out = await GetGroupPttUrl.invoke(deps, { groupId: 1, node: { fileUuid: 'uuid' } });
|
||||
expect(out).toBe('https://cdn.qq/x?r=1');
|
||||
});
|
||||
|
||||
it('throws when fileUuid is missing on the node', async () => {
|
||||
const deps = makeDeps({} as any);
|
||||
await expect(GetGroupPttUrl.invoke(deps, { groupId: 1, node: {} }))
|
||||
.rejects.toThrow(/fileUuid is required/);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,45 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type { NTV2RichMediaReq, NTV2RichMediaResp } from '@snowluma/proto-defs/oidb-actions/media';
|
||||
import type { SendPacketResult } from '@snowluma/common/packet-sender';
|
||||
|
||||
import { GetGroupVideoUrl } from '../../../src/oidb-services/group-file/get-group-video-url';
|
||||
|
||||
function makeDeps(body?: NTV2RichMediaResp) {
|
||||
const responseData = body !== undefined
|
||||
? Buffer.from(protobuf_encode<OidbBase<NTV2RichMediaResp>>({ body }))
|
||||
: Buffer.alloc(0);
|
||||
const r: SendPacketResult = { success: true, gotResponse: true, errorCode: 0, errorMessage: '', responseData };
|
||||
return { sendRawPacket: vi.fn(async () => r) };
|
||||
}
|
||||
|
||||
describe('GetGroupVideoUrl namespace', () => {
|
||||
it('declares 0x11EA_200 with uinForm=true', () => {
|
||||
expect(GetGroupVideoUrl.command).toBe(0x11EA);
|
||||
expect(GetGroupVideoUrl.subCommand).toBe(200);
|
||||
expect(GetGroupVideoUrl.uinForm).toBe(true);
|
||||
});
|
||||
|
||||
it('emits scene{requestType=2, businessType=2, sceneType=2, group}', async () => {
|
||||
const deps = makeDeps({
|
||||
respHead: { retCode: 0 },
|
||||
download: { info: { domain: 'd', urlPath: '/v' }, rKeyParam: '' },
|
||||
} as any);
|
||||
await GetGroupVideoUrl.invoke(deps, { groupId: 12345, node: { fileUuid: 'uuid' } });
|
||||
const env = protobuf_decode<OidbBase<NTV2RichMediaReq>>(deps.sendRawPacket.mock.calls[0]![1]);
|
||||
expect(env.body?.reqHead?.scene).toMatchObject({
|
||||
requestType: 2, businessType: 2, sceneType: 2,
|
||||
group: { groupUin: 12345 },
|
||||
});
|
||||
});
|
||||
|
||||
it('bubbles up retCode != 0 via the shared ntv2 deserializer', async () => {
|
||||
const deps = makeDeps({
|
||||
respHead: { retCode: 99, message: 'gone' },
|
||||
download: { info: { domain: 'd', urlPath: '/p' }, rKeyParam: '' },
|
||||
} as any);
|
||||
await expect(GetGroupVideoUrl.invoke(deps, { groupId: 1, node: { fileUuid: 'u' } }))
|
||||
.rejects.toThrow(/code=99/);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,61 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type {
|
||||
OidbPrivateFileDownloadReq, OidbPrivateFileDownloadResp,
|
||||
} from '@snowluma/proto-defs/oidb-actions/media';
|
||||
import type { SendPacketResult } from '@snowluma/common/packet-sender';
|
||||
|
||||
import { GetPrivateFileUrl } from '../../../src/oidb-services/group-file/get-private-file-url';
|
||||
|
||||
function makeDeps(body?: OidbPrivateFileDownloadResp) {
|
||||
const responseData = body !== undefined
|
||||
? Buffer.from(protobuf_encode<OidbBase<OidbPrivateFileDownloadResp>>({ body }))
|
||||
: Buffer.alloc(0);
|
||||
const r: SendPacketResult = { success: true, gotResponse: true, errorCode: 0, errorMessage: '', responseData };
|
||||
return { sendRawPacket: vi.fn(async () => r) };
|
||||
}
|
||||
|
||||
describe('GetPrivateFileUrl namespace', () => {
|
||||
it('declares 0xE37_1200', () => {
|
||||
expect(GetPrivateFileUrl.command).toBe(0xE37);
|
||||
expect(GetPrivateFileUrl.subCommand).toBe(1200);
|
||||
});
|
||||
|
||||
it('packages the magic field99999 cookie + body fields', async () => {
|
||||
const deps = makeDeps({
|
||||
body: { result: { server: 'host', port: 80, url: '/u' } } as any,
|
||||
});
|
||||
await GetPrivateFileUrl.invoke(deps, { selfUid: 'self', fileId: 'fid', fileHash: 'h' });
|
||||
const [wire, bytes] = deps.sendRawPacket.mock.calls[0]!;
|
||||
expect(wire).toBe('OidbSvcTrpcTcp.0xe37_1200');
|
||||
const env = protobuf_decode<OidbBase<OidbPrivateFileDownloadReq>>(bytes);
|
||||
expect(env.body).toMatchObject({
|
||||
subCommand: 1200,
|
||||
field2: 1,
|
||||
field101: 3,
|
||||
field102: 103,
|
||||
field200: 1,
|
||||
});
|
||||
expect(env.body?.body).toMatchObject({
|
||||
receiverUid: 'self', fileUuid: 'fid', type: 2, fileHash: 'h',
|
||||
});
|
||||
expect(env.body?.field99999).toEqual(new Uint8Array([0xC0, 0x85, 0x2C, 0x01]));
|
||||
});
|
||||
|
||||
it('returns the result sub-message verbatim', 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');
|
||||
});
|
||||
|
||||
it('throws when result is missing', async () => {
|
||||
const deps = makeDeps({ body: {} });
|
||||
await expect(GetPrivateFileUrl.invoke(deps, { selfUid: 's', fileId: 'f', fileHash: 'h' }))
|
||||
.rejects.toThrow(/private file url response invalid/);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,36 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type { NTV2RichMediaReq, NTV2RichMediaResp } from '@snowluma/proto-defs/oidb-actions/media';
|
||||
import type { SendPacketResult } from '@snowluma/common/packet-sender';
|
||||
|
||||
import { GetPrivatePttUrl } from '../../../src/oidb-services/group-file/get-private-ptt-url';
|
||||
|
||||
function makeDeps(body?: NTV2RichMediaResp) {
|
||||
const responseData = body !== undefined
|
||||
? Buffer.from(protobuf_encode<OidbBase<NTV2RichMediaResp>>({ body }))
|
||||
: Buffer.alloc(0);
|
||||
const r: SendPacketResult = { success: true, gotResponse: true, errorCode: 0, errorMessage: '', responseData };
|
||||
return { sendRawPacket: vi.fn(async () => r) };
|
||||
}
|
||||
|
||||
describe('GetPrivatePttUrl namespace', () => {
|
||||
it('declares 0x126D_200 with uinForm=true', () => {
|
||||
expect(GetPrivatePttUrl.command).toBe(0x126D);
|
||||
expect(GetPrivatePttUrl.subCommand).toBe(200);
|
||||
expect(GetPrivatePttUrl.uinForm).toBe(true);
|
||||
});
|
||||
|
||||
it('emits c2c scene with self uid as targetUid', async () => {
|
||||
const deps = makeDeps({
|
||||
respHead: { retCode: 0 },
|
||||
download: { info: { domain: 'd', urlPath: '/p' }, rKeyParam: '' },
|
||||
} as any);
|
||||
await GetPrivatePttUrl.invoke(deps, { selfUid: 'self', node: { fileUuid: 'uuid' } });
|
||||
const env = protobuf_decode<OidbBase<NTV2RichMediaReq>>(deps.sendRawPacket.mock.calls[0]![1]);
|
||||
expect(env.body?.reqHead?.scene).toMatchObject({
|
||||
requestType: 1, businessType: 3, sceneType: 1,
|
||||
c2c: { accountType: 2, targetUid: 'self' },
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,36 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type { NTV2RichMediaReq, NTV2RichMediaResp } from '@snowluma/proto-defs/oidb-actions/media';
|
||||
import type { SendPacketResult } from '@snowluma/common/packet-sender';
|
||||
|
||||
import { GetPrivateVideoUrl } from '../../../src/oidb-services/group-file/get-private-video-url';
|
||||
|
||||
function makeDeps(body?: NTV2RichMediaResp) {
|
||||
const responseData = body !== undefined
|
||||
? Buffer.from(protobuf_encode<OidbBase<NTV2RichMediaResp>>({ body }))
|
||||
: Buffer.alloc(0);
|
||||
const r: SendPacketResult = { success: true, gotResponse: true, errorCode: 0, errorMessage: '', responseData };
|
||||
return { sendRawPacket: vi.fn(async () => r) };
|
||||
}
|
||||
|
||||
describe('GetPrivateVideoUrl namespace', () => {
|
||||
it('declares 0x11E9_200 with uinForm=true', () => {
|
||||
expect(GetPrivateVideoUrl.command).toBe(0x11E9);
|
||||
expect(GetPrivateVideoUrl.subCommand).toBe(200);
|
||||
expect(GetPrivateVideoUrl.uinForm).toBe(true);
|
||||
});
|
||||
|
||||
it('emits c2c scene with self uid as targetUid', async () => {
|
||||
const deps = makeDeps({
|
||||
respHead: { retCode: 0 },
|
||||
download: { info: { domain: 'd', urlPath: '/v' }, rKeyParam: '' },
|
||||
} as any);
|
||||
await GetPrivateVideoUrl.invoke(deps, { selfUid: 'self', node: { fileUuid: 'uuid' } });
|
||||
const env = protobuf_decode<OidbBase<NTV2RichMediaReq>>(deps.sendRawPacket.mock.calls[0]![1]);
|
||||
expect(env.body?.reqHead?.scene).toMatchObject({
|
||||
requestType: 2, businessType: 2, sceneType: 1,
|
||||
c2c: { accountType: 2, targetUid: 'self' },
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,58 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type {
|
||||
OidbGroupFileViewReq, OidbGroupFileViewResp,
|
||||
} from '@snowluma/proto-defs/oidb-actions/group-file';
|
||||
import type { SendPacketResult } from '@snowluma/common/packet-sender';
|
||||
|
||||
import { ListGroupFilesPage } from '../../../src/oidb-services/group-file/list-group-files-page';
|
||||
|
||||
function makeDeps(body?: OidbGroupFileViewResp) {
|
||||
const responseData = body !== undefined
|
||||
? Buffer.from(protobuf_encode<OidbBase<OidbGroupFileViewResp>>({ body }))
|
||||
: Buffer.alloc(0);
|
||||
const r: SendPacketResult = { success: true, gotResponse: true, errorCode: 0, errorMessage: '', responseData };
|
||||
return { sendRawPacket: vi.fn(async () => r) };
|
||||
}
|
||||
|
||||
describe('ListGroupFilesPage namespace', () => {
|
||||
it('declares 0x6D8_1 with uinForm=true', () => {
|
||||
expect(ListGroupFilesPage.command).toBe(0x6D8);
|
||||
expect(ListGroupFilesPage.subCommand).toBe(1);
|
||||
expect(ListGroupFilesPage.uinForm).toBe(true);
|
||||
});
|
||||
|
||||
it('packages the page parameters (sortBy=1, field17=2, field18=0)', async () => {
|
||||
const deps = makeDeps({ list: { isEnd: true, items: [] } as any });
|
||||
await ListGroupFilesPage.invoke(deps, {
|
||||
groupId: 12345, targetDirectory: '/a', startIndex: 20, pageSize: 50,
|
||||
});
|
||||
const env = protobuf_decode<OidbBase<OidbGroupFileViewReq>>(deps.sendRawPacket.mock.calls[0]![1]);
|
||||
expect(env.body?.list).toMatchObject({
|
||||
groupUin: 12345, appId: 7,
|
||||
targetDirectory: '/a', fileCount: 50,
|
||||
sortBy: 1, startIndex: 20,
|
||||
field17: 2,
|
||||
});
|
||||
});
|
||||
|
||||
it('returns the list body so the facade can walk items / isEnd', 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);
|
||||
});
|
||||
|
||||
it('returns null when the server elides the list slot', async () => {
|
||||
const deps = makeDeps({});
|
||||
const out = await ListGroupFilesPage.invoke(deps, {
|
||||
groupId: 1, targetDirectory: '/', startIndex: 0, pageSize: 10,
|
||||
});
|
||||
expect(out).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,45 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type {
|
||||
OidbGroupFileReq, OidbGroupFileResp,
|
||||
} from '@snowluma/proto-defs/oidb-actions/group-file';
|
||||
import type { SendPacketResult } from '@snowluma/common/packet-sender';
|
||||
|
||||
import { MoveGroupFile } from '../../../src/oidb-services/group-file/move-group-file';
|
||||
|
||||
function makeDeps(body?: OidbGroupFileResp) {
|
||||
const responseData = body !== undefined
|
||||
? Buffer.from(protobuf_encode<OidbBase<OidbGroupFileResp>>({ body }))
|
||||
: Buffer.alloc(0);
|
||||
const r: SendPacketResult = { success: true, gotResponse: true, errorCode: 0, errorMessage: '', responseData };
|
||||
return { sendRawPacket: vi.fn(async () => r) };
|
||||
}
|
||||
|
||||
describe('MoveGroupFile namespace', () => {
|
||||
it('declares 0x6D6_5 with uinForm=true', () => {
|
||||
expect(MoveGroupFile.command).toBe(0x6D6);
|
||||
expect(MoveGroupFile.subCommand).toBe(5);
|
||||
expect(MoveGroupFile.uinForm).toBe(true);
|
||||
});
|
||||
|
||||
it('packages parent + target directories under the move slot', async () => {
|
||||
const deps = makeDeps({ move: {} as any });
|
||||
await MoveGroupFile.invoke(deps, {
|
||||
groupId: 12345, fileId: 'fid',
|
||||
parentDirectory: '/a', targetDirectory: '/b',
|
||||
});
|
||||
const env = protobuf_decode<OidbBase<OidbGroupFileReq>>(deps.sendRawPacket.mock.calls[0]![1]);
|
||||
expect(env.body?.move).toMatchObject({
|
||||
groupUin: 12345, appId: 7, busId: 102, fileId: 'fid',
|
||||
parentDirectory: '/a', targetDirectory: '/b',
|
||||
});
|
||||
});
|
||||
|
||||
it('throws on missing move sub-message', async () => {
|
||||
const deps = makeDeps({});
|
||||
await expect(MoveGroupFile.invoke(deps, {
|
||||
groupId: 1, fileId: 'f', parentDirectory: '/', targetDirectory: '/',
|
||||
})).rejects.toThrow(/move response missing/);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,41 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { protobuf_decode } from '@snowluma/proton';
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type { OidbGroupSendFileReq } from '@snowluma/proto-defs/oidb-actions/group-file';
|
||||
import type { SendPacketResult } from '@snowluma/common/packet-sender';
|
||||
|
||||
import { PublishGroupFile } from '../../../src/oidb-services/group-file/publish-group-file';
|
||||
|
||||
function makeDeps() {
|
||||
const r: SendPacketResult = { success: true, gotResponse: true, errorCode: 0, errorMessage: '', responseData: Buffer.alloc(0) };
|
||||
return { sendRawPacket: vi.fn(async () => r) };
|
||||
}
|
||||
|
||||
describe('PublishGroupFile namespace', () => {
|
||||
it('declares 0x6D9_4', () => {
|
||||
expect(PublishGroupFile.command).toBe(0x6D9);
|
||||
expect(PublishGroupFile.subCommand).toBe(4);
|
||||
});
|
||||
|
||||
it('routes to 0x6d9_4 with busiType=102, type=2, field5=true', async () => {
|
||||
const deps = makeDeps();
|
||||
await PublishGroupFile.invoke(deps, { groupId: 12345, fileId: 'fid' });
|
||||
const [wire, bytes] = deps.sendRawPacket.mock.calls[0]!;
|
||||
expect(wire).toBe('OidbSvcTrpcTcp.0x6d9_4');
|
||||
const env = protobuf_decode<OidbBase<OidbGroupSendFileReq>>(bytes);
|
||||
expect(env.body?.body).toMatchObject({
|
||||
groupUin: 12345, type: 2,
|
||||
info: expect.objectContaining({ busiType: 102, fileId: 'fid', field5: true }),
|
||||
});
|
||||
});
|
||||
|
||||
it('emits a non-zero `info.field3` random discriminator', async () => {
|
||||
// Lagrange-V2 sets this to `Random.Shared.Next()`; our serialize uses
|
||||
// Math.random() — both produce a 31-bit unsigned int, never 0.
|
||||
const deps = makeDeps();
|
||||
await PublishGroupFile.invoke(deps, { groupId: 1, fileId: 'f' });
|
||||
const env = protobuf_decode<OidbBase<OidbGroupSendFileReq>>(deps.sendRawPacket.mock.calls[0]![1]);
|
||||
const field3 = env.body?.body?.info?.field3 ?? 0;
|
||||
expect(typeof field3).toBe('number');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,43 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type {
|
||||
OidbGroupFileFolderReq, OidbGroupFileFolderResp,
|
||||
} from '@snowluma/proto-defs/oidb-actions/group-file';
|
||||
import type { SendPacketResult } from '@snowluma/common/packet-sender';
|
||||
|
||||
import { RenameGroupFolder } from '../../../src/oidb-services/group-file/rename-group-folder';
|
||||
|
||||
function makeDeps(body?: OidbGroupFileFolderResp) {
|
||||
const responseData = body !== undefined
|
||||
? Buffer.from(protobuf_encode<OidbBase<OidbGroupFileFolderResp>>({ body }))
|
||||
: Buffer.alloc(0);
|
||||
const r: SendPacketResult = { success: true, gotResponse: true, errorCode: 0, errorMessage: '', responseData };
|
||||
return { sendRawPacket: vi.fn(async () => r) };
|
||||
}
|
||||
|
||||
describe('RenameGroupFolder namespace', () => {
|
||||
it('declares 0x6D7_2 with uinForm=true', () => {
|
||||
expect(RenameGroupFolder.command).toBe(0x6D7);
|
||||
expect(RenameGroupFolder.subCommand).toBe(2);
|
||||
expect(RenameGroupFolder.uinForm).toBe(true);
|
||||
});
|
||||
|
||||
it('packages rename.{groupUin, folderId, newFolderName}', async () => {
|
||||
const deps = makeDeps({ rename: {} as any });
|
||||
await RenameGroupFolder.invoke(deps, {
|
||||
groupId: 12345, folderId: 'fid', newFolderName: 'newname',
|
||||
});
|
||||
const env = protobuf_decode<OidbBase<OidbGroupFileFolderReq>>(deps.sendRawPacket.mock.calls[0]![1]);
|
||||
expect(env.body?.rename).toMatchObject({
|
||||
groupUin: 12345, folderId: 'fid', newFolderName: 'newname',
|
||||
});
|
||||
});
|
||||
|
||||
it('throws on missing rename sub-message', async () => {
|
||||
const deps = makeDeps({});
|
||||
await expect(RenameGroupFolder.invoke(deps, {
|
||||
groupId: 1, folderId: 'f', newFolderName: 'n',
|
||||
})).rejects.toThrow(/folder rename response missing/);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,64 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type {
|
||||
OidbGroupFileReq, OidbGroupFileResp,
|
||||
} from '@snowluma/proto-defs/oidb-actions/group-file';
|
||||
import type { SendPacketResult } from '@snowluma/common/packet-sender';
|
||||
|
||||
import { UploadGroupFileRequest } from '../../../src/oidb-services/group-file/upload-group-file-request';
|
||||
|
||||
function makeDeps(body?: OidbGroupFileResp) {
|
||||
const responseData = body !== undefined
|
||||
? Buffer.from(protobuf_encode<OidbBase<OidbGroupFileResp>>({ body }))
|
||||
: Buffer.alloc(0);
|
||||
const r: SendPacketResult = { success: true, gotResponse: true, errorCode: 0, errorMessage: '', responseData };
|
||||
return { sendRawPacket: vi.fn(async () => r) };
|
||||
}
|
||||
|
||||
describe('UploadGroupFileRequest namespace', () => {
|
||||
it('declares 0x6D6_0 with uinForm=true', () => {
|
||||
expect(UploadGroupFileRequest.command).toBe(0x6D6);
|
||||
expect(UploadGroupFileRequest.subCommand).toBe(0);
|
||||
expect(UploadGroupFileRequest.uinForm).toBe(true);
|
||||
});
|
||||
|
||||
it('packages the file pre-flight slot (entrance=6, appId=4, busId=102)', async () => {
|
||||
const deps = makeDeps({ upload: { fileId: 'fid', boolFileExist: true } as any });
|
||||
await UploadGroupFileRequest.invoke(deps, {
|
||||
groupId: 12345,
|
||||
fileName: 'doc.pdf',
|
||||
folderId: '/',
|
||||
fileSize: 1024,
|
||||
fileSha1: new Uint8Array(20),
|
||||
fileMd5: new Uint8Array(16),
|
||||
});
|
||||
const [wire, bytes] = deps.sendRawPacket.mock.calls[0]!;
|
||||
expect(wire).toBe('OidbSvcTrpcTcp.0x6d6_0');
|
||||
const env = protobuf_decode<OidbBase<OidbGroupFileReq>>(bytes);
|
||||
expect(env.reserved).toBe(1); // uinForm
|
||||
expect(env.body?.file).toMatchObject({
|
||||
groupUin: 12345, appId: 4, busId: 102, entrance: 6,
|
||||
targetDirectory: '/', fileName: 'doc.pdf', localDirectory: '/doc.pdf',
|
||||
fileSize: 1024n, field15: true,
|
||||
});
|
||||
});
|
||||
|
||||
it('returns the upload-info body for the facade orchestration', async () => {
|
||||
const deps = makeDeps({ upload: { fileId: 'fid-X', boolFileExist: true } as any });
|
||||
const out = await UploadGroupFileRequest.invoke(deps, {
|
||||
groupId: 1, fileName: 'f', folderId: '/',
|
||||
fileSize: 0, fileSha1: new Uint8Array(0), fileMd5: new Uint8Array(0),
|
||||
});
|
||||
expect(out.fileId).toBe('fid-X');
|
||||
expect(out.boolFileExist).toBe(true);
|
||||
});
|
||||
|
||||
it('throws when the upload sub-message is missing', async () => {
|
||||
const deps = makeDeps({});
|
||||
await expect(UploadGroupFileRequest.invoke(deps, {
|
||||
groupId: 1, fileName: 'f', folderId: '/',
|
||||
fileSize: 0, fileSha1: new Uint8Array(0), fileMd5: new Uint8Array(0),
|
||||
})).rejects.toThrow(/upload response missing/);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,68 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type {
|
||||
OidbPrivateFileUploadReq, OidbPrivateFileUploadResp,
|
||||
} from '@snowluma/proto-defs/oidb-actions/media';
|
||||
import type { SendPacketResult } from '@snowluma/common/packet-sender';
|
||||
|
||||
import { UploadPrivateFileRequest } from '../../../src/oidb-services/group-file/upload-private-file-request';
|
||||
|
||||
function makeDeps(body?: OidbPrivateFileUploadResp) {
|
||||
const responseData = body !== undefined
|
||||
? Buffer.from(protobuf_encode<OidbBase<OidbPrivateFileUploadResp>>({ body }))
|
||||
: Buffer.alloc(0);
|
||||
const r: SendPacketResult = { success: true, gotResponse: true, errorCode: 0, errorMessage: '', responseData };
|
||||
return { sendRawPacket: vi.fn(async () => r) };
|
||||
}
|
||||
|
||||
describe('UploadPrivateFileRequest namespace', () => {
|
||||
it('declares 0xE37_1700', () => {
|
||||
expect(UploadPrivateFileRequest.command).toBe(0xE37);
|
||||
expect(UploadPrivateFileRequest.subCommand).toBe(1700);
|
||||
});
|
||||
|
||||
it('packages businessId=3, clientType=1, flagSupportMediaPlatform=1 alongside the upload body', async () => {
|
||||
const deps = makeDeps({ upload: { uuid: 'fid', boolFileExist: true } as any });
|
||||
await UploadPrivateFileRequest.invoke(deps, {
|
||||
senderUid: 's', receiverUid: 'r',
|
||||
fileName: 'f.pdf', fileSize: 4096,
|
||||
fileSha1: new Uint8Array(20), fileMd5: new Uint8Array(16),
|
||||
md510MCheckSum: new Uint8Array(16),
|
||||
});
|
||||
const [wire, bytes] = deps.sendRawPacket.mock.calls[0]!;
|
||||
expect(wire).toBe('OidbSvcTrpcTcp.0xe37_1700');
|
||||
const env = protobuf_decode<OidbBase<OidbPrivateFileUploadReq>>(bytes);
|
||||
expect(env.body).toMatchObject({
|
||||
command: 1700, businessId: 3, clientType: 1, flagSupportMediaPlatform: 1,
|
||||
});
|
||||
expect(env.body?.upload).toMatchObject({
|
||||
senderUid: 's', receiverUid: 'r',
|
||||
fileSize: 4096, fileName: 'f.pdf',
|
||||
});
|
||||
});
|
||||
|
||||
it('returns the upload body for the facade host-selection step', async () => {
|
||||
const deps = makeDeps({
|
||||
upload: { uuid: 'fid-Y', fileAddon: 'hash', boolFileExist: true } as any,
|
||||
});
|
||||
const out = await UploadPrivateFileRequest.invoke(deps, {
|
||||
senderUid: 's', receiverUid: 'r',
|
||||
fileName: 'f', fileSize: 0,
|
||||
fileSha1: new Uint8Array(0), fileMd5: new Uint8Array(0),
|
||||
md510MCheckSum: new Uint8Array(0),
|
||||
});
|
||||
expect(out.uuid).toBe('fid-Y');
|
||||
expect(out.fileAddon).toBe('hash');
|
||||
});
|
||||
|
||||
it('throws when the upload sub-message is missing', async () => {
|
||||
const deps = makeDeps({});
|
||||
await expect(UploadPrivateFileRequest.invoke(deps, {
|
||||
senderUid: 's', receiverUid: 'r',
|
||||
fileName: 'f', fileSize: 0,
|
||||
fileSha1: new Uint8Array(0), fileMd5: new Uint8Array(0),
|
||||
md510MCheckSum: new Uint8Array(0),
|
||||
})).rejects.toThrow(/upload response missing/);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user