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
@@ -211,6 +211,74 @@
|
||||
"types": "./src/oidb-services/group-admin/get-at-all-remain.ts",
|
||||
"default": "./src/oidb-services/group-admin/get-at-all-remain.ts"
|
||||
},
|
||||
"./oidb-services/shared": {
|
||||
"types": "./src/oidb-services/shared.ts",
|
||||
"default": "./src/oidb-services/shared.ts"
|
||||
},
|
||||
"./oidb-services/group-file/publish-group-file": {
|
||||
"types": "./src/oidb-services/group-file/publish-group-file.ts",
|
||||
"default": "./src/oidb-services/group-file/publish-group-file.ts"
|
||||
},
|
||||
"./oidb-services/group-file/get-group-file-count": {
|
||||
"types": "./src/oidb-services/group-file/get-group-file-count.ts",
|
||||
"default": "./src/oidb-services/group-file/get-group-file-count.ts"
|
||||
},
|
||||
"./oidb-services/group-file/upload-group-file-request": {
|
||||
"types": "./src/oidb-services/group-file/upload-group-file-request.ts",
|
||||
"default": "./src/oidb-services/group-file/upload-group-file-request.ts"
|
||||
},
|
||||
"./oidb-services/group-file/upload-private-file-request": {
|
||||
"types": "./src/oidb-services/group-file/upload-private-file-request.ts",
|
||||
"default": "./src/oidb-services/group-file/upload-private-file-request.ts"
|
||||
},
|
||||
"./oidb-services/group-file/list-group-files-page": {
|
||||
"types": "./src/oidb-services/group-file/list-group-files-page.ts",
|
||||
"default": "./src/oidb-services/group-file/list-group-files-page.ts"
|
||||
},
|
||||
"./oidb-services/group-file/get-group-file-url": {
|
||||
"types": "./src/oidb-services/group-file/get-group-file-url.ts",
|
||||
"default": "./src/oidb-services/group-file/get-group-file-url.ts"
|
||||
},
|
||||
"./oidb-services/group-file/get-private-file-url": {
|
||||
"types": "./src/oidb-services/group-file/get-private-file-url.ts",
|
||||
"default": "./src/oidb-services/group-file/get-private-file-url.ts"
|
||||
},
|
||||
"./oidb-services/group-file/delete-group-file": {
|
||||
"types": "./src/oidb-services/group-file/delete-group-file.ts",
|
||||
"default": "./src/oidb-services/group-file/delete-group-file.ts"
|
||||
},
|
||||
"./oidb-services/group-file/move-group-file": {
|
||||
"types": "./src/oidb-services/group-file/move-group-file.ts",
|
||||
"default": "./src/oidb-services/group-file/move-group-file.ts"
|
||||
},
|
||||
"./oidb-services/group-file/create-group-folder": {
|
||||
"types": "./src/oidb-services/group-file/create-group-folder.ts",
|
||||
"default": "./src/oidb-services/group-file/create-group-folder.ts"
|
||||
},
|
||||
"./oidb-services/group-file/delete-group-folder": {
|
||||
"types": "./src/oidb-services/group-file/delete-group-folder.ts",
|
||||
"default": "./src/oidb-services/group-file/delete-group-folder.ts"
|
||||
},
|
||||
"./oidb-services/group-file/rename-group-folder": {
|
||||
"types": "./src/oidb-services/group-file/rename-group-folder.ts",
|
||||
"default": "./src/oidb-services/group-file/rename-group-folder.ts"
|
||||
},
|
||||
"./oidb-services/group-file/get-group-ptt-url": {
|
||||
"types": "./src/oidb-services/group-file/get-group-ptt-url.ts",
|
||||
"default": "./src/oidb-services/group-file/get-group-ptt-url.ts"
|
||||
},
|
||||
"./oidb-services/group-file/get-private-ptt-url": {
|
||||
"types": "./src/oidb-services/group-file/get-private-ptt-url.ts",
|
||||
"default": "./src/oidb-services/group-file/get-private-ptt-url.ts"
|
||||
},
|
||||
"./oidb-services/group-file/get-group-video-url": {
|
||||
"types": "./src/oidb-services/group-file/get-group-video-url.ts",
|
||||
"default": "./src/oidb-services/group-file/get-group-video-url.ts"
|
||||
},
|
||||
"./oidb-services/group-file/get-private-video-url": {
|
||||
"types": "./src/oidb-services/group-file/get-private-video-url.ts",
|
||||
"default": "./src/oidb-services/group-file/get-private-video-url.ts"
|
||||
},
|
||||
"./bridge-context": {
|
||||
"types": "./src/bridge-context.ts",
|
||||
"default": "./src/bridge-context.ts"
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
// 0x6D7_0 — create a sub-folder under `parentId` in the group file
|
||||
// hierarchy. parentId='/' is the root.
|
||||
|
||||
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 { invokeOidb, type OidbSender } from '../../oidb-service';
|
||||
import { ensureRetCodeZero } from '../shared';
|
||||
|
||||
export namespace CreateGroupFolder {
|
||||
export const command = 0x6D7;
|
||||
export const subCommand = 0;
|
||||
export const uinForm = true;
|
||||
|
||||
export interface Params { groupId: number; parentId: string; folderName: string; }
|
||||
export type Deps = OidbSender;
|
||||
|
||||
export const serialize = (p: Params): OidbGroupFileFolderReq => ({
|
||||
create: {
|
||||
groupUin: p.groupId,
|
||||
rootDirectory: p.parentId,
|
||||
folderName: p.folderName,
|
||||
},
|
||||
});
|
||||
|
||||
export const deserialize = (body: OidbGroupFileFolderResp): void => {
|
||||
const result = body.create;
|
||||
if (!result) throw new Error('group folder create response missing');
|
||||
ensureRetCodeZero('group folder create', result.retcode, result.retMsg, result.clientWording);
|
||||
};
|
||||
|
||||
export const encode = (env: OidbBase<OidbGroupFileFolderReq>): Uint8Array =>
|
||||
protobuf_encode<OidbBase<OidbGroupFileFolderReq>>(env);
|
||||
|
||||
export const decode = (bytes: Uint8Array): OidbBase<OidbGroupFileFolderResp> =>
|
||||
protobuf_decode<OidbBase<OidbGroupFileFolderResp>>(bytes);
|
||||
|
||||
export const invoke = (deps: Deps, params: Params): Promise<void> =>
|
||||
invokeOidb(deps, CreateGroupFolder, params);
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
// 0x6D6_3 — delete a single group file by id.
|
||||
|
||||
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 { invokeOidb, type OidbSender } from '../../oidb-service';
|
||||
import { ensureRetCodeZero } from '../shared';
|
||||
|
||||
export namespace DeleteGroupFile {
|
||||
export const command = 0x6D6;
|
||||
export const subCommand = 3;
|
||||
export const uinForm = true;
|
||||
|
||||
export interface Params { groupId: number; fileId: string; }
|
||||
export type Deps = OidbSender;
|
||||
|
||||
export const serialize = (p: Params): OidbGroupFileReq => ({
|
||||
delete: {
|
||||
groupUin: p.groupId,
|
||||
busId: 102,
|
||||
fileId: p.fileId,
|
||||
},
|
||||
});
|
||||
|
||||
export const deserialize = (body: OidbGroupFileResp): void => {
|
||||
const result = body.delete;
|
||||
if (!result) throw new Error('group file delete response missing');
|
||||
ensureRetCodeZero('group file delete', result.retCode, result.retMsg, result.clientWording);
|
||||
};
|
||||
|
||||
export const encode = (env: OidbBase<OidbGroupFileReq>): Uint8Array =>
|
||||
protobuf_encode<OidbBase<OidbGroupFileReq>>(env);
|
||||
|
||||
export const decode = (bytes: Uint8Array): OidbBase<OidbGroupFileResp> =>
|
||||
protobuf_decode<OidbBase<OidbGroupFileResp>>(bytes);
|
||||
|
||||
export const invoke = (deps: Deps, params: Params): Promise<void> =>
|
||||
invokeOidb(deps, DeleteGroupFile, params);
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
// 0x6D7_1 — delete a group folder by id (any files inside are
|
||||
// orphaned; UI sometimes pre-empties first via per-file deletes).
|
||||
|
||||
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 { invokeOidb, type OidbSender } from '../../oidb-service';
|
||||
import { ensureRetCodeZero } from '../shared';
|
||||
|
||||
export namespace DeleteGroupFolder {
|
||||
export const command = 0x6D7;
|
||||
export const subCommand = 1;
|
||||
export const uinForm = true;
|
||||
|
||||
export interface Params { groupId: number; folderId: string; }
|
||||
export type Deps = OidbSender;
|
||||
|
||||
export const serialize = (p: Params): OidbGroupFileFolderReq => ({
|
||||
delete: { groupUin: p.groupId, folderId: p.folderId },
|
||||
});
|
||||
|
||||
export const deserialize = (body: OidbGroupFileFolderResp): void => {
|
||||
const result = body.delete;
|
||||
if (!result) throw new Error('group folder delete response missing');
|
||||
ensureRetCodeZero('group folder delete', result.retcode, result.retMsg, result.clientWording);
|
||||
};
|
||||
|
||||
export const encode = (env: OidbBase<OidbGroupFileFolderReq>): Uint8Array =>
|
||||
protobuf_encode<OidbBase<OidbGroupFileFolderReq>>(env);
|
||||
|
||||
export const decode = (bytes: Uint8Array): OidbBase<OidbGroupFileFolderResp> =>
|
||||
protobuf_decode<OidbBase<OidbGroupFileFolderResp>>(bytes);
|
||||
|
||||
export const invoke = (deps: Deps, params: Params): Promise<void> =>
|
||||
invokeOidb(deps, DeleteGroupFolder, params);
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
// 0x6D8_3 — fetch group file slot usage. Returns the current count
|
||||
// alongside the server-side ceiling (NTQQ's `maxCount` default is
|
||||
// 10000; we surface that fallback so the OneBot action can render
|
||||
// the gauge without a second call when the server elides the field).
|
||||
|
||||
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 { invokeOidb, type OidbSender } from '../../oidb-service';
|
||||
|
||||
export interface GroupFileCount {
|
||||
fileCount: number;
|
||||
maxCount: number;
|
||||
}
|
||||
|
||||
export namespace GetGroupFileCount {
|
||||
export const command = 0x6D8;
|
||||
export const subCommand = 3;
|
||||
|
||||
export interface Params { groupId: number; }
|
||||
export type Deps = OidbSender;
|
||||
|
||||
export const serialize = (p: Params): OidbGroupFileCountViewReq => ({
|
||||
count: { groupUin: p.groupId, appId: 7, busId: 0 },
|
||||
});
|
||||
|
||||
export const deserialize = (body: OidbGroupFileCountViewResp): GroupFileCount => ({
|
||||
fileCount: Number(body.count?.fileCount ?? 0),
|
||||
maxCount: Number(body.count?.maxCount ?? 10000),
|
||||
});
|
||||
|
||||
export const encode = (env: OidbBase<OidbGroupFileCountViewReq>): Uint8Array =>
|
||||
protobuf_encode<OidbBase<OidbGroupFileCountViewReq>>(env);
|
||||
|
||||
export const decode = (bytes: Uint8Array): OidbBase<OidbGroupFileCountViewResp> =>
|
||||
protobuf_decode<OidbBase<OidbGroupFileCountViewResp>>(bytes);
|
||||
|
||||
export const invoke = (deps: Deps, params: Params): Promise<GroupFileCount> =>
|
||||
invokeOidb(deps, GetGroupFileCount, params);
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
// 0x6D6_2 — resolve a group file_id → ftn_handler download URL. The
|
||||
// server returns a `downloadUrl` blob (raw bytes that hex-encode the
|
||||
// download key) and a `downloadDns` host. The facade composes the
|
||||
// final `https://<dns>/ftn_handler/<HEX>/?fname=<fileId>` string.
|
||||
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type {
|
||||
OidbGroupFileReq, OidbGroupFileResp, OidbGroupFileDownloadResp,
|
||||
} from '@snowluma/proto-defs/oidb-actions/group-file';
|
||||
import { invokeOidb, type OidbSender } from '../../oidb-service';
|
||||
|
||||
export namespace GetGroupFileUrl {
|
||||
export const command = 0x6D6;
|
||||
export const subCommand = 2;
|
||||
export const uinForm = true;
|
||||
|
||||
export interface Params { groupId: number; fileId: string; busId: number; }
|
||||
export type Deps = OidbSender;
|
||||
|
||||
export const serialize = (p: Params): OidbGroupFileReq => ({
|
||||
download: {
|
||||
groupUin: p.groupId,
|
||||
appId: 7,
|
||||
busId: p.busId,
|
||||
fileId: p.fileId,
|
||||
},
|
||||
});
|
||||
|
||||
export const deserialize = (body: OidbGroupFileResp): OidbGroupFileDownloadResp => {
|
||||
const download = body.download;
|
||||
if (!download) throw new Error('group file url response missing');
|
||||
return download;
|
||||
};
|
||||
|
||||
export const encode = (env: OidbBase<OidbGroupFileReq>): Uint8Array =>
|
||||
protobuf_encode<OidbBase<OidbGroupFileReq>>(env);
|
||||
|
||||
export const decode = (bytes: Uint8Array): OidbBase<OidbGroupFileResp> =>
|
||||
protobuf_decode<OidbBase<OidbGroupFileResp>>(bytes);
|
||||
|
||||
export const invoke = (deps: Deps, params: Params): Promise<OidbGroupFileDownloadResp> =>
|
||||
invokeOidb(deps, GetGroupFileUrl, params);
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
// 0x126E_200 — fetch a download URL for a group-scope rich-media node
|
||||
// (voice in this case — busiType=3 means "ptt/voice", sceneType=2
|
||||
// means group). Pairs with the c2c-scope variant `GetPrivatePttUrl`
|
||||
// (0x126D_200) which only differs in scene.
|
||||
|
||||
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 { invokeOidb, type OidbSender } from '../../oidb-service';
|
||||
import {
|
||||
normalizeMediaNode, parseNtv2DownloadUrl, type NtMediaIndex,
|
||||
} from './ntv2-download';
|
||||
|
||||
export namespace GetGroupPttUrl {
|
||||
export const command = 0x126E;
|
||||
export const subCommand = 200;
|
||||
export const uinForm = true;
|
||||
|
||||
export interface Params { groupId: number; node: NtMediaIndex; }
|
||||
export type Deps = OidbSender;
|
||||
|
||||
export const serialize = (p: Params): NTV2RichMediaReq => ({
|
||||
reqHead: {
|
||||
common: { requestId: 4, command: 200 },
|
||||
scene: {
|
||||
requestType: 1,
|
||||
businessType: 3,
|
||||
sceneType: 2,
|
||||
group: { groupUin: p.groupId },
|
||||
},
|
||||
client: { agentType: 2 },
|
||||
},
|
||||
download: {
|
||||
node: normalizeMediaNode(p.node) as any,
|
||||
download: { video: { busiType: 0, sceneType: 0 } },
|
||||
},
|
||||
});
|
||||
|
||||
export const deserialize = parseNtv2DownloadUrl;
|
||||
|
||||
export const encode = (env: OidbBase<NTV2RichMediaReq>): Uint8Array =>
|
||||
protobuf_encode<OidbBase<NTV2RichMediaReq>>(env);
|
||||
|
||||
export const decode = (bytes: Uint8Array): OidbBase<NTV2RichMediaResp> =>
|
||||
protobuf_decode<OidbBase<NTV2RichMediaResp>>(bytes);
|
||||
|
||||
export const invoke = (deps: Deps, params: Params): Promise<string> =>
|
||||
invokeOidb(deps, GetGroupPttUrl, params);
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
// 0x11EA_200 — video URL fetch, group scope. Same envelope shape as
|
||||
// GetGroupPttUrl; `requestType=2 + businessType=2` swaps voice for
|
||||
// video. The scene's `group` block carries the group uin.
|
||||
|
||||
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 { invokeOidb, type OidbSender } from '../../oidb-service';
|
||||
import {
|
||||
normalizeMediaNode, parseNtv2DownloadUrl, type NtMediaIndex,
|
||||
} from './ntv2-download';
|
||||
|
||||
export namespace GetGroupVideoUrl {
|
||||
export const command = 0x11EA;
|
||||
export const subCommand = 200;
|
||||
export const uinForm = true;
|
||||
|
||||
export interface Params { groupId: number; node: NtMediaIndex; }
|
||||
export type Deps = OidbSender;
|
||||
|
||||
export const serialize = (p: Params): NTV2RichMediaReq => ({
|
||||
reqHead: {
|
||||
common: { requestId: 1, command: 200 },
|
||||
scene: {
|
||||
requestType: 2,
|
||||
businessType: 2,
|
||||
sceneType: 2,
|
||||
group: { groupUin: p.groupId },
|
||||
},
|
||||
client: { agentType: 2 },
|
||||
},
|
||||
download: {
|
||||
node: normalizeMediaNode(p.node) as any,
|
||||
download: { video: { busiType: 0, sceneType: 0 } },
|
||||
},
|
||||
});
|
||||
|
||||
export const deserialize = parseNtv2DownloadUrl;
|
||||
|
||||
export const encode = (env: OidbBase<NTV2RichMediaReq>): Uint8Array =>
|
||||
protobuf_encode<OidbBase<NTV2RichMediaReq>>(env);
|
||||
|
||||
export const decode = (bytes: Uint8Array): OidbBase<NTV2RichMediaResp> =>
|
||||
protobuf_decode<OidbBase<NTV2RichMediaResp>>(bytes);
|
||||
|
||||
export const invoke = (deps: Deps, params: Params): Promise<string> =>
|
||||
invokeOidb(deps, GetGroupVideoUrl, params);
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
// 0xE37_1200 — resolve a private (c2c) file_id → http download URL.
|
||||
// Carries an opaque 4-byte `field99999` magic the server's deserializer
|
||||
// requires (Lagrange has the same constant). The facade composes the
|
||||
// final `http://<server>:<port><url>&isthumb=0` string.
|
||||
//
|
||||
// 5s timeout matches the original facade — the server batches these
|
||||
// at low priority and stalls past the default 30s.
|
||||
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type {
|
||||
OidbPrivateFileDownloadReq, OidbPrivateFileDownloadResp,
|
||||
OidbPrivateFileDownloadRespResult,
|
||||
} from '@snowluma/proto-defs/oidb-actions/media';
|
||||
import { invokeOidb, type OidbSender } from '../../oidb-service';
|
||||
|
||||
const TIMEOUT_MS = 5000;
|
||||
|
||||
export namespace GetPrivateFileUrl {
|
||||
export const command = 0xE37;
|
||||
export const subCommand = 1200;
|
||||
|
||||
export interface Params { selfUid: string; fileId: string; fileHash: string; }
|
||||
export type Deps = OidbSender;
|
||||
|
||||
export const serialize = (p: Params): OidbPrivateFileDownloadReq => ({
|
||||
subCommand: 1200,
|
||||
field2: 1,
|
||||
body: {
|
||||
receiverUid: p.selfUid,
|
||||
fileUuid: p.fileId,
|
||||
type: 2,
|
||||
fileHash: p.fileHash,
|
||||
t2: 0,
|
||||
},
|
||||
field101: 3,
|
||||
field102: 103,
|
||||
field200: 1,
|
||||
field99999: new Uint8Array([0xC0, 0x85, 0x2C, 0x01]),
|
||||
});
|
||||
|
||||
export const deserialize = (body: OidbPrivateFileDownloadResp): OidbPrivateFileDownloadRespResult => {
|
||||
const result = body.body?.result;
|
||||
if (!result) throw new Error('private file url response invalid');
|
||||
return result;
|
||||
};
|
||||
|
||||
export const encode = (env: OidbBase<OidbPrivateFileDownloadReq>): Uint8Array =>
|
||||
protobuf_encode<OidbBase<OidbPrivateFileDownloadReq>>(env);
|
||||
|
||||
export const decode = (bytes: Uint8Array): OidbBase<OidbPrivateFileDownloadResp> =>
|
||||
protobuf_decode<OidbBase<OidbPrivateFileDownloadResp>>(bytes);
|
||||
|
||||
export const invoke = (deps: Deps, params: Params): Promise<OidbPrivateFileDownloadRespResult> =>
|
||||
invokeOidb(deps, GetPrivateFileUrl, params, TIMEOUT_MS);
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
// 0x126D_200 — c2c-scope counterpart of GetGroupPttUrl. Same shape,
|
||||
// `scene` is `c2c` rather than `group`. Needs the bot's own uid to
|
||||
// fill the c2c.targetUid slot.
|
||||
|
||||
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 { invokeOidb, type OidbSender } from '../../oidb-service';
|
||||
import {
|
||||
normalizeMediaNode, parseNtv2DownloadUrl, type NtMediaIndex,
|
||||
} from './ntv2-download';
|
||||
|
||||
export namespace GetPrivatePttUrl {
|
||||
export const command = 0x126D;
|
||||
export const subCommand = 200;
|
||||
export const uinForm = true;
|
||||
|
||||
export interface Params { selfUid: string; node: NtMediaIndex; }
|
||||
export type Deps = OidbSender;
|
||||
|
||||
export const serialize = (p: Params): NTV2RichMediaReq => ({
|
||||
reqHead: {
|
||||
common: { requestId: 1, command: 200 },
|
||||
scene: {
|
||||
requestType: 1,
|
||||
businessType: 3,
|
||||
sceneType: 1,
|
||||
c2c: { accountType: 2, targetUid: p.selfUid },
|
||||
},
|
||||
client: { agentType: 2 },
|
||||
},
|
||||
download: {
|
||||
node: normalizeMediaNode(p.node) as any,
|
||||
download: { video: { busiType: 0, sceneType: 0 } },
|
||||
},
|
||||
});
|
||||
|
||||
export const deserialize = parseNtv2DownloadUrl;
|
||||
|
||||
export const encode = (env: OidbBase<NTV2RichMediaReq>): Uint8Array =>
|
||||
protobuf_encode<OidbBase<NTV2RichMediaReq>>(env);
|
||||
|
||||
export const decode = (bytes: Uint8Array): OidbBase<NTV2RichMediaResp> =>
|
||||
protobuf_decode<OidbBase<NTV2RichMediaResp>>(bytes);
|
||||
|
||||
export const invoke = (deps: Deps, params: Params): Promise<string> =>
|
||||
invokeOidb(deps, GetPrivatePttUrl, params);
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
// 0x11E9_200 — c2c-scope video URL fetch (pair of GetGroupVideoUrl).
|
||||
// `scene.c2c.targetUid` is the bot's own uid; the server uses it as
|
||||
// the read-side identity for the asset lookup.
|
||||
|
||||
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 { invokeOidb, type OidbSender } from '../../oidb-service';
|
||||
import {
|
||||
normalizeMediaNode, parseNtv2DownloadUrl, type NtMediaIndex,
|
||||
} from './ntv2-download';
|
||||
|
||||
export namespace GetPrivateVideoUrl {
|
||||
export const command = 0x11E9;
|
||||
export const subCommand = 200;
|
||||
export const uinForm = true;
|
||||
|
||||
export interface Params { selfUid: string; node: NtMediaIndex; }
|
||||
export type Deps = OidbSender;
|
||||
|
||||
export const serialize = (p: Params): NTV2RichMediaReq => ({
|
||||
reqHead: {
|
||||
common: { requestId: 1, command: 200 },
|
||||
scene: {
|
||||
requestType: 2,
|
||||
businessType: 2,
|
||||
sceneType: 1,
|
||||
c2c: { accountType: 2, targetUid: p.selfUid },
|
||||
},
|
||||
client: { agentType: 2 },
|
||||
},
|
||||
download: {
|
||||
node: normalizeMediaNode(p.node) as any,
|
||||
download: { video: { busiType: 0, sceneType: 0 } },
|
||||
},
|
||||
});
|
||||
|
||||
export const deserialize = parseNtv2DownloadUrl;
|
||||
|
||||
export const encode = (env: OidbBase<NTV2RichMediaReq>): Uint8Array =>
|
||||
protobuf_encode<OidbBase<NTV2RichMediaReq>>(env);
|
||||
|
||||
export const decode = (bytes: Uint8Array): OidbBase<NTV2RichMediaResp> =>
|
||||
protobuf_decode<OidbBase<NTV2RichMediaResp>>(bytes);
|
||||
|
||||
export const invoke = (deps: Deps, params: Params): Promise<string> =>
|
||||
invokeOidb(deps, GetPrivateVideoUrl, params);
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
// 0x6D8_1 — ONE page of the group-file listing under `targetDirectory`.
|
||||
// Paginated; the facade loops this until `isEnd=true` or the page cap
|
||||
// is hit. Each page yields a mix of files (`type=1`) and folders
|
||||
// (`type=2`); the caller flattens them.
|
||||
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type {
|
||||
OidbGroupFileViewReq, OidbGroupFileViewResp, OidbGroupFileListResp,
|
||||
} from '@snowluma/proto-defs/oidb-actions/group-file';
|
||||
import { invokeOidb, type OidbSender } from '../../oidb-service';
|
||||
|
||||
export namespace ListGroupFilesPage {
|
||||
export const command = 0x6D8;
|
||||
export const subCommand = 1;
|
||||
export const uinForm = true;
|
||||
|
||||
export interface Params {
|
||||
groupId: number;
|
||||
targetDirectory: string;
|
||||
startIndex: number;
|
||||
pageSize: number;
|
||||
}
|
||||
|
||||
export type Deps = OidbSender;
|
||||
|
||||
export const serialize = (p: Params): OidbGroupFileViewReq => ({
|
||||
list: {
|
||||
groupUin: p.groupId,
|
||||
appId: 7,
|
||||
targetDirectory: p.targetDirectory,
|
||||
fileCount: p.pageSize,
|
||||
sortBy: 1,
|
||||
startIndex: p.startIndex,
|
||||
field17: 2,
|
||||
field18: 0,
|
||||
},
|
||||
});
|
||||
|
||||
/** Returns the list body directly so the facade can inspect
|
||||
* `items`, `isEnd`, and `retCode` in one place. Returns null when
|
||||
* the server elides the list entirely (end-of-stream sentinel). */
|
||||
export const deserialize = (body: OidbGroupFileViewResp): OidbGroupFileListResp | null => {
|
||||
return body.list ?? null;
|
||||
};
|
||||
|
||||
export const encode = (env: OidbBase<OidbGroupFileViewReq>): Uint8Array =>
|
||||
protobuf_encode<OidbBase<OidbGroupFileViewReq>>(env);
|
||||
|
||||
export const decode = (bytes: Uint8Array): OidbBase<OidbGroupFileViewResp> =>
|
||||
protobuf_decode<OidbBase<OidbGroupFileViewResp>>(bytes);
|
||||
|
||||
export const invoke = (deps: Deps, params: Params): Promise<OidbGroupFileListResp | null> =>
|
||||
invokeOidb(deps, ListGroupFilesPage, params);
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
// 0x6D6_5 — move a group file between folders.
|
||||
|
||||
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 { invokeOidb, type OidbSender } from '../../oidb-service';
|
||||
import { ensureRetCodeZero } from '../shared';
|
||||
|
||||
export namespace MoveGroupFile {
|
||||
export const command = 0x6D6;
|
||||
export const subCommand = 5;
|
||||
export const uinForm = true;
|
||||
|
||||
export interface Params {
|
||||
groupId: number; fileId: string;
|
||||
parentDirectory: string; targetDirectory: string;
|
||||
}
|
||||
export type Deps = OidbSender;
|
||||
|
||||
export const serialize = (p: Params): OidbGroupFileReq => ({
|
||||
move: {
|
||||
groupUin: p.groupId,
|
||||
appId: 7,
|
||||
busId: 102,
|
||||
fileId: p.fileId,
|
||||
parentDirectory: p.parentDirectory,
|
||||
targetDirectory: p.targetDirectory,
|
||||
},
|
||||
});
|
||||
|
||||
export const deserialize = (body: OidbGroupFileResp): void => {
|
||||
const result = body.move;
|
||||
if (!result) throw new Error('group file move response missing');
|
||||
ensureRetCodeZero('group file move', result.retCode, result.retMsg, result.clientWording);
|
||||
};
|
||||
|
||||
export const encode = (env: OidbBase<OidbGroupFileReq>): Uint8Array =>
|
||||
protobuf_encode<OidbBase<OidbGroupFileReq>>(env);
|
||||
|
||||
export const decode = (bytes: Uint8Array): OidbBase<OidbGroupFileResp> =>
|
||||
protobuf_decode<OidbBase<OidbGroupFileResp>>(bytes);
|
||||
|
||||
export const invoke = (deps: Deps, params: Params): Promise<void> =>
|
||||
invokeOidb(deps, MoveGroupFile, params);
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
// Shared deserializer for the four NTV2-rich-media URL fetchers:
|
||||
// - get-group-ptt-url (0x126E_200)
|
||||
// - get-private-ptt-url (0x126D_200)
|
||||
// - get-group-video-url (0x11EA_200)
|
||||
// - get-private-video-url (0x11E9_200)
|
||||
//
|
||||
// All four hit the `MultiMedia.OidbSvc.0x...` family with the same
|
||||
// `NTV2RichMediaReq` shape; only the `scene` block + the wire cmd
|
||||
// differ. The response is parsed into a `domain + urlPath +
|
||||
// rKeyParam` triple → composed into `https://<domain><path><rKey>`.
|
||||
|
||||
import type { NTV2RichMediaResp } from '@snowluma/proto-defs/oidb-actions/media';
|
||||
import { ensureRetCodeZero } from '../shared';
|
||||
|
||||
export function parseNtv2DownloadUrl(body: NTV2RichMediaResp): string {
|
||||
ensureRetCodeZero('ntv2 download', body.respHead?.retCode, body.respHead?.message, undefined);
|
||||
const domain = typeof body.download?.info?.domain === 'string' ? body.download.info.domain : '';
|
||||
const path = typeof body.download?.info?.urlPath === 'string' ? body.download.info.urlPath : '';
|
||||
const rKeyParam = typeof body.download?.rKeyParam === 'string' ? body.download.rKeyParam : '';
|
||||
if (!domain || !path) throw new Error('ntv2 download response invalid');
|
||||
return `https://${domain}${path}${rKeyParam}`;
|
||||
}
|
||||
|
||||
/** Normalize a MediaIndexNode-shaped object into the wire-fields the
|
||||
* NTV2RichMedia `download.node` slot expects: `info{...}` /
|
||||
* `fileUuid` / `storeId` / `uploadTime` / `ttl` / `subType`. */
|
||||
export function normalizeMediaNode(node: NtMediaIndex): Record<string, unknown> {
|
||||
const fileUuid = typeof node.fileUuid === 'string' ? node.fileUuid : '';
|
||||
if (!fileUuid) throw new Error('media node fileUuid is required');
|
||||
|
||||
const info = node.info ?? {};
|
||||
const type = info.type ?? {};
|
||||
|
||||
return {
|
||||
info: {
|
||||
fileSize: toInt(info.fileSize),
|
||||
fileHash: typeof info.fileHash === 'string' ? info.fileHash : '',
|
||||
fileSha1: typeof info.fileSha1 === 'string' ? info.fileSha1 : '',
|
||||
fileName: typeof info.fileName === 'string' ? info.fileName : '',
|
||||
type: {
|
||||
type: toInt(type.type),
|
||||
picFormat: toInt(type.picFormat),
|
||||
videoFormat: toInt(type.videoFormat),
|
||||
voiceFormat: toInt(type.voiceFormat),
|
||||
},
|
||||
width: toInt(info.width),
|
||||
height: toInt(info.height),
|
||||
time: toInt(info.time),
|
||||
original: toInt(info.original),
|
||||
},
|
||||
fileUuid,
|
||||
storeId: toInt(node.storeId),
|
||||
uploadTime: toInt(node.uploadTime),
|
||||
ttl: toInt(node.ttl),
|
||||
subType: toInt(node.subType),
|
||||
};
|
||||
}
|
||||
|
||||
function toInt(value: unknown): number {
|
||||
if (typeof value === 'number' && Number.isFinite(value)) return Math.trunc(value);
|
||||
if (typeof value === 'bigint') return Number(value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
export interface NtMediaIndex {
|
||||
info?: {
|
||||
fileSize?: number;
|
||||
fileHash?: string;
|
||||
fileSha1?: string;
|
||||
fileName?: string;
|
||||
width?: number;
|
||||
height?: number;
|
||||
time?: number;
|
||||
original?: number;
|
||||
type?: {
|
||||
type?: number;
|
||||
picFormat?: number;
|
||||
videoFormat?: number;
|
||||
voiceFormat?: number;
|
||||
};
|
||||
};
|
||||
fileUuid?: string;
|
||||
storeId?: number;
|
||||
uploadTime?: number;
|
||||
ttl?: number;
|
||||
subType?: number;
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
// 0x6D9_4 — publish a previously-uploaded group file as a chat
|
||||
// message (the file-bubble in the group transcript).
|
||||
//
|
||||
// The QQ-NT server rejects the legacy `TransElem(elemType=24)` payload
|
||||
// on outgoing send (`result=79`) so the file-publish path goes via a
|
||||
// dedicated OIDB hop instead of `MessageSvc.PbSendMsg`. Mirror
|
||||
// Lagrange.Core V2's `GroupSendFileService.cs`:
|
||||
// - `info.field3` is a 31-bit random — Lagrange does `Random.Shared.Next()`
|
||||
// - `info.field5 = true` is the discriminator the server's deserializer
|
||||
// expects to recognise this branch.
|
||||
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type { OidbBase, OidbEmpty } from '@snowluma/proto-defs/oidb';
|
||||
import type { OidbGroupSendFileReq } from '@snowluma/proto-defs/oidb-actions/group-file';
|
||||
import { invokeOidb, type OidbSender } from '../../oidb-service';
|
||||
|
||||
export namespace PublishGroupFile {
|
||||
export const command = 0x6D9;
|
||||
export const subCommand = 4;
|
||||
|
||||
export interface Params { groupId: number; fileId: string; }
|
||||
export type Deps = OidbSender;
|
||||
|
||||
export const serialize = (p: Params): OidbGroupSendFileReq => ({
|
||||
body: {
|
||||
groupUin: p.groupId,
|
||||
type: 2,
|
||||
info: {
|
||||
busiType: 102,
|
||||
fileId: p.fileId,
|
||||
field3: Math.floor(Math.random() * 0x7fffffff) >>> 0,
|
||||
field5: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export const deserialize = (_: OidbEmpty): void => {};
|
||||
|
||||
export const encode = (env: OidbBase<OidbGroupSendFileReq>): Uint8Array =>
|
||||
protobuf_encode<OidbBase<OidbGroupSendFileReq>>(env);
|
||||
|
||||
export const decode = (bytes: Uint8Array): OidbBase<OidbEmpty> =>
|
||||
protobuf_decode<OidbBase<OidbEmpty>>(bytes);
|
||||
|
||||
export const invoke = (deps: Deps, params: Params): Promise<void> =>
|
||||
invokeOidb(deps, PublishGroupFile, params);
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
// 0x6D7_2 — rename a group folder. Note the wire field is
|
||||
// `newFolderName` (not `folderName`); the rename slot lives on the
|
||||
// shared `OidbGroupFileFolderReq` envelope.
|
||||
|
||||
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 { invokeOidb, type OidbSender } from '../../oidb-service';
|
||||
import { ensureRetCodeZero } from '../shared';
|
||||
|
||||
export namespace RenameGroupFolder {
|
||||
export const command = 0x6D7;
|
||||
export const subCommand = 2;
|
||||
export const uinForm = true;
|
||||
|
||||
export interface Params { groupId: number; folderId: string; newFolderName: string; }
|
||||
export type Deps = OidbSender;
|
||||
|
||||
export const serialize = (p: Params): OidbGroupFileFolderReq => ({
|
||||
rename: {
|
||||
groupUin: p.groupId,
|
||||
folderId: p.folderId,
|
||||
newFolderName: p.newFolderName,
|
||||
},
|
||||
});
|
||||
|
||||
export const deserialize = (body: OidbGroupFileFolderResp): void => {
|
||||
const result = body.rename;
|
||||
if (!result) throw new Error('group folder rename response missing');
|
||||
ensureRetCodeZero('group folder rename', result.retcode, result.retMsg, result.clientWording);
|
||||
};
|
||||
|
||||
export const encode = (env: OidbBase<OidbGroupFileFolderReq>): Uint8Array =>
|
||||
protobuf_encode<OidbBase<OidbGroupFileFolderReq>>(env);
|
||||
|
||||
export const decode = (bytes: Uint8Array): OidbBase<OidbGroupFileFolderResp> =>
|
||||
protobuf_decode<OidbBase<OidbGroupFileFolderResp>>(bytes);
|
||||
|
||||
export const invoke = (deps: Deps, params: Params): Promise<void> =>
|
||||
invokeOidb(deps, RenameGroupFolder, params);
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
// 0x6D6_0 — group-file upload preflight. Hands the server the file
|
||||
// metadata + hashes and gets back:
|
||||
// - `boolFileExist` — if true, the bytes are already on the server
|
||||
// and the highway step is skipped
|
||||
// - `fileId` — the persistent id used by `publish` (0x6D9_4) and
|
||||
// later download/delete/move calls
|
||||
// - upload host/port + the `fileKey`/`checkKey` blob the highway
|
||||
// PUT needs in its FileUploadExt envelope
|
||||
//
|
||||
// This namespace ONLY does the preflight; the highway PUT and the
|
||||
// follow-on `publish` chat-message hop live on the facade because
|
||||
// they're orchestration (highway client, ext blob composition) that
|
||||
// doesn't fit a single OIDB call boundary.
|
||||
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type {
|
||||
OidbGroupFileReq, OidbGroupFileResp, OidbGroupFileUploadResp,
|
||||
} from '@snowluma/proto-defs/oidb-actions/group-file';
|
||||
import { invokeOidb, type OidbSender } from '../../oidb-service';
|
||||
|
||||
export namespace UploadGroupFileRequest {
|
||||
export const command = 0x6D6;
|
||||
export const subCommand = 0;
|
||||
export const uinForm = true;
|
||||
|
||||
export interface Params {
|
||||
groupId: number;
|
||||
fileName: string;
|
||||
folderId: string;
|
||||
fileSize: number;
|
||||
fileSha1: Uint8Array;
|
||||
fileMd5: Uint8Array;
|
||||
}
|
||||
|
||||
export type Deps = OidbSender;
|
||||
|
||||
export const serialize = (p: Params): OidbGroupFileReq => ({
|
||||
file: {
|
||||
groupUin: p.groupId,
|
||||
appId: 4,
|
||||
busId: 102,
|
||||
entrance: 6,
|
||||
targetDirectory: p.folderId,
|
||||
fileName: p.fileName,
|
||||
localDirectory: `/${p.fileName}`,
|
||||
fileSize: BigInt(p.fileSize),
|
||||
fileSha1: p.fileSha1,
|
||||
fileSha3: new Uint8Array(0),
|
||||
fileMd5: p.fileMd5,
|
||||
field15: true,
|
||||
},
|
||||
});
|
||||
|
||||
export const deserialize = (body: OidbGroupFileResp): OidbGroupFileUploadResp => {
|
||||
const upload = body.upload;
|
||||
if (!upload) throw new Error('group file upload response missing');
|
||||
return upload;
|
||||
};
|
||||
|
||||
export const encode = (env: OidbBase<OidbGroupFileReq>): Uint8Array =>
|
||||
protobuf_encode<OidbBase<OidbGroupFileReq>>(env);
|
||||
|
||||
export const decode = (bytes: Uint8Array): OidbBase<OidbGroupFileResp> =>
|
||||
protobuf_decode<OidbBase<OidbGroupFileResp>>(bytes);
|
||||
|
||||
export const invoke = (deps: Deps, params: Params): Promise<OidbGroupFileUploadResp> =>
|
||||
invokeOidb(deps, UploadGroupFileRequest, params);
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
// 0xE37_1700 — private (c2c) file upload preflight. Server returns
|
||||
// the same shape of upload-host info as the group-file path but the
|
||||
// fields are laid out differently (rtpMediaPlatformUploadAddress is
|
||||
// the primary host source on current QQ-NT; legacy `uploadIp` /
|
||||
// `uploadDomain` / `uploadIpList[]` are fallbacks).
|
||||
//
|
||||
// As with the group-file preflight, this namespace ONLY does the
|
||||
// preflight; the highway PUT and the follow-on `sendC2cFile` chat
|
||||
// hop live on the facade.
|
||||
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type {
|
||||
OidbPrivateFileUploadReq, OidbPrivateFileUploadResp,
|
||||
OidbPrivateFileUploadRespBody,
|
||||
} from '@snowluma/proto-defs/oidb-actions/media';
|
||||
import { invokeOidb, type OidbSender } from '../../oidb-service';
|
||||
|
||||
export namespace UploadPrivateFileRequest {
|
||||
export const command = 0xE37;
|
||||
export const subCommand = 1700;
|
||||
|
||||
export interface Params {
|
||||
senderUid: string;
|
||||
receiverUid: string;
|
||||
fileName: string;
|
||||
fileSize: number;
|
||||
fileSha1: Uint8Array;
|
||||
fileMd5: Uint8Array;
|
||||
/** md5 over the first 10 MiB; caller passes this in because we
|
||||
* can't redo the hash here without re-reading the source. */
|
||||
md510MCheckSum: Uint8Array;
|
||||
}
|
||||
|
||||
export type Deps = OidbSender;
|
||||
|
||||
export const serialize = (p: Params): OidbPrivateFileUploadReq => ({
|
||||
command: 1700,
|
||||
seq: 0,
|
||||
upload: {
|
||||
senderUid: p.senderUid,
|
||||
receiverUid: p.receiverUid,
|
||||
fileSize: p.fileSize,
|
||||
fileName: p.fileName,
|
||||
md510MCheckSum: p.md510MCheckSum,
|
||||
sha1CheckSum: p.fileSha1,
|
||||
localPath: '/',
|
||||
md5CheckSum: p.fileMd5,
|
||||
sha3CheckSum: new Uint8Array(0),
|
||||
},
|
||||
businessId: 3,
|
||||
clientType: 1,
|
||||
flagSupportMediaPlatform: 1,
|
||||
});
|
||||
|
||||
export const deserialize = (body: OidbPrivateFileUploadResp): OidbPrivateFileUploadRespBody => {
|
||||
const upload = body.upload;
|
||||
if (!upload) throw new Error('private file upload response missing');
|
||||
return upload;
|
||||
};
|
||||
|
||||
export const encode = (env: OidbBase<OidbPrivateFileUploadReq>): Uint8Array =>
|
||||
protobuf_encode<OidbBase<OidbPrivateFileUploadReq>>(env);
|
||||
|
||||
export const decode = (bytes: Uint8Array): OidbBase<OidbPrivateFileUploadResp> =>
|
||||
protobuf_decode<OidbBase<OidbPrivateFileUploadResp>>(bytes);
|
||||
|
||||
export const invoke = (deps: Deps, params: Params): Promise<OidbPrivateFileUploadRespBody> =>
|
||||
invokeOidb(deps, UploadPrivateFileRequest, params);
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
// Tiny helpers shared between OIDB namespaces — kept here instead of
|
||||
// `@snowluma/core/bridge/apis/shared` to avoid a circular dep
|
||||
// (services live in @snowluma/bridge, facades in @snowluma/core).
|
||||
|
||||
/** Coerce numbers, strings, and bigints to a plain integer. */
|
||||
export function toInt(value: unknown): number {
|
||||
if (typeof value === 'number' && Number.isFinite(value)) return Math.trunc(value);
|
||||
if (typeof value === 'bigint') {
|
||||
const n = Number(value);
|
||||
return Number.isFinite(n) ? Math.trunc(n) : 0;
|
||||
}
|
||||
if (typeof value === 'string' && value.trim()) {
|
||||
const n = Number(value);
|
||||
return Number.isFinite(n) ? Math.trunc(n) : 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** Standard OIDB sub-response check: throw a typed Error if retCode != 0.
|
||||
* Prefers `wording` over `msg` for the human-facing message. */
|
||||
export function ensureRetCodeZero(
|
||||
operation: string, code: unknown, msg: unknown, wording: unknown,
|
||||
): void {
|
||||
const retCode = toInt(code);
|
||||
if (retCode === 0) return;
|
||||
const text = (typeof wording === 'string' && wording) || (typeof msg === 'string' && msg) || 'unknown error';
|
||||
throw new Error(`${operation} failed: code=${retCode} msg=${text}`);
|
||||
}
|
||||
@@ -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/);
|
||||
});
|
||||
});
|
||||
@@ -1,44 +1,40 @@
|
||||
// GroupFileApi — group file CRUD + private (c2c) file upload + media
|
||||
// download URL resolvers. Inlined from `actions/group-file.ts`
|
||||
// (deleted alongside the rest of actions/* in commit 13).
|
||||
// download URL resolvers.
|
||||
//
|
||||
// Naming: methods drop the redundant `Group`/`File` suffix where the
|
||||
// area name already says it. The `Private`/`Group` axis stays
|
||||
// explicit because some methods only exist for one side
|
||||
// (`publish` only makes sense for group, `getPrivateUrl` only for
|
||||
// c2c) — keeping them in one Api lets the few shared private helpers
|
||||
// (`fetchNtv2DownloadUrl`, the upload-ext builder) live in one file.
|
||||
// Single-OIDB-call methods are one-line forwarders to namespaces
|
||||
// under @snowluma/bridge/oidb-services/group-file. The multi-stage
|
||||
// methods (`upload` / `uploadPrivate`) stay here because they
|
||||
// orchestrate three discrete legs (OIDB preflight → highway PUT →
|
||||
// follow-on OIDB publish or message send) plus the upload-cache
|
||||
// bookkeeping the OneBot send path relies on.
|
||||
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import { protobuf_encode } from '@snowluma/proton';
|
||||
import { toHexUpper } from '@snowluma/common/hex';
|
||||
import { createLogger } from '@snowluma/common/logger';
|
||||
import type { BridgeContext } from '../bridge-context';
|
||||
import type { Bridge } from '../bridge';
|
||||
import { makeOidbEnvelope, runOidb } from '@snowluma/bridge/bridge-oidb';
|
||||
import { fetchHighwaySession, uploadHighwayHttp } from '@snowluma/bridge/highway';
|
||||
import { computeHashes, computeMd5, FILE_UPLOAD_MAX_BYTES, loadBinarySource } from '@snowluma/bridge/highway/utils';
|
||||
import type { FileUploadExt } from '@snowluma/proto-defs/highway';
|
||||
import { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type {
|
||||
OidbGroupFileCountViewReq,
|
||||
OidbGroupFileCountViewResp,
|
||||
OidbGroupFileFolderReq,
|
||||
OidbGroupFileFolderResp,
|
||||
OidbGroupFileReq,
|
||||
OidbGroupFileResp,
|
||||
OidbGroupFileViewReq,
|
||||
OidbGroupFileViewResp,
|
||||
OidbGroupSendFileReq,
|
||||
} from '@snowluma/proto-defs/oidb-actions/group-file';
|
||||
import type {
|
||||
NTV2RichMediaReq,
|
||||
NTV2RichMediaResp,
|
||||
OidbPrivateFileDownloadReq,
|
||||
OidbPrivateFileDownloadResp,
|
||||
OidbPrivateFileUploadReq,
|
||||
OidbPrivateFileUploadResp,
|
||||
} from '@snowluma/proto-defs/oidb-actions/media';
|
||||
import { ensureRetCodeZero, resolveSelfUid, toInt, type MediaIndexNode } from './shared';
|
||||
import { resolveSelfUid, toInt, type MediaIndexNode } from './shared';
|
||||
|
||||
import { PublishGroupFile } from '@snowluma/bridge/oidb-services/group-file/publish-group-file';
|
||||
import { GetGroupFileCount } from '@snowluma/bridge/oidb-services/group-file/get-group-file-count';
|
||||
import { UploadGroupFileRequest } from '@snowluma/bridge/oidb-services/group-file/upload-group-file-request';
|
||||
import { UploadPrivateFileRequest } from '@snowluma/bridge/oidb-services/group-file/upload-private-file-request';
|
||||
import { ListGroupFilesPage } from '@snowluma/bridge/oidb-services/group-file/list-group-files-page';
|
||||
import { GetGroupFileUrl } from '@snowluma/bridge/oidb-services/group-file/get-group-file-url';
|
||||
import { GetPrivateFileUrl } from '@snowluma/bridge/oidb-services/group-file/get-private-file-url';
|
||||
import { DeleteGroupFile } from '@snowluma/bridge/oidb-services/group-file/delete-group-file';
|
||||
import { MoveGroupFile } from '@snowluma/bridge/oidb-services/group-file/move-group-file';
|
||||
import { CreateGroupFolder } from '@snowluma/bridge/oidb-services/group-file/create-group-folder';
|
||||
import { DeleteGroupFolder } from '@snowluma/bridge/oidb-services/group-file/delete-group-folder';
|
||||
import { RenameGroupFolder } from '@snowluma/bridge/oidb-services/group-file/rename-group-folder';
|
||||
import { GetGroupPttUrl } from '@snowluma/bridge/oidb-services/group-file/get-group-ptt-url';
|
||||
import { GetPrivatePttUrl } from '@snowluma/bridge/oidb-services/group-file/get-private-ptt-url';
|
||||
import { GetGroupVideoUrl } from '@snowluma/bridge/oidb-services/group-file/get-group-video-url';
|
||||
import { GetPrivateVideoUrl } from '@snowluma/bridge/oidb-services/group-file/get-private-video-url';
|
||||
import { ensureRetCodeZero } from '@snowluma/bridge/oidb-services/shared';
|
||||
|
||||
const log = createLogger('GroupFile');
|
||||
|
||||
@@ -230,120 +226,23 @@ function buildPrivateFileUploadExt(
|
||||
});
|
||||
}
|
||||
|
||||
function normalizeMediaNode(node: MediaIndexNode): Record<string, unknown> {
|
||||
const fileUuid = typeof node.fileUuid === 'string' ? node.fileUuid : '';
|
||||
if (!fileUuid) throw new Error('media node fileUuid is required');
|
||||
|
||||
const info = node.info ?? {};
|
||||
const type = info.type ?? {};
|
||||
|
||||
return {
|
||||
info: {
|
||||
fileSize: toInt(info.fileSize),
|
||||
fileHash: typeof info.fileHash === 'string' ? info.fileHash : '',
|
||||
fileSha1: typeof info.fileSha1 === 'string' ? info.fileSha1 : '',
|
||||
fileName: typeof info.fileName === 'string' ? info.fileName : '',
|
||||
type: {
|
||||
type: toInt(type.type),
|
||||
picFormat: toInt(type.picFormat),
|
||||
videoFormat: toInt(type.videoFormat),
|
||||
voiceFormat: toInt(type.voiceFormat),
|
||||
},
|
||||
width: toInt(info.width),
|
||||
height: toInt(info.height),
|
||||
time: toInt(info.time),
|
||||
original: toInt(info.original),
|
||||
},
|
||||
fileUuid,
|
||||
storeId: toInt(node.storeId),
|
||||
uploadTime: toInt(node.uploadTime),
|
||||
ttl: toInt(node.ttl),
|
||||
subType: toInt(node.subType),
|
||||
};
|
||||
}
|
||||
|
||||
async function fetchNtv2DownloadUrl(
|
||||
bridge: Bridge,
|
||||
serviceCmd: string,
|
||||
oidbCmd: number,
|
||||
payload: Record<string, unknown>,
|
||||
): Promise<string> {
|
||||
const env = makeOidbEnvelope<NTV2RichMediaReq>(oidbCmd, 200, payload as any, true);
|
||||
const respBytes = await runOidb(bridge, serviceCmd, protobuf_encode<OidbBase<NTV2RichMediaReq>>(env));
|
||||
const resp = protobuf_decode<OidbBase<NTV2RichMediaResp>>(respBytes).body;
|
||||
|
||||
ensureRetCodeZero('ntv2 download', resp?.respHead?.retCode, resp?.respHead?.message, undefined);
|
||||
const domain = typeof resp?.download?.info?.domain === 'string' ? resp.download.info.domain : '';
|
||||
const path = typeof resp?.download?.info?.urlPath === 'string' ? resp.download.info.urlPath : '';
|
||||
const rKeyParam = typeof resp?.download?.rKeyParam === 'string' ? resp.download.rKeyParam : '';
|
||||
|
||||
if (!domain || !path) {
|
||||
throw new Error('ntv2 download response invalid');
|
||||
}
|
||||
return `https://${domain}${path}${rKeyParam}`;
|
||||
}
|
||||
|
||||
export class GroupFileApi {
|
||||
constructor(private readonly ctx: BridgeContext) {}
|
||||
|
||||
// ─────────────── publish (group file → chat) ───────────────
|
||||
|
||||
/**
|
||||
* Publish a previously-uploaded group file as a chat message.
|
||||
*
|
||||
* Wire is OIDB `OidbSvcTrpcTcp.0x6d9_4` — NOT `MessageSvc.PbSendMsg`.
|
||||
* Lagrange.Core V2 splits these two roles: the file UPLOAD path goes
|
||||
* via 0x6D6_0 + highway PUT, then a SECOND OIDB hop (this one) tells
|
||||
* the QQ server "now publish that staged blob as a chat message" so
|
||||
* everyone in the group can see the file bubble.
|
||||
*
|
||||
* The old approach — wrap the file as `TransElem(elemType=24)` inside
|
||||
* `richText.elems[]` and ship it via PbSendMsg — works for INCOMING
|
||||
* messages (the receive decoder unpacks transElem(24) into a
|
||||
* FileEntity) but the QQ-NT server REJECTS it on outgoing with
|
||||
* `result=79` ("invalid element on send-side"). Mirror Lagrange's
|
||||
* dedicated GroupSendFileService instead.
|
||||
*
|
||||
* The unused `field4` slot and the `field3=random` value match
|
||||
* Lagrange's send-side defaults (`OidbSvcTrpcTcp0x6D9_4.cs` + the
|
||||
* `Random.Shared.Next()` call in `GroupSendFileService.cs`). Field 5
|
||||
* is the `Field5=true` flag the receiver's deserializer expects.
|
||||
*/
|
||||
async publish(groupId: number, fileId: string): Promise<void> {
|
||||
publish(groupId: number, fileId: string): Promise<void> {
|
||||
if (!fileId) throw new Error('publish requires fileId');
|
||||
const bridge = asBridge(this.ctx);
|
||||
const env = makeOidbEnvelope<OidbGroupSendFileReq>(0x6D9, 4, {
|
||||
body: {
|
||||
groupUin: groupId,
|
||||
type: 2,
|
||||
info: {
|
||||
busiType: 102,
|
||||
fileId,
|
||||
field3: Math.floor(Math.random() * 0x7fffffff) >>> 0,
|
||||
field5: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
await runOidb(bridge, 'OidbSvcTrpcTcp.0x6d9_4', protobuf_encode<OidbBase<OidbGroupSendFileReq>>(env));
|
||||
return PublishGroupFile.invoke(this.ctx, { groupId, fileId });
|
||||
}
|
||||
|
||||
// ─────────────── count ───────────────
|
||||
|
||||
async getCount(groupId: number): Promise<{ fileCount: number; maxCount: number }> {
|
||||
const bridge = asBridge(this.ctx);
|
||||
const env = makeOidbEnvelope<OidbGroupFileCountViewReq>(
|
||||
0x6D8, 3,
|
||||
{ count: { groupUin: groupId, appId: 7, busId: 0 } },
|
||||
);
|
||||
const respBytes = await runOidb(bridge, 'OidbSvcTrpcTcp.0x6d8_3', protobuf_encode<OidbBase<OidbGroupFileCountViewReq>>(env));
|
||||
const resp = protobuf_decode<OidbBase<OidbGroupFileCountViewResp>>(respBytes).body;
|
||||
return {
|
||||
fileCount: toInt(resp?.count?.fileCount ?? 0),
|
||||
maxCount: toInt(resp?.count?.maxCount ?? 10000),
|
||||
};
|
||||
getCount(groupId: number): Promise<{ fileCount: number; maxCount: number }> {
|
||||
return GetGroupFileCount.invoke(this.ctx, { groupId });
|
||||
}
|
||||
|
||||
// ─────────────── upload ───────────────
|
||||
// ─────────────── upload (3-stage: OIDB preflight → highway → publish) ───────────────
|
||||
|
||||
async upload(
|
||||
groupId: number,
|
||||
@@ -361,31 +260,14 @@ export class GroupFileApi {
|
||||
const fileName = normalizeUploadFileName(name, loaded.fileName);
|
||||
const hashes = computeHashes(loaded.bytes);
|
||||
|
||||
const env = makeOidbEnvelope<OidbGroupFileReq>(
|
||||
0x6D6, 0,
|
||||
{
|
||||
file: {
|
||||
groupUin: groupId,
|
||||
appId: 4,
|
||||
busId: 102,
|
||||
entrance: 6,
|
||||
targetDirectory: normalizeDirectory(folderId),
|
||||
fileName,
|
||||
localDirectory: `/${fileName}`,
|
||||
fileSize: BigInt(loaded.bytes.length),
|
||||
fileSha1: hashes.sha1,
|
||||
fileSha3: new Uint8Array(0),
|
||||
fileMd5: hashes.md5,
|
||||
field15: true,
|
||||
},
|
||||
},
|
||||
true,
|
||||
);
|
||||
const respBytes = await runOidb(bridge, 'OidbSvcTrpcTcp.0x6d6_0', protobuf_encode<OidbBase<OidbGroupFileReq>>(env));
|
||||
const resp = protobuf_decode<OidbBase<OidbGroupFileResp>>(respBytes).body;
|
||||
|
||||
const upload = resp?.upload;
|
||||
if (!upload) throw new Error('group file upload response missing');
|
||||
const upload = await UploadGroupFileRequest.invoke(this.ctx, {
|
||||
groupId,
|
||||
fileName,
|
||||
folderId: normalizeDirectory(folderId),
|
||||
fileSize: loaded.bytes.length,
|
||||
fileSha1: hashes.sha1,
|
||||
fileMd5: hashes.md5,
|
||||
});
|
||||
ensureRetCodeZero('group file upload', upload.retCode, upload.retMsg, upload.clientWording);
|
||||
|
||||
const fileId = typeof upload.fileId === 'string' && upload.fileId ? upload.fileId : null;
|
||||
@@ -470,8 +352,6 @@ export class GroupFileApi {
|
||||
uploadFile = true,
|
||||
): Promise<UploadFileResult> {
|
||||
const bridge = asBridge(this.ctx);
|
||||
// Group/private files may legitimately be up to 4 GiB on QQ's wire,
|
||||
// so override the default 1 GiB cap with the protocol ceiling.
|
||||
const loaded = await loadBinarySource(source, 'file', FILE_UPLOAD_MAX_BYTES);
|
||||
if (!loaded.bytes.length) throw new Error('private file is empty');
|
||||
|
||||
@@ -491,29 +371,15 @@ export class GroupFileApi {
|
||||
const fileName = normalizeUploadFileName(name, loaded.fileName);
|
||||
const hashes = computeHashes(loaded.bytes);
|
||||
|
||||
const env = makeOidbEnvelope<OidbPrivateFileUploadReq>(0xE37, 1700, {
|
||||
command: 1700,
|
||||
seq: 0,
|
||||
upload: {
|
||||
senderUid: selfUid,
|
||||
receiverUid: targetUid,
|
||||
fileSize: loaded.bytes.length,
|
||||
fileName,
|
||||
md510MCheckSum: md5First10MB(loaded.bytes),
|
||||
sha1CheckSum: hashes.sha1,
|
||||
localPath: '/',
|
||||
md5CheckSum: hashes.md5,
|
||||
sha3CheckSum: new Uint8Array(0),
|
||||
},
|
||||
businessId: 3,
|
||||
clientType: 1,
|
||||
flagSupportMediaPlatform: 1,
|
||||
const upload = await UploadPrivateFileRequest.invoke(this.ctx, {
|
||||
senderUid: selfUid,
|
||||
receiverUid: targetUid,
|
||||
fileName,
|
||||
fileSize: loaded.bytes.length,
|
||||
fileSha1: hashes.sha1,
|
||||
fileMd5: hashes.md5,
|
||||
md510MCheckSum: md5First10MB(loaded.bytes),
|
||||
});
|
||||
const respBytes = await runOidb(bridge, 'OidbSvcTrpcTcp.0xe37_1700', protobuf_encode<OidbBase<OidbPrivateFileUploadReq>>(env));
|
||||
const resp = protobuf_decode<OidbBase<OidbPrivateFileUploadResp>>(respBytes).body;
|
||||
|
||||
const upload = resp?.upload;
|
||||
if (!upload) throw new Error('private file upload response missing');
|
||||
ensureRetCodeZero('private file upload', upload.retCode, upload.retMsg, undefined);
|
||||
|
||||
const fileId = typeof upload.uuid === 'string' && upload.uuid ? upload.uuid : null;
|
||||
@@ -583,10 +449,6 @@ export class GroupFileApi {
|
||||
? toInt(upload.uploadHttpsPort)
|
||||
: toInt(upload.uploadPort);
|
||||
if (!uploadHost || uploadPort <= 0) {
|
||||
// Surface every host-bearing field we know about so a user
|
||||
// hitting this can show us exactly which slot the server filled
|
||||
// (or whether it returned nothing at all — which would point at
|
||||
// a request mismatch rather than a missing decoder).
|
||||
const rtpDump = Array.isArray(upload.rtpMediaPlatformUploadAddress)
|
||||
? JSON.stringify(upload.rtpMediaPlatformUploadAddress.map((e: any) => ({
|
||||
outIP: e.outIP, outPort: e.outPort, inIP: e.inIP, inPort: e.inPort,
|
||||
@@ -647,10 +509,9 @@ export class GroupFileApi {
|
||||
return { fileId, fileHash };
|
||||
}
|
||||
|
||||
// ─────────────── list ───────────────
|
||||
// ─────────────── list (paginated loop) ───────────────
|
||||
|
||||
async list(groupId: number, folderId = '/'): Promise<GroupFilesResult> {
|
||||
const bridge = asBridge(this.ctx);
|
||||
const targetDirectory = normalizeDirectory(folderId);
|
||||
const files: GroupFileInfo[] = [];
|
||||
const folders: GroupFolderInfo[] = [];
|
||||
@@ -658,26 +519,9 @@ export class GroupFileApi {
|
||||
const pageSize = 20;
|
||||
let startIndex = 0;
|
||||
for (let page = 0; page < 200; page++) {
|
||||
const env = makeOidbEnvelope<OidbGroupFileViewReq>(
|
||||
0x6D8, 1,
|
||||
{
|
||||
list: {
|
||||
groupUin: groupId,
|
||||
appId: 7,
|
||||
targetDirectory,
|
||||
fileCount: pageSize,
|
||||
sortBy: 1,
|
||||
startIndex,
|
||||
field17: 2,
|
||||
field18: 0,
|
||||
},
|
||||
},
|
||||
true,
|
||||
);
|
||||
const respBytes = await runOidb(bridge, 'OidbSvcTrpcTcp.0x6d8_1', protobuf_encode<OidbBase<OidbGroupFileViewReq>>(env));
|
||||
const resp = protobuf_decode<OidbBase<OidbGroupFileViewResp>>(respBytes).body;
|
||||
|
||||
const list = resp?.list;
|
||||
const list = await ListGroupFilesPage.invoke(this.ctx, {
|
||||
groupId, targetDirectory, startIndex, pageSize,
|
||||
});
|
||||
if (!list) break;
|
||||
ensureRetCodeZero('group file list', list.retCode, list.retMsg, list.clientWording);
|
||||
|
||||
@@ -730,24 +574,7 @@ export class GroupFileApi {
|
||||
// ─────────────── url fetch (group / private files) ───────────────
|
||||
|
||||
async getUrl(groupId: number, fileId: string, busId = 102): Promise<string> {
|
||||
const bridge = asBridge(this.ctx);
|
||||
const env = makeOidbEnvelope<OidbGroupFileReq>(
|
||||
0x6D6, 2,
|
||||
{
|
||||
download: {
|
||||
groupUin: groupId,
|
||||
appId: 7,
|
||||
busId,
|
||||
fileId,
|
||||
},
|
||||
},
|
||||
true,
|
||||
);
|
||||
const respBytes = await runOidb(bridge, 'OidbSvcTrpcTcp.0x6d6_2', protobuf_encode<OidbBase<OidbGroupFileReq>>(env));
|
||||
const resp = protobuf_decode<OidbBase<OidbGroupFileResp>>(respBytes).body;
|
||||
|
||||
const download = resp?.download;
|
||||
if (!download) throw new Error('group file url response missing');
|
||||
const download = await GetGroupFileUrl.invoke(this.ctx, { groupId, fileId, busId });
|
||||
ensureRetCodeZero('group file url', download.retCode, download.retMsg, download.clientWording);
|
||||
|
||||
const dns = (typeof download.downloadDns === 'string' && download.downloadDns)
|
||||
@@ -766,25 +593,8 @@ export class GroupFileApi {
|
||||
const bridge = asBridge(this.ctx);
|
||||
const selfUid = await resolveSelfUid(bridge);
|
||||
void userId;
|
||||
const env = makeOidbEnvelope<OidbPrivateFileDownloadReq>(0xE37, 1200, {
|
||||
subCommand: 1200,
|
||||
field2: 1,
|
||||
body: {
|
||||
receiverUid: selfUid,
|
||||
fileUuid: fileId,
|
||||
type: 2,
|
||||
fileHash,
|
||||
t2: 0,
|
||||
},
|
||||
field101: 3,
|
||||
field102: 103,
|
||||
field200: 1,
|
||||
field99999: new Uint8Array([0xC0, 0x85, 0x2C, 0x01]),
|
||||
});
|
||||
const respBytes = await runOidb(bridge, 'OidbSvcTrpcTcp.0xe37_1200', protobuf_encode<OidbBase<OidbPrivateFileDownloadReq>>(env), 5000);
|
||||
const resp = protobuf_decode<OidbBase<OidbPrivateFileDownloadResp>>(respBytes).body;
|
||||
const result = await GetPrivateFileUrl.invoke(this.ctx, { selfUid, fileId, fileHash });
|
||||
|
||||
const result = resp?.body?.result;
|
||||
const server = typeof result?.server === 'string' ? result.server : '';
|
||||
const port = toInt(result?.port);
|
||||
const url = typeof result?.url === 'string' ? result.url : '';
|
||||
@@ -796,211 +606,49 @@ export class GroupFileApi {
|
||||
|
||||
// ─────────────── delete / move ───────────────
|
||||
|
||||
async delete(groupId: number, fileId: string): Promise<void> {
|
||||
const bridge = asBridge(this.ctx);
|
||||
const env = makeOidbEnvelope<OidbGroupFileReq>(
|
||||
0x6D6, 3,
|
||||
{
|
||||
delete: {
|
||||
groupUin: groupId,
|
||||
busId: 102,
|
||||
fileId,
|
||||
},
|
||||
},
|
||||
true,
|
||||
);
|
||||
const respBytes = await runOidb(bridge, 'OidbSvcTrpcTcp.0x6d6_3', protobuf_encode<OidbBase<OidbGroupFileReq>>(env));
|
||||
const resp = protobuf_decode<OidbBase<OidbGroupFileResp>>(respBytes).body;
|
||||
|
||||
const result = resp?.delete;
|
||||
if (!result) throw new Error('group file delete response missing');
|
||||
ensureRetCodeZero('group file delete', result.retCode, result.retMsg, result.clientWording);
|
||||
delete(groupId: number, fileId: string): Promise<void> {
|
||||
return DeleteGroupFile.invoke(this.ctx, { groupId, fileId });
|
||||
}
|
||||
|
||||
async move(
|
||||
groupId: number,
|
||||
fileId: string,
|
||||
parentDirectory: string,
|
||||
targetDirectory: string,
|
||||
): Promise<void> {
|
||||
const bridge = asBridge(this.ctx);
|
||||
const env = makeOidbEnvelope<OidbGroupFileReq>(
|
||||
0x6D6, 5,
|
||||
{
|
||||
move: {
|
||||
groupUin: groupId,
|
||||
appId: 7,
|
||||
busId: 102,
|
||||
fileId,
|
||||
parentDirectory,
|
||||
targetDirectory,
|
||||
},
|
||||
},
|
||||
true,
|
||||
);
|
||||
const respBytes = await runOidb(bridge, 'OidbSvcTrpcTcp.0x6d6_5', protobuf_encode<OidbBase<OidbGroupFileReq>>(env));
|
||||
const resp = protobuf_decode<OidbBase<OidbGroupFileResp>>(respBytes).body;
|
||||
|
||||
const result = resp?.move;
|
||||
if (!result) throw new Error('group file move response missing');
|
||||
ensureRetCodeZero('group file move', result.retCode, result.retMsg, result.clientWording);
|
||||
move(groupId: number, fileId: string, parentDirectory: string, targetDirectory: string): Promise<void> {
|
||||
return MoveGroupFile.invoke(this.ctx, { groupId, fileId, parentDirectory, targetDirectory });
|
||||
}
|
||||
|
||||
// ─────────────── folders ───────────────
|
||||
|
||||
async createFolder(groupId: number, name: string, parentId = '/'): Promise<void> {
|
||||
const bridge = asBridge(this.ctx);
|
||||
const env = makeOidbEnvelope<OidbGroupFileFolderReq>(
|
||||
0x6D7, 0,
|
||||
{
|
||||
create: {
|
||||
groupUin: groupId,
|
||||
rootDirectory: normalizeDirectory(parentId),
|
||||
folderName: name,
|
||||
},
|
||||
},
|
||||
true,
|
||||
);
|
||||
const respBytes = await runOidb(bridge, 'OidbSvcTrpcTcp.0x6d7_0', protobuf_encode<OidbBase<OidbGroupFileFolderReq>>(env));
|
||||
const resp = protobuf_decode<OidbBase<OidbGroupFileFolderResp>>(respBytes).body;
|
||||
|
||||
const result = resp?.create;
|
||||
if (!result) throw new Error('group folder create response missing');
|
||||
ensureRetCodeZero('group folder create', result.retcode, result.retMsg, result.clientWording);
|
||||
createFolder(groupId: number, name: string, parentId = '/'): Promise<void> {
|
||||
return CreateGroupFolder.invoke(this.ctx, {
|
||||
groupId, parentId: normalizeDirectory(parentId), folderName: name,
|
||||
});
|
||||
}
|
||||
|
||||
async deleteFolder(groupId: number, folderId: string): Promise<void> {
|
||||
const bridge = asBridge(this.ctx);
|
||||
const env = makeOidbEnvelope<OidbGroupFileFolderReq>(
|
||||
0x6D7, 1,
|
||||
{
|
||||
delete: {
|
||||
groupUin: groupId,
|
||||
folderId,
|
||||
},
|
||||
},
|
||||
true,
|
||||
);
|
||||
const respBytes = await runOidb(bridge, 'OidbSvcTrpcTcp.0x6d7_1', protobuf_encode<OidbBase<OidbGroupFileFolderReq>>(env));
|
||||
const resp = protobuf_decode<OidbBase<OidbGroupFileFolderResp>>(respBytes).body;
|
||||
|
||||
const result = resp?.delete;
|
||||
if (!result) throw new Error('group folder delete response missing');
|
||||
ensureRetCodeZero('group folder delete', result.retcode, result.retMsg, result.clientWording);
|
||||
deleteFolder(groupId: number, folderId: string): Promise<void> {
|
||||
return DeleteGroupFolder.invoke(this.ctx, { groupId, folderId });
|
||||
}
|
||||
|
||||
async renameFolder(groupId: number, folderId: string, newFolderName: string): Promise<void> {
|
||||
const bridge = asBridge(this.ctx);
|
||||
const env = makeOidbEnvelope<OidbGroupFileFolderReq>(
|
||||
0x6D7, 2,
|
||||
{
|
||||
rename: {
|
||||
groupUin: groupId,
|
||||
folderId,
|
||||
newFolderName,
|
||||
},
|
||||
},
|
||||
true,
|
||||
);
|
||||
const respBytes = await runOidb(bridge, 'OidbSvcTrpcTcp.0x6d7_2', protobuf_encode<OidbBase<OidbGroupFileFolderReq>>(env));
|
||||
const resp = protobuf_decode<OidbBase<OidbGroupFileFolderResp>>(respBytes).body;
|
||||
|
||||
const result = resp?.rename;
|
||||
if (!result) throw new Error('group folder rename response missing');
|
||||
ensureRetCodeZero('group folder rename', result.retcode, result.retMsg, result.clientWording);
|
||||
renameFolder(groupId: number, folderId: string, newFolderName: string): Promise<void> {
|
||||
return RenameGroupFolder.invoke(this.ctx, { groupId, folderId, newFolderName });
|
||||
}
|
||||
|
||||
// ─────────────── rich-media URL by node ───────────────
|
||||
|
||||
async getPttUrl(groupId: number, node: MediaIndexNode): Promise<string> {
|
||||
const bridge = asBridge(this.ctx);
|
||||
const normalizedNode = normalizeMediaNode(node);
|
||||
return fetchNtv2DownloadUrl(bridge, 'OidbSvcTrpcTcp.0x126e_200', 0x126E, {
|
||||
reqHead: {
|
||||
common: { requestId: 4, command: 200 },
|
||||
scene: {
|
||||
requestType: 1,
|
||||
businessType: 3,
|
||||
sceneType: 2,
|
||||
group: { groupUin: groupId },
|
||||
},
|
||||
client: { agentType: 2 },
|
||||
},
|
||||
download: {
|
||||
node: normalizedNode,
|
||||
download: { video: { busiType: 0, sceneType: 0 } },
|
||||
},
|
||||
});
|
||||
getPttUrl(groupId: number, node: MediaIndexNode): Promise<string> {
|
||||
return GetGroupPttUrl.invoke(this.ctx, { groupId, node });
|
||||
}
|
||||
|
||||
async getPrivatePttUrl(node: MediaIndexNode): Promise<string> {
|
||||
const bridge = asBridge(this.ctx);
|
||||
const selfUid = await resolveSelfUid(bridge);
|
||||
const normalizedNode = normalizeMediaNode(node);
|
||||
return fetchNtv2DownloadUrl(bridge, 'OidbSvcTrpcTcp.0x126d_200', 0x126D, {
|
||||
reqHead: {
|
||||
common: { requestId: 1, command: 200 },
|
||||
scene: {
|
||||
requestType: 1,
|
||||
businessType: 3,
|
||||
sceneType: 1,
|
||||
c2c: {
|
||||
accountType: 2,
|
||||
targetUid: selfUid,
|
||||
},
|
||||
},
|
||||
client: { agentType: 2 },
|
||||
},
|
||||
download: {
|
||||
node: normalizedNode,
|
||||
download: { video: { busiType: 0, sceneType: 0 } },
|
||||
},
|
||||
});
|
||||
return GetPrivatePttUrl.invoke(this.ctx, { selfUid, node });
|
||||
}
|
||||
|
||||
async getVideoUrl(groupId: number, node: MediaIndexNode): Promise<string> {
|
||||
const bridge = asBridge(this.ctx);
|
||||
const normalizedNode = normalizeMediaNode(node);
|
||||
return fetchNtv2DownloadUrl(bridge, 'OidbSvcTrpcTcp.0x11ea_200', 0x11EA, {
|
||||
reqHead: {
|
||||
common: { requestId: 1, command: 200 },
|
||||
scene: {
|
||||
requestType: 2,
|
||||
businessType: 2,
|
||||
sceneType: 2,
|
||||
group: { groupUin: groupId },
|
||||
},
|
||||
client: { agentType: 2 },
|
||||
},
|
||||
download: {
|
||||
node: normalizedNode,
|
||||
download: { video: { busiType: 0, sceneType: 0 } },
|
||||
},
|
||||
});
|
||||
getVideoUrl(groupId: number, node: MediaIndexNode): Promise<string> {
|
||||
return GetGroupVideoUrl.invoke(this.ctx, { groupId, node });
|
||||
}
|
||||
|
||||
async getPrivateVideoUrl(node: MediaIndexNode): Promise<string> {
|
||||
const bridge = asBridge(this.ctx);
|
||||
const selfUid = await resolveSelfUid(bridge);
|
||||
const normalizedNode = normalizeMediaNode(node);
|
||||
return fetchNtv2DownloadUrl(bridge, 'OidbSvcTrpcTcp.0x11e9_200', 0x11E9, {
|
||||
reqHead: {
|
||||
common: { requestId: 1, command: 200 },
|
||||
scene: {
|
||||
requestType: 2,
|
||||
businessType: 2,
|
||||
sceneType: 1,
|
||||
c2c: {
|
||||
accountType: 2,
|
||||
targetUid: selfUid,
|
||||
},
|
||||
},
|
||||
client: { agentType: 2 },
|
||||
},
|
||||
download: {
|
||||
node: normalizedNode,
|
||||
download: { video: { busiType: 0, sceneType: 0 } },
|
||||
},
|
||||
});
|
||||
return GetPrivateVideoUrl.invoke(this.ctx, { selfUid, node });
|
||||
}
|
||||
}
|
||||
@@ -1,32 +1,26 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
import { protobuf_encode } from '@snowluma/proton';
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type {
|
||||
OidbGroupFileCountViewResp,
|
||||
OidbGroupFileReq,
|
||||
OidbGroupFileResp,
|
||||
OidbGroupFileViewResp,
|
||||
OidbGroupFileFolderResp,
|
||||
OidbGroupSendFileReq,
|
||||
} from '@snowluma/proto-defs/oidb-actions/group-file';
|
||||
import type {
|
||||
OidbPrivateFileUploadResp,
|
||||
NTV2RichMediaResp,
|
||||
} from '@snowluma/proto-defs/oidb-actions/media';
|
||||
|
||||
// `encodeOidbEnv` / `decodeOidbEnv` are proton-bound pass-through wrappers
|
||||
// (substituted at the call site with the inlined codec). Mocking them on
|
||||
// the module object is a no-op — proton has already inlined the call.
|
||||
// We mock `runOidb` (non-generic, proton leaves it alone) to return real
|
||||
// proton-encoded bytes, which the production-side codec then decodes.
|
||||
vi.mock('@snowluma/bridge/bridge-oidb', async () => {
|
||||
const actual = await vi.importActual<typeof import('@snowluma/bridge/bridge-oidb')>(
|
||||
'@snowluma/bridge/bridge-oidb',
|
||||
);
|
||||
return {
|
||||
...actual,
|
||||
runOidb: vi.fn(async () => new Uint8Array()),
|
||||
makeOidbEnvelope: vi.fn((_oidbCmd, _subCmd, body) => ({ body })),
|
||||
};
|
||||
});
|
||||
// Post-namespace migration: GroupFileApi forwards single-OIDB methods
|
||||
// through namespaces under @snowluma/bridge/oidb-services/group-file.
|
||||
// The multi-stage methods (`upload` / `uploadPrivate`) keep their
|
||||
// orchestration on the facade; we assert against bridge.sendRawPacket
|
||||
// directly. Highway calls (fetchHighwaySession / uploadHighwayHttp)
|
||||
// and the file-source loader are still module-mocked because the
|
||||
// facade owns those calls directly.
|
||||
|
||||
vi.mock('@snowluma/bridge/highway', () => ({
|
||||
fetchHighwaySession: vi.fn(async () => ({})),
|
||||
@@ -43,55 +37,56 @@ vi.mock('@snowluma/bridge/highway/utils', () => ({
|
||||
FILE_UPLOAD_MAX_BYTES: 4 * 1024 * 1024 * 1024,
|
||||
}));
|
||||
|
||||
import * as oidb from '@snowluma/bridge/bridge-oidb';
|
||||
import * as highwayClient from '@snowluma/bridge/highway';
|
||||
import { GroupFileApi } from '../../src/bridge/apis/group-file';
|
||||
import { mockBridge } from './_helpers';
|
||||
|
||||
describe('actions/group-file', () => {
|
||||
function packResponse(body: Uint8Array) {
|
||||
return {
|
||||
success: true, gotResponse: true, errorCode: 0, errorMessage: '',
|
||||
responseData: Buffer.from(body),
|
||||
};
|
||||
}
|
||||
|
||||
describe('apis/group-file', () => {
|
||||
beforeEach(() => {
|
||||
vi.mocked(oidb.runOidb).mockReset();
|
||||
vi.mocked(oidb.runOidb).mockResolvedValue(new Uint8Array());
|
||||
vi.mocked(oidb.makeOidbEnvelope).mockClear();
|
||||
vi.mocked(highwayClient.fetchHighwaySession).mockClear();
|
||||
vi.mocked(highwayClient.uploadHighwayHttp).mockClear();
|
||||
});
|
||||
|
||||
it('getCount returns { fileCount, maxCount } from the OIDB response', async () => {
|
||||
const bridge = mockBridge();
|
||||
vi.mocked(oidb.runOidb).mockResolvedValueOnce(
|
||||
bridge.sendRawPacket.mockResolvedValueOnce(packResponse(
|
||||
protobuf_encode<OidbBase<OidbGroupFileCountViewResp>>({
|
||||
body: { count: { fileCount: 42, maxCount: 1000 } },
|
||||
}),
|
||||
);
|
||||
));
|
||||
const out = await new GroupFileApi(bridge as any).getCount(12345);
|
||||
expect(out).toEqual({ fileCount: 42, maxCount: 1000 });
|
||||
});
|
||||
|
||||
it('getCount falls back to defaults on partial response', async () => {
|
||||
const bridge = mockBridge();
|
||||
vi.mocked(oidb.runOidb).mockResolvedValueOnce(
|
||||
bridge.sendRawPacket.mockResolvedValueOnce(packResponse(
|
||||
protobuf_encode<OidbBase<OidbGroupFileCountViewResp>>({ body: { count: {} } }),
|
||||
);
|
||||
));
|
||||
const out = await new GroupFileApi(bridge as any).getCount(12345);
|
||||
expect(out).toEqual({ fileCount: 0, maxCount: 10000 });
|
||||
});
|
||||
|
||||
it('upload skips highway when boolFileExist is true', async () => {
|
||||
const bridge = mockBridge();
|
||||
vi.mocked(oidb.runOidb).mockResolvedValueOnce(
|
||||
bridge.sendRawPacket.mockResolvedValueOnce(packResponse(
|
||||
protobuf_encode<OidbBase<OidbGroupFileResp>>({
|
||||
body: {
|
||||
upload: {
|
||||
// retCode 0 omitted by proto3 — production only checks against nonzero
|
||||
fileId: 'fid-xyz',
|
||||
boolFileExist: true,
|
||||
},
|
||||
} as any,
|
||||
}),
|
||||
);
|
||||
));
|
||||
const api = new GroupFileApi(bridge as any);
|
||||
// Suppress the auto-publish — that path is covered separately.
|
||||
vi.spyOn(api, 'publish').mockResolvedValue();
|
||||
const out = await api.upload(12345, '/path/file.bin');
|
||||
expect(out).toEqual({ fileId: 'fid-xyz' });
|
||||
@@ -101,13 +96,12 @@ describe('actions/group-file', () => {
|
||||
|
||||
it('upload runs highway PUT when boolFileExist is false', async () => {
|
||||
const bridge = mockBridge();
|
||||
vi.mocked(oidb.runOidb).mockResolvedValueOnce(
|
||||
bridge.sendRawPacket.mockResolvedValueOnce(packResponse(
|
||||
protobuf_encode<OidbBase<OidbGroupFileResp>>({
|
||||
body: {
|
||||
upload: {
|
||||
fileId: 'fid-xyz',
|
||||
// boolFileExist is the proto3 default (false) — omit, production
|
||||
// sees undefined which the helper treats as "must upload via highway".
|
||||
// boolFileExist is the proto3 default (false) — omit.
|
||||
uploadIp: '1.2.3.4',
|
||||
uploadPort: 8080,
|
||||
fileKey: new Uint8Array([9]),
|
||||
@@ -115,7 +109,7 @@ describe('actions/group-file', () => {
|
||||
},
|
||||
} as any,
|
||||
}),
|
||||
);
|
||||
));
|
||||
const api = new GroupFileApi(bridge as any);
|
||||
vi.spyOn(api, 'publish').mockResolvedValue();
|
||||
await api.upload(12345, '/path/file.bin');
|
||||
@@ -125,20 +119,20 @@ describe('actions/group-file', () => {
|
||||
|
||||
it('upload throws on missing upload response', async () => {
|
||||
const bridge = mockBridge();
|
||||
vi.mocked(oidb.runOidb).mockResolvedValueOnce(
|
||||
bridge.sendRawPacket.mockResolvedValueOnce(packResponse(
|
||||
protobuf_encode<OidbBase<OidbGroupFileResp>>({ body: {} }),
|
||||
);
|
||||
));
|
||||
await expect(new GroupFileApi(bridge as any).upload(12345, '/path/file.bin'))
|
||||
.rejects.toThrow(/response missing/);
|
||||
});
|
||||
|
||||
it('upload bubbles up OIDB retCode errors', async () => {
|
||||
const bridge = mockBridge();
|
||||
vi.mocked(oidb.runOidb).mockResolvedValueOnce(
|
||||
bridge.sendRawPacket.mockResolvedValueOnce(packResponse(
|
||||
protobuf_encode<OidbBase<OidbGroupFileResp>>({
|
||||
body: { upload: { retCode: 999, retMsg: 'quota exceeded' } as any },
|
||||
}),
|
||||
);
|
||||
));
|
||||
await expect(new GroupFileApi(bridge as any).upload(12345, '/path/file.bin'))
|
||||
.rejects.toThrow(/code=999/);
|
||||
});
|
||||
@@ -146,17 +140,13 @@ describe('actions/group-file', () => {
|
||||
it('upload publishes the file via OIDB 0x6d9_4 after upload (the "empty message" regression)', async () => {
|
||||
// Reproduces the bug report: OIDB upload + highway PUT alone only
|
||||
// stage the bytes on QQ's side; without the trailing 0x6d9_4 OIDB
|
||||
// call the file never appears in the chat. Earlier attempts used
|
||||
// PbSendMsg with a transElem(24) but the QQ-NT server rejects that
|
||||
// with result=79 (transElem(24) is a receive-side decoding shape,
|
||||
// not a send-side one). Asserts that `this.publish` is invoked
|
||||
// with the uploaded fileId.
|
||||
// call the file never appears in the chat.
|
||||
const bridge = mockBridge();
|
||||
vi.mocked(oidb.runOidb).mockResolvedValueOnce(
|
||||
bridge.sendRawPacket.mockResolvedValueOnce(packResponse(
|
||||
protobuf_encode<OidbBase<OidbGroupFileResp>>({
|
||||
body: { upload: { fileId: 'fid-pub', boolFileExist: true } as any },
|
||||
}),
|
||||
);
|
||||
));
|
||||
const api = new GroupFileApi(bridge as any);
|
||||
const publishSpy = vi.spyOn(api, 'publish').mockResolvedValue();
|
||||
await api.upload(12345, '/path/some-file.bin', 'mynote.txt');
|
||||
@@ -164,18 +154,16 @@ describe('actions/group-file', () => {
|
||||
const [groupId, fileId] = publishSpy.mock.calls[0]!;
|
||||
expect(groupId).toBe(12345);
|
||||
expect(fileId).toBe('fid-pub');
|
||||
// sendGroup must NOT be touched — the previous wire shape
|
||||
// (PbSendMsg w/ transElem(24)) is the bug we're guarding against.
|
||||
expect(bridge.apis.message.sendGroup).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('upload skips the chat post when uploadFile=false', async () => {
|
||||
const bridge = mockBridge();
|
||||
vi.mocked(oidb.runOidb).mockResolvedValueOnce(
|
||||
bridge.sendRawPacket.mockResolvedValueOnce(packResponse(
|
||||
protobuf_encode<OidbBase<OidbGroupFileResp>>({
|
||||
body: { upload: { fileId: 'fid-skip', boolFileExist: true } as any },
|
||||
}),
|
||||
);
|
||||
));
|
||||
const api = new GroupFileApi(bridge as any);
|
||||
const publishSpy = vi.spyOn(api, 'publish').mockResolvedValue();
|
||||
await api.upload(12345, '/path/file.bin', '', '/', false);
|
||||
@@ -184,11 +172,11 @@ describe('actions/group-file', () => {
|
||||
|
||||
it('upload returns success even when the chat post fails (file is still uploaded)', async () => {
|
||||
const bridge = mockBridge();
|
||||
vi.mocked(oidb.runOidb).mockResolvedValueOnce(
|
||||
bridge.sendRawPacket.mockResolvedValueOnce(packResponse(
|
||||
protobuf_encode<OidbBase<OidbGroupFileResp>>({
|
||||
body: { upload: { fileId: 'fid-tolerant', boolFileExist: true } as any },
|
||||
}),
|
||||
);
|
||||
));
|
||||
const api = new GroupFileApi(bridge as any);
|
||||
const publishSpy = vi.spyOn(api, 'publish').mockRejectedValueOnce(new Error('message rejected'));
|
||||
const out = await api.upload(12345, '/path/file.bin');
|
||||
@@ -197,15 +185,12 @@ describe('actions/group-file', () => {
|
||||
});
|
||||
|
||||
it('upload caches the upload metadata for later resend by file_id', async () => {
|
||||
// After upload, a later `send_group_msg` carrying just the file_id
|
||||
// needs to recover the name/size/md5 from somewhere. Production
|
||||
// populates `ctx.rememberUploadedFile` with the full tuple.
|
||||
const bridge = mockBridge();
|
||||
vi.mocked(oidb.runOidb).mockResolvedValueOnce(
|
||||
bridge.sendRawPacket.mockResolvedValueOnce(packResponse(
|
||||
protobuf_encode<OidbBase<OidbGroupFileResp>>({
|
||||
body: { upload: { fileId: 'fid-cached', boolFileExist: true } as any },
|
||||
}),
|
||||
);
|
||||
));
|
||||
const api = new GroupFileApi(bridge as any);
|
||||
vi.spyOn(api, 'publish').mockResolvedValue();
|
||||
await api.upload(12345, '/path/x.bin', 'x.bin');
|
||||
@@ -220,30 +205,23 @@ describe('actions/group-file', () => {
|
||||
});
|
||||
|
||||
it('publish hits OIDB 0x6d9_4 with the right body', async () => {
|
||||
// Direct cover of the new bridge method. The previous send-shape
|
||||
// (PbSendMsg + transElem(24)) failed with result=79; this is the
|
||||
// Lagrange-V2-mirrored fix.
|
||||
const bridge = mockBridge();
|
||||
vi.mocked(oidb.runOidb).mockResolvedValueOnce(new Uint8Array());
|
||||
await new GroupFileApi(bridge as any).publish(12345, 'fid-publish');
|
||||
expect(oidb.runOidb).toHaveBeenCalledOnce();
|
||||
const [, cmd] = vi.mocked(oidb.runOidb).mock.calls[0]!;
|
||||
expect(cmd).toBe('OidbSvcTrpcTcp.0x6d9_4');
|
||||
// The envelope wraps a `{body: {groupUin, type=2, info: {busiType=102, fileId, ...}}}`.
|
||||
expect(oidb.makeOidbEnvelope).toHaveBeenCalledWith(
|
||||
0x6D9, 4,
|
||||
expect.objectContaining({
|
||||
body: expect.objectContaining({
|
||||
groupUin: 12345,
|
||||
type: 2,
|
||||
info: expect.objectContaining({
|
||||
busiType: 102,
|
||||
fileId: 'fid-publish',
|
||||
field5: true,
|
||||
}),
|
||||
}),
|
||||
expect(bridge.sendRawPacket).toHaveBeenCalledOnce();
|
||||
const [wire, bytes] = bridge.sendRawPacket.mock.calls[0]!;
|
||||
expect(wire).toBe('OidbSvcTrpcTcp.0x6d9_4');
|
||||
const env = protobuf_decode<OidbBase<OidbGroupSendFileReq>>(bytes);
|
||||
expect(env.command).toBe(0x6D9);
|
||||
expect(env.subCommand).toBe(4);
|
||||
expect(env.body?.body).toMatchObject({
|
||||
groupUin: 12345,
|
||||
type: 2,
|
||||
info: expect.objectContaining({
|
||||
busiType: 102,
|
||||
fileId: 'fid-publish',
|
||||
field5: true,
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('uploadPrivate resolves both target + self UID before OIDB call', async () => {
|
||||
@@ -258,31 +236,26 @@ describe('actions/group-file', () => {
|
||||
},
|
||||
});
|
||||
vi.mocked(bridge.resolveUserUid)
|
||||
.mockResolvedValueOnce('target-uid') // target user
|
||||
.mockResolvedValueOnce('self-uid-resolved'); // self fallback
|
||||
vi.mocked(oidb.runOidb).mockResolvedValueOnce(
|
||||
.mockResolvedValueOnce('target-uid')
|
||||
.mockResolvedValueOnce('self-uid-resolved');
|
||||
bridge.sendRawPacket.mockResolvedValueOnce(packResponse(
|
||||
protobuf_encode<OidbBase<OidbPrivateFileUploadResp>>({
|
||||
body: { upload: { uuid: 'fid', fileAddon: 'hash', boolFileExist: true } as any },
|
||||
}),
|
||||
);
|
||||
));
|
||||
const out = await new GroupFileApi(bridge as any).uploadPrivate(67890, '/path/file');
|
||||
expect(out).toEqual({ fileId: 'fid', fileHash: 'hash' });
|
||||
expect(bridge.resolveUserUid).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
it('uploadPrivate publishes the file via apis.message.sendC2cFile after upload', async () => {
|
||||
// C2C files use `RichText.notOnlineFile` (not in the elems array),
|
||||
// so `uploadPrivate` calls the dedicated `sendC2cFile` path on
|
||||
// the bridge rather than `sendPrivate`. Same bug class as the
|
||||
// group case — without this the recipient sees no message even
|
||||
// though the bytes are on the server.
|
||||
const bridge = mockBridge();
|
||||
vi.mocked(bridge.resolveUserUid).mockResolvedValueOnce('target-uid');
|
||||
vi.mocked(oidb.runOidb).mockResolvedValueOnce(
|
||||
bridge.sendRawPacket.mockResolvedValueOnce(packResponse(
|
||||
protobuf_encode<OidbBase<OidbPrivateFileUploadResp>>({
|
||||
body: { upload: { uuid: 'pfid', fileAddon: 'phash', boolFileExist: true } as any },
|
||||
}),
|
||||
);
|
||||
));
|
||||
await new GroupFileApi(bridge as any).uploadPrivate(67890, '/path/private-file.bin', 'doc.pdf');
|
||||
expect(bridge.apis.message.sendC2cFile).toHaveBeenCalledOnce();
|
||||
const [userUin, userUid, info] = bridge.apis.message.sendC2cFile.mock.calls[0]!;
|
||||
@@ -293,18 +266,13 @@ describe('actions/group-file', () => {
|
||||
});
|
||||
|
||||
it('uploadPrivate caches the upload metadata for later resend by file_id', async () => {
|
||||
// C2C file resend (send_private_msg with just file_id) was the
|
||||
// "sends a 0 B file" bug: the wire packet needs fileSize/fileMd5/
|
||||
// fileName/fileHash, but the OneBot caller only knows the file_id.
|
||||
// Caching the upload tuple lets the OneBot send-message path
|
||||
// recover the rest via `ctx.recallUploadedFile(fileId)`.
|
||||
const bridge = mockBridge();
|
||||
vi.mocked(bridge.resolveUserUid).mockResolvedValueOnce('target-uid');
|
||||
vi.mocked(oidb.runOidb).mockResolvedValueOnce(
|
||||
bridge.sendRawPacket.mockResolvedValueOnce(packResponse(
|
||||
protobuf_encode<OidbBase<OidbPrivateFileUploadResp>>({
|
||||
body: { upload: { uuid: 'pfid-cache', fileAddon: 'addon-hash', boolFileExist: true } as any },
|
||||
}),
|
||||
);
|
||||
));
|
||||
await new GroupFileApi(bridge as any).uploadPrivate(67890, '/path/cache-me.txt', 'cache-me.txt');
|
||||
expect(bridge.rememberUploadedFile).toHaveBeenCalledOnce();
|
||||
const [meta] = bridge.rememberUploadedFile.mock.calls[0]!;
|
||||
@@ -320,32 +288,24 @@ describe('actions/group-file', () => {
|
||||
it('uploadPrivate skips the chat post when uploadFile=false', async () => {
|
||||
const bridge = mockBridge();
|
||||
vi.mocked(bridge.resolveUserUid).mockResolvedValueOnce('target-uid');
|
||||
vi.mocked(oidb.runOidb).mockResolvedValueOnce(
|
||||
bridge.sendRawPacket.mockResolvedValueOnce(packResponse(
|
||||
protobuf_encode<OidbBase<OidbPrivateFileUploadResp>>({
|
||||
body: { upload: { uuid: 'pfid', fileAddon: 'phash', boolFileExist: true } as any },
|
||||
}),
|
||||
);
|
||||
));
|
||||
await new GroupFileApi(bridge as any).uploadPrivate(67890, '/path/file', '', false);
|
||||
expect(bridge.apis.message.sendC2cFile).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('uploadPrivate reads host from rtpMediaPlatformUploadAddress[0].inIP when populated', async () => {
|
||||
// The 2026 QQ-NT server rollout moved the upload host out of the
|
||||
// legacy `uploadIp` (field 60) string into the new
|
||||
// `rtpMediaPlatformUploadAddress` (field 210, repeated IPv4 message).
|
||||
// Mirrors acidify's `UploadPrivateFile.kt` consumer logic — read
|
||||
// `inIP` (LAN, same DC as the OIDB endpoint) and pair with `inPort`.
|
||||
// The int is little-endian-packed: 0x0101A8C0 → 192.168.1.1.
|
||||
const bridge = mockBridge();
|
||||
vi.mocked(bridge.resolveUserUid).mockResolvedValueOnce('target-uid');
|
||||
vi.mocked(oidb.runOidb).mockResolvedValueOnce(
|
||||
bridge.sendRawPacket.mockResolvedValueOnce(packResponse(
|
||||
protobuf_encode<OidbBase<OidbPrivateFileUploadResp>>({
|
||||
body: {
|
||||
upload: {
|
||||
uuid: 'pfid',
|
||||
fileAddon: 'phash',
|
||||
// boolFileExist defaults to false — forces highway path
|
||||
// 192.168.1.1 little-endian packed = (1 << 24) | (1 << 16) | (168 << 8) | 192 = 16885952
|
||||
rtpMediaPlatformUploadAddress: [
|
||||
{ outIP: 0, outPort: 0, inIP: 16885952, inPort: 8080, iPType: 1 },
|
||||
],
|
||||
@@ -353,59 +313,46 @@ describe('actions/group-file', () => {
|
||||
} as any,
|
||||
},
|
||||
}),
|
||||
);
|
||||
));
|
||||
await new GroupFileApi(bridge as any).uploadPrivate(67890, '/path/file.bin');
|
||||
expect(highwayClient.uploadHighwayHttp).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
it('uploadPrivate falls back to uploadDomain when uploadIp is empty', async () => {
|
||||
// Regression: the server has been observed in the wild returning the
|
||||
// highway host in `uploadDomain` (field 70) instead of `uploadIp`
|
||||
// (field 60), causing "private file upload host is invalid". The
|
||||
// helper should walk the parallel host fields rather than dying on
|
||||
// a single missing slot. Cross-referenced against napcat's proto
|
||||
// (`Oidb.0XE37_800.ts` ApplyUploadRespV3) — fields 60/70/130/150/160
|
||||
// all carry plausible host values from the same server endpoint.
|
||||
const bridge = mockBridge();
|
||||
vi.mocked(bridge.resolveUserUid).mockResolvedValueOnce('target-uid');
|
||||
vi.mocked(oidb.runOidb).mockResolvedValueOnce(
|
||||
bridge.sendRawPacket.mockResolvedValueOnce(packResponse(
|
||||
protobuf_encode<OidbBase<OidbPrivateFileUploadResp>>({
|
||||
body: {
|
||||
upload: {
|
||||
uuid: 'pfid',
|
||||
fileAddon: 'phash',
|
||||
// boolFileExist defaults to false (proto3) — forces the
|
||||
// highway path where the host fields actually matter.
|
||||
uploadDomain: 'upload.qpic.cn',
|
||||
uploadPort: 8080,
|
||||
mediaPlatformUploadKey: new Uint8Array([1, 2, 3]),
|
||||
} as any,
|
||||
},
|
||||
}),
|
||||
);
|
||||
));
|
||||
await new GroupFileApi(bridge as any).uploadPrivate(67890, '/path/file.bin');
|
||||
expect(highwayClient.uploadHighwayHttp).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
it('uploadPrivate throws "host is invalid" only when every host field is empty', async () => {
|
||||
// The diagnostic warn-log lists every host slot to help users
|
||||
// report which one the server actually populated; this test just
|
||||
// asserts that the throw still fires when none of them carry a
|
||||
// value (boolFileExist=false + no usable host).
|
||||
const bridge = mockBridge();
|
||||
vi.mocked(bridge.resolveUserUid).mockResolvedValueOnce('target-uid');
|
||||
vi.mocked(oidb.runOidb).mockResolvedValueOnce(
|
||||
bridge.sendRawPacket.mockResolvedValueOnce(packResponse(
|
||||
protobuf_encode<OidbBase<OidbPrivateFileUploadResp>>({
|
||||
body: { upload: { uuid: 'pfid', fileAddon: 'phash', uploadPort: 8080 } as any },
|
||||
}),
|
||||
);
|
||||
));
|
||||
await expect(new GroupFileApi(bridge as any).uploadPrivate(67890, '/path/file.bin'))
|
||||
.rejects.toThrow(/upload host is invalid/);
|
||||
});
|
||||
|
||||
it('list paginates files + folders out of OIDB items', async () => {
|
||||
const bridge = mockBridge();
|
||||
vi.mocked(oidb.runOidb).mockResolvedValueOnce(
|
||||
bridge.sendRawPacket.mockResolvedValueOnce(packResponse(
|
||||
protobuf_encode<OidbBase<OidbGroupFileViewResp>>({
|
||||
body: {
|
||||
list: {
|
||||
@@ -417,7 +364,7 @@ describe('actions/group-file', () => {
|
||||
} as any,
|
||||
},
|
||||
}),
|
||||
);
|
||||
));
|
||||
const out = await new GroupFileApi(bridge as any).list(12345);
|
||||
expect(out.files).toHaveLength(1);
|
||||
expect(out.files[0]).toMatchObject({ fileId: 'f1', fileName: 'a.txt', uploader: 1, uploaderName: 'alice' });
|
||||
@@ -427,7 +374,7 @@ describe('actions/group-file', () => {
|
||||
|
||||
it('getUrl builds the https URL from downloadDns + hex-encoded path', async () => {
|
||||
const bridge = mockBridge();
|
||||
vi.mocked(oidb.runOidb).mockResolvedValueOnce(
|
||||
bridge.sendRawPacket.mockResolvedValueOnce(packResponse(
|
||||
protobuf_encode<OidbBase<OidbGroupFileResp>>({
|
||||
body: {
|
||||
download: {
|
||||
@@ -436,49 +383,53 @@ describe('actions/group-file', () => {
|
||||
} as any,
|
||||
},
|
||||
}),
|
||||
);
|
||||
));
|
||||
const url = await new GroupFileApi(bridge as any).getUrl(12345, 'fid-xyz');
|
||||
expect(url).toBe('https://cdn.example.com/ftn_handler/0102/?fname=fid-xyz');
|
||||
});
|
||||
|
||||
it('getUrl throws when response is missing dns or url', async () => {
|
||||
const bridge = mockBridge();
|
||||
vi.mocked(oidb.runOidb).mockResolvedValueOnce(
|
||||
bridge.sendRawPacket.mockResolvedValueOnce(packResponse(
|
||||
protobuf_encode<OidbBase<OidbGroupFileResp>>({
|
||||
body: { download: {} as any },
|
||||
}),
|
||||
);
|
||||
));
|
||||
await expect(new GroupFileApi(bridge as any).getUrl(12345, 'fid-xyz'))
|
||||
.rejects.toThrow(/invalid/);
|
||||
});
|
||||
|
||||
it('delete / move dispatch the right sub-commands', async () => {
|
||||
const bridge = mockBridge();
|
||||
vi.mocked(oidb.runOidb)
|
||||
.mockResolvedValueOnce(protobuf_encode<OidbBase<OidbGroupFileResp>>({ body: { delete: {} as any } }))
|
||||
.mockResolvedValueOnce(protobuf_encode<OidbBase<OidbGroupFileResp>>({ body: { move: {} as any } }));
|
||||
bridge.sendRawPacket
|
||||
.mockResolvedValueOnce(packResponse(protobuf_encode<OidbBase<OidbGroupFileResp>>({ body: { delete: {} as any } })))
|
||||
.mockResolvedValueOnce(packResponse(protobuf_encode<OidbBase<OidbGroupFileResp>>({ body: { move: {} as any } })));
|
||||
const api = new GroupFileApi(bridge as any);
|
||||
await api.delete(12345, 'fid');
|
||||
await api.move(12345, 'fid', '/a', '/b');
|
||||
expect(vi.mocked(oidb.makeOidbEnvelope).mock.calls.map(c => c[1])).toEqual([3, 5]);
|
||||
const env1 = protobuf_decode<OidbBase<OidbGroupFileReq>>(bridge.sendRawPacket.mock.calls[0]![1]);
|
||||
const env2 = protobuf_decode<OidbBase<OidbGroupFileReq>>(bridge.sendRawPacket.mock.calls[1]![1]);
|
||||
expect(env1.subCommand).toBe(3);
|
||||
expect(env2.subCommand).toBe(5);
|
||||
});
|
||||
|
||||
it('createFolder / deleteFolder / renameFolder dispatch 0x6d7 family', async () => {
|
||||
const bridge = mockBridge();
|
||||
vi.mocked(oidb.runOidb)
|
||||
.mockResolvedValueOnce(protobuf_encode<OidbBase<OidbGroupFileFolderResp>>({ body: { create: {} as any } }))
|
||||
.mockResolvedValueOnce(protobuf_encode<OidbBase<OidbGroupFileFolderResp>>({ body: { delete: {} as any } }))
|
||||
.mockResolvedValueOnce(protobuf_encode<OidbBase<OidbGroupFileFolderResp>>({ body: { rename: {} as any } }));
|
||||
bridge.sendRawPacket
|
||||
.mockResolvedValueOnce(packResponse(protobuf_encode<OidbBase<OidbGroupFileFolderResp>>({ body: { create: {} as any } })))
|
||||
.mockResolvedValueOnce(packResponse(protobuf_encode<OidbBase<OidbGroupFileFolderResp>>({ body: { delete: {} as any } })))
|
||||
.mockResolvedValueOnce(packResponse(protobuf_encode<OidbBase<OidbGroupFileFolderResp>>({ body: { rename: {} as any } })));
|
||||
const api = new GroupFileApi(bridge as any);
|
||||
await api.createFolder(1, 'folder');
|
||||
await api.deleteFolder(1, 'fid');
|
||||
await api.renameFolder(1, 'fid', 'newname');
|
||||
expect(vi.mocked(oidb.makeOidbEnvelope).mock.calls.map(c => c[0])).toEqual([0x6D7, 0x6D7, 0x6D7]);
|
||||
const cmds = bridge.sendRawPacket.mock.calls.map(c => c[0]);
|
||||
expect(cmds).toEqual(['OidbSvcTrpcTcp.0x6d7_0', 'OidbSvcTrpcTcp.0x6d7_1', 'OidbSvcTrpcTcp.0x6d7_2']);
|
||||
});
|
||||
|
||||
it('get*Url builds https://domain/path?rkey from the NTV2 response', async () => {
|
||||
const bridge = mockBridge();
|
||||
vi.mocked(oidb.runOidb).mockResolvedValue(
|
||||
bridge.sendRawPacket.mockResolvedValue(packResponse(
|
||||
protobuf_encode<OidbBase<NTV2RichMediaResp>>({
|
||||
body: {
|
||||
respHead: {},
|
||||
@@ -488,7 +439,7 @@ describe('actions/group-file', () => {
|
||||
} as any,
|
||||
} as any,
|
||||
}),
|
||||
);
|
||||
));
|
||||
const url = await new GroupFileApi(bridge as any).getVideoUrl(12345, { fileUuid: 'uuid' });
|
||||
expect(url).toBe('https://media.example.com/path/x?rkey=abc');
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user