refactor(packages): rename @snowluma/bridge → @snowluma/protocol
The package previously named "bridge" houses the protocol-byte layer (OIDB cmds, msg-push decoders, highway uploaders, element-builder, event bus). The name "bridge" suggested transport/lifecycle, which it isn't — that role lives in core/hook and core/bridge/manager. Rename to match what's actually inside. This is a pure rename: zero logic changes, all 73 import sites updated mechanically and TS-verified. core/onebot dependencies key updated. ESLint override path adjusted for the moved oidb-services directory. Rename detection threshold: git log --find-renames=20% recommended when following history across this commit — content-replacement (@snowluma/bridge → @snowluma/protocol) dropped per-file similarity below git's default 50% on import-heavy files.
This commit is contained in:
238 files changed
+247
-284
No files matched your search
@@ -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 = (_ctx: Deps, p: Params): OidbGroupFileFolderReq => ({
|
||||
create: {
|
||||
groupUin: p.groupId,
|
||||
rootDirectory: p.parentId,
|
||||
folderName: p.folderName,
|
||||
},
|
||||
});
|
||||
|
||||
export const deserialize = (_ctx: Deps, 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 = (_ctx: Deps, p: Params): OidbGroupFileReq => ({
|
||||
delete: {
|
||||
groupUin: p.groupId,
|
||||
busId: 102,
|
||||
fileId: p.fileId,
|
||||
},
|
||||
});
|
||||
|
||||
export const deserialize = (_ctx: Deps, 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 = (_ctx: Deps, p: Params): OidbGroupFileFolderReq => ({
|
||||
delete: { groupUin: p.groupId, folderId: p.folderId },
|
||||
});
|
||||
|
||||
export const deserialize = (_ctx: Deps, 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 = (_ctx: Deps, p: Params): OidbGroupFileCountViewReq => ({
|
||||
count: { groupUin: p.groupId, appId: 7, busId: 0 },
|
||||
});
|
||||
|
||||
export const deserialize = (_ctx: Deps, 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 = (_ctx: Deps, p: Params): OidbGroupFileReq => ({
|
||||
download: {
|
||||
groupUin: p.groupId,
|
||||
appId: 7,
|
||||
busId: p.busId,
|
||||
fileId: p.fileId,
|
||||
},
|
||||
});
|
||||
|
||||
export const deserialize = (_ctx: Deps, 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 = (_ctx: Deps, 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 = (_ctx: Deps, body: NTV2RichMediaResp): string => parseNtv2DownloadUrl(body);
|
||||
|
||||
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 = (_ctx: Deps, 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 = (_ctx: Deps, body: NTV2RichMediaResp): string => parseNtv2DownloadUrl(body);
|
||||
|
||||
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 = (_ctx: Deps, 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 = (_ctx: Deps, 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 = (_ctx: Deps, 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 = (_ctx: Deps, body: NTV2RichMediaResp): string => parseNtv2DownloadUrl(body);
|
||||
|
||||
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 = (_ctx: Deps, 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 = (_ctx: Deps, body: NTV2RichMediaResp): string => parseNtv2DownloadUrl(body);
|
||||
|
||||
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 = (_ctx: Deps, 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 = (_ctx: Deps, 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 = (_ctx: Deps, p: Params): OidbGroupFileReq => ({
|
||||
move: {
|
||||
groupUin: p.groupId,
|
||||
appId: 7,
|
||||
busId: 102,
|
||||
fileId: p.fileId,
|
||||
parentDirectory: p.parentDirectory,
|
||||
targetDirectory: p.targetDirectory,
|
||||
},
|
||||
});
|
||||
|
||||
export const deserialize = (_ctx: Deps, 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 = (_ctx: Deps, 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 = (_ctx: Deps, _: 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 = (_ctx: Deps, p: Params): OidbGroupFileFolderReq => ({
|
||||
rename: {
|
||||
groupUin: p.groupId,
|
||||
folderId: p.folderId,
|
||||
newFolderName: p.newFolderName,
|
||||
},
|
||||
});
|
||||
|
||||
export const deserialize = (_ctx: Deps, 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 = (_ctx: Deps, 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 = (_ctx: Deps, 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 = (_ctx: Deps, 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 = (_ctx: Deps, 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);
|
||||
}
|
||||
Reference in new issue
Block a user