feat(flash-transfer): QQ flash transfer (fileset) upload, share, download (#113)

* feat(proto-defs): add flash-transfer OIDB proto types

QQ 闪传(FlashTransfer / fileset)的 protobuf 类型定义:
- FlashFileEntry(0x93d2/0x93d3 文件条目)
- 0x93cf 申请 fileSet / 0x93d0 commit / 0x93db 完成 / 0x93d1 设状态
- 0x93d3 文件集详情 / 0x93d4 下载 URL(含主文件 fileId + 缩略图)
- 0x12a9 sub=100/103/200 prepare/apply/get-download
- sliceupload body + Sha1StateV
- 0x9407 删除 / 0x9427 重命名 / 0x93d7 发送
注册到 oidb-actions/index.ts,package.json 加 exports。

* feat(protocol): add flash-transfer OIDB services + sha1-stream

闪传协议层(OIDB namespace,复用 invokeOidb/OidbCallSpec):
- apply-fileset / commit-file / complete-fileset / set-status(上传流程)
- prepare-upload (0x12a9_100) / apply-upload (0x12a9_103)(sliceupload 凭证)
- get-fileset-detail (0x93d3) / list-filesets (0x93d2) / get-download-url (0x93d4)
- get-flash-download (0x12a9_200,主文件下载直链)
- delete-file (0x9407) / rename-file (0x9427,sub=0+uinForm) / send-flash (0x93d7)
- sha1-stream:SHA1 中间 state 计算器(sliceupload f107.f6 需要,Node crypto 不支持)
- byte-oracle 单测(apply/prepare/get-download-url/send-flash)+ sha1-stream 单测
package.json 加 exports。

* feat(core): add FlashTransferApi facade

FlashTransferApi 编排闪传全流程,复用 OIDB 基础设施(invokeOidb)+
computeHashes/loadBinarySource/fetch:
- createFlashTask:统一走 sub=100/103+sliceupload(含缩略图),不走小文件 PUT
  (PUT 不上报主文件 sha1,fileset 卡在未完成;QQ 客户端小文件也走 sliceupload)
- buildFileId:主文件 appid=14901(进 f14.f1),缩略图 png=14903/jpg=14902
- uploadThumbnail:随机纯色 PNG 占位(手写编码,不引入图像库),关联主文件下载入口
- getFilesetInfo/getFlashFileList/getShareLink/getFlashFileUrl/downloadFileset
- sendFlashMsg(私聊 uid / 群聊 groupId)/ getFilesetIdByCode(网页解析)
- deleteFlashFile / renameFlashFile / listFilesets
注册到 ApiHub(flashTransfer 字段)+ export。

* feat(onebot): add flash-transfer actions

OneBot action(extended.ts)10 个:
create_flash_task / get_fileset_info / get_flash_file_list /
get_flash_file_url / get_share_link / download_fileset /
send_flash_msg(私聊 user_id / 群聊 group_id)/ get_fileset_id /
rename_flash_file / delete_flash_file
MCP catalog(生成文件)同步新增 action 元数据。
extended-actions 接线单测覆盖。

* fix(onebot): align flash file list field name with NapCat

flashFileInfoToJson 的文件大小字段从 file_size 改为 size,对齐 NapCat
get_flash_file_list 响应(NapCat 用 size)。get_fileset_info 的 file_list
复用同一映射,一并生效。便于 NapCat 客户端 drop-in 迁移。

* feat(proto-defs): support multi-file commit in flash-transfer

0x93d0 commit 的 f4 改为 repeated,一个请求携带 fileset 内全部文件条目。
FlashCommitFileInfo 的 f3/f5/f6/f7/f10/f12 用 pb_optional,强制 0 值上 wire
(服务端多文件时严格校验字段存在,省略 0 会导致后续文件不计入 fileset)。

* feat(protocol): parameterize flash-transfer upload for multi-file

CommitFile.Params 改为 entries 数组,serialize 输出 repeated f4,每条 f6=文件序号。
PrepareUpload/ApplyUpload 加 fileIndex + formatCode 参数:filesetWrap.f4 用 fileIndex
(与 commit f6 对齐),f7 用 formatCode(mp4=2 非 26),f9=1。

* feat(core): multi-file flash-transfer upload

createFlashTask 支持多文件共用一个 fileset。关键改动:
- ApplyFileset 多文件时 fileName 用「<首文件名>等N个文件」、fileSize 用总和,
  服务端据此判定 fileset 为多文件,commit 的后续 entry 才被计入
- 一次性 CommitFile 提交所有文件元数据(f4 repeated)
- 两阶段上传:先全部 prepare+apply 注册 fileId,再全部 sliceupload 落盘
- 拆分原 uploadLargeFile 为 prepareAndApply + sliceuploadFile
- fileTypeCode mp4 formatCode 26→2(与 commit f7/filesetWrap.f7 一致)

* feat(onebot): multi-file create_flash_task + list_filesets action

create_flash_task 的 files 参数支持 string 或 string[],多文件共用一个 fileset。
新增 list_filesets action(facade.listFilesets 之前未暴露)。MCP catalog 同步更新
files schema(anyOf string/array)与 list_filesets 条目。

* fix(flash-transfer): multi-file download by fileIndex

0x93d4 响应 f1.f3 是 repeated fileInfo(多文件 fileset 每个文件一条,f6=序号、
f14=主文件 fileId),之前定义成单个导致多文件只能拿到第一个文件。
FlashDownloadEntry.fileInfo 改 pb_repeated,GetDownloadUrl 返回所有文件元信息,
download_fileset 按 fileIndex 选中目标文件走 0x12a9 sub=200 拿直链。

* test(protocol): inline byte-oracle hex fixtures

两个 flash-transfer byte-oracle 测试原先用 readFileSync 读仓库外的
.claude/reverse/scripts/proto/*.hex(本地逆向笔记目录),CI 上不存在导致失败。
把 hex 内容内联成常量,测试自包含。

* fix(flash-transfer): address review feedback

1. get_flash_file_url 接 file_index 参数并在 action 透传(之前漏接,多文件永远返回首文件)
2. getFileDownload 越界 fileIndex 不再静默回退首文件,找不到返回 null
3. postSliceupload status 缺失不再当成功,非 success 一律抛错
4. computeSha1StateV 改 O(n) 增量 update(之前每片 reset 重算整个前缀,O(n²))
5. get_flash_file_url 找不到文件抛错(之前返回空串当成功)
6. create_flash_task files 数组拒绝空字符串
This commit is contained in:
Qiao authored and GitHub committed 2026-06-21 14:24:51 +08:00
1 parent ebadfb968b
commit 127f2cd2d6
29 files changed
+3213 -20

No files matched your search

@@ -0,0 +1,112 @@
// 流式 SHA1 计算器,支持输出中间 state(不 finalize)。
// 闪传 sliceupload 的 f107.f6 (Sha1StateV) 需要每片对应的累积 SHA1 中间 state,
// Node.js 内置 crypto 只能算完整 digest,这里自行实现 transform 以暴露中间 state。
import { createHash } from 'node:crypto';
const SHA1_BLOCK_SIZE = 64;
const SHA1_DIGEST_SIZE = 20;
function rotl(x: number, n: number): number {
return ((x << n) | (x >>> (32 - n))) >>> 0;
}
export class Sha1Stream {
private readonly state = new Uint32Array(5);
private readonly count = new Uint32Array(2); // [low, high] bit count
private readonly buffer = new Uint8Array(SHA1_BLOCK_SIZE);
constructor() { this.reset(); }
reset(): void {
this.state[0] = 0x67452301;
this.state[1] = 0xEFCDAB89;
this.state[2] = 0x98BADCFE;
this.state[3] = 0x10325476;
this.state[4] = 0xC3D2E1F0;
this.count[0] = 0;
this.count[1] = 0;
}
private transform(data: Uint8Array, offset: number): void {
const w = new Uint32Array(80);
const dv = new DataView(data.buffer, data.byteOffset + offset, 64);
for (let i = 0; i < 16; i++) w[i] = dv.getUint32(i * 4, false); // big-endian
for (let i = 16; i < 80; i++) {
w[i] = rotl(w[i - 3] ^ w[i - 8] ^ w[i - 14] ^ w[i - 16], 1);
}
let a = this.state[0], b = this.state[1], c = this.state[2], d = this.state[3], e = this.state[4];
for (let i = 0; i < 80; i++) {
let temp: number;
if (i < 20) temp = ((b & c) | (~b & d)) + 0x5A827999;
else if (i < 40) temp = (b ^ c ^ d) + 0x6ED9EBA1;
else if (i < 60) temp = ((b & c) | (b & d) | (c & d)) + 0x8F1BBCDC;
else temp = (b ^ c ^ d) + 0xCA62C1D6;
temp = (temp + rotl(a, 5) + e + w[i]) >>> 0;
e = d; d = c; c = rotl(b, 30); b = a; a = temp;
}
this.state[0] = (this.state[0] + a) >>> 0;
this.state[1] = (this.state[1] + b) >>> 0;
this.state[2] = (this.state[2] + c) >>> 0;
this.state[3] = (this.state[3] + d) >>> 0;
this.state[4] = (this.state[4] + e) >>> 0;
}
update(data: Uint8Array): void {
const len = data.length;
let index = (this.count[0] >>> 3) & 0x3F;
this.count[0] = (this.count[0] + (len << 3)) >>> 0;
if (this.count[0] < (len << 3)) this.count[1] = (this.count[1] + 1) >>> 0;
this.count[1] = (this.count[1] + (len >>> 29)) >>> 0;
let partLen = SHA1_BLOCK_SIZE - index;
let i = 0;
if (len >= partLen) {
this.buffer.set(data.subarray(0, partLen), index);
this.transform(this.buffer, 0);
i = partLen;
while (i + SHA1_BLOCK_SIZE <= len) {
this.transform(data, i);
i += SHA1_BLOCK_SIZE;
}
index = 0;
}
this.buffer.set(data.subarray(i), index);
}
/** 输出当前 state(20B)。littleEndian=true 小端,false 大端。不 finalize。 */
hash(littleEndian: boolean): Uint8Array {
const digest = new Uint8Array(SHA1_DIGEST_SIZE);
const dv = new DataView(digest.buffer);
for (let i = 0; i < 5; i++) {
if (littleEndian) dv.setUint32(i * 4, this.state[i], true);
else dv.setUint32(i * 4, this.state[i], false);
}
return digest;
}
}
/**
* 计算闪传 sliceupload 的 Sha1StateV(累积 SHA1 state list)。
* states[i] = SHA1 中间 state(从初始 state 处理 file[0:(i+1)*sliceSize] 后,无 finalize,小端 20B)。
* 最后一片 states[last] = 标准整文件 SHA1(有 finalize)。
*
* 用单个 Sha1Stream 增量 update:每片只喂新增的 sliceSize 字节再快照,O(n)。
* (sliceSize=1MB 是 SHA1 块大小 64B 的整数倍,增量 update 不会残留半块。)
*/
export function computeSha1StateV(bytes: Uint8Array, sliceCount: number, sliceSize: number): Uint8Array[] {
const states: Uint8Array[] = [];
const sha1 = new Sha1Stream();
for (let i = 0; i < sliceCount; i++) {
const start = i * sliceSize;
const end = Math.min(start + sliceSize, bytes.length);
sha1.update(bytes.subarray(start, end));
if (i !== sliceCount - 1) {
states.push(sha1.hash(true)); // 小端中间 state,不 finalize
} else {
// 最后一片:标准整文件 SHA1(有 finalize)
states.push(new Uint8Array(createHash('sha1').update(Buffer.from(bytes)).digest()));
}
}
return states;
}
@@ -0,0 +1,66 @@
// OIDB 0x93cf_1 — 申请创建 fileSet(上传起点)。
// 请求 f1=1, f2=FileInfo{filename,origName,type=1,size,uploader}, f3=类型码, f12=1。
// 响应 f1=filesetUuid, f2=uploadKey(同f1), f3=上传URL(qfile.qq.com/q/<code>), f4=expire, f5=ttl。
// subCommand=1, reserved=0(真客户端 envelope 实测确认)。
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type {
FlashApplyFilesetReq,
FlashApplyFilesetResp,
} from '@snowluma/proto-defs/oidb-actions/flash-transfer';
import { invokeOidb, type OidbSender } from '../../oidb-service';
export interface FlashUploaderInfo {
uin: string;
nickname: string;
uid: string;
}
export namespace ApplyFileset {
export const command = 0x93cf;
export const subCommand = 1;
export interface Params {
fileName: string;
origName: string;
fileSize: number;
/** 文件类型码:rar=2, png/mp4=7。 */
typeCode: number;
uploader: FlashUploaderInfo;
}
export type Deps = OidbSender;
export const serialize = (_ctx: Deps, p: Params): FlashApplyFilesetReq => ({
field1: 1,
fileInfo: {
fileName: p.fileName,
origName: p.origName,
fileType: 1,
fileSize: BigInt(p.fileSize),
uploader: {
uin: p.uploader.uin,
nickname: p.uploader.nickname,
uid: p.uploader.uid,
field4: {},
},
field16: 1,
field20: 0,
field21: 0,
},
typeCode: p.typeCode,
field12: 1,
});
export const deserialize = (_ctx: Deps, body: FlashApplyFilesetResp): FlashApplyFilesetResp => body;
export const encode = (env: OidbBase<FlashApplyFilesetReq>): Uint8Array =>
protobuf_encode<OidbBase<FlashApplyFilesetReq>>(env);
export const decode = (bytes: Uint8Array): OidbBase<FlashApplyFilesetResp> =>
protobuf_decode<OidbBase<FlashApplyFilesetResp>>(bytes);
export const invoke = (deps: Deps, params: Params): Promise<FlashApplyFilesetResp> =>
invokeOidb(deps, ApplyFileset, params);
}
@@ -0,0 +1,98 @@
// OIDB 0x12a9_103 — apply-upload(注册 fileId,sliceupload 前调用)。
// uinForm=true。带 MD5 + 客户端构造的 fileId。响应无 rkey(rkey 来自 sub=100)。
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type {
FlashApplyUploadReq,
FlashApplyUploadResp,
} from '@snowluma/proto-defs/oidb-actions/flash-transfer';
import { invokeOidb, type OidbSender } from '../../oidb-service';
let seqCounter = 100;
export namespace ApplyUpload {
export const command = 0x12a9;
export const subCommand = 103;
export const uinForm = true;
export interface Params {
filesetUuid: string;
fileUuid: string;
fileId: string; // 来自 sub=100 响应
fileName: string;
fileSize: number;
md5: string; // 32 hex
sha1: string; // 40 hex
/** fileset 内序号(1,2,3...),与 0x93d0 commit f6 一致。 */
fileIndex: number;
/** 格式码:与 commit f7 一致(mp4=2, rar/zip=4)。主文件 filesetWrap.f7 用此值;
* 缩略图固定 png=26/jpg=2。 */
formatCode: number;
/** 缩略图类型:undefined=主文件, 'png'=png 缩略图, 'jpg'=jpg 缩略图。 */
thumbType?: 'png' | 'jpg';
width?: number;
height?: number;
}
export type Deps = OidbSender;
export const serialize = (_ctx: Deps, p: Params): FlashApplyUploadReq => {
// 缩略图与主文件字段差异:config.f103、FileInfo.f5.f1/f6/f7/f9、
// filesetWrap.f4/f5/f6/f7/f9。filesetWrap.f4 统一用 fileIndex。
const isThumb = p.thumbType !== undefined;
const isJpg = p.thumbType === 'jpg';
return {
head: {
sub: { seq: seqCounter++, sub: 103 },
config: { field101: 2, field102: 4, field103: isThumb ? (isJpg ? 24 : 23) : 22, field200: 5 },
field3: { field1: 1 },
},
payload: {
wrapper: {
fileInfo: {
fileSize: p.fileSize,
md5: p.md5,
sha1: p.sha1,
fileName: p.fileName,
field5: { field1: isJpg ? 1 : 0, field2: 0, field3: 0, field4: 0 },
field6: p.width ?? 0,
field7: p.height ?? 0,
field8: 0,
field9: isJpg ? 0 : 1,
},
fileId: p.fileId,
field3: 1,
field4: Math.floor(Date.now() / 1000),
field5: 1209600, // TTL 14 天
field6: 0,
},
flag2: { field1: 2 },
field3: { field1: 0, field2: 0, field3: 0, field4: {} },
filesetWrap: {
filesetUuid: p.filesetUuid,
uploadKey: p.filesetUuid,
fileUuid: p.fileUuid,
field4: p.fileIndex,
field5: isThumb && !isJpg ? 1 : 0, // png=1, jpg/mp4=0
field6: isThumb ? (isJpg ? 1 : 0) : 0, // png缩略图=0, jpg缩略图=1, 主文件=0
field7: isThumb ? (isJpg ? 2 : 26) : p.formatCode, // 主文件=formatCode(mp4=2), png缩略图=26, jpg缩略图=2
field8: {},
field9: 1, field10: 0, field11: 0, field12: 0, field13: 0, field14: 0,
},
},
};
};
export const deserialize = (_ctx: Deps, _body: FlashApplyUploadResp): void => {
// sub=103 resp f12={f1:filesetWrap}(注册确认,无 rkey)。rkey 来自 sub=100。
};
export const encode = (env: OidbBase<FlashApplyUploadReq>): Uint8Array =>
protobuf_encode<OidbBase<FlashApplyUploadReq>>(env);
export const decode = (bytes: Uint8Array): OidbBase<FlashApplyUploadResp> =>
protobuf_decode<OidbBase<FlashApplyUploadResp>>(bytes);
export const invoke = (deps: Deps, params: Params): Promise<void> =>
invokeOidb(deps, ApplyUpload, params);
}
@@ -0,0 +1,70 @@
// OIDB 0x93d0_1 — fileset 内所有文件的元数据上报(commit)。
// 多文件机制:f4 是 repeated,一个请求同时携带 fileset 内全部文件条目,
// 每条 f6=文件序号(1,2,3...),f7=formatCode。单文件时只有一个条目。
// 响应 f1=1(ack), f2/f3=filesetUuid。subCommand=1, reserved=0。
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type {
FlashCommitFileReq,
FlashCommitFileResp,
} from '@snowluma/proto-defs/oidb-actions/flash-transfer';
import { invokeOidb, type OidbSender } from '../../oidb-service';
export namespace CommitFile {
export const command = 0x93d0;
export const subCommand = 1;
/** 单个文件的 commit 元数据。fileIndex 为 fileset 内序号(从 1 递增)。 */
export interface CommitEntry {
fileUuid: string;
fileName: string;
origName: string;
fileSize: number;
/** 格式码:rar=4, mp4=2。 */
formatCode: number;
/** fileset 内序号(1,2,3...),与 0x12a9 filesetWrap.f4 一致。 */
fileIndex: number;
}
export interface Params {
filesetUuid: string;
/** fileset 内全部文件条目;一次 0x93d0 请求同时上报。 */
entries: CommitEntry[];
}
export type Deps = OidbSender;
export const serialize = (_ctx: Deps, p: Params): FlashCommitFileReq => ({
field1: 1,
filesetUuid: p.filesetUuid,
uploadKey: p.filesetUuid,
commitInfo: p.entries.map((e) => ({
filesetUuid: p.filesetUuid,
fileUuid: e.fileUuid,
field3: 0,
field4: {},
field5: 1,
field6: e.fileIndex,
formatCode: e.formatCode,
fileName: e.fileName,
origName: e.origName,
field10: 0,
fileSize: BigInt(e.fileSize),
field12: 0,
field24: {},
})),
field5: 1,
field6: 1,
});
export const deserialize = (_ctx: Deps, body: FlashCommitFileResp): FlashCommitFileResp => body;
export const encode = (env: OidbBase<FlashCommitFileReq>): Uint8Array =>
protobuf_encode<OidbBase<FlashCommitFileReq>>(env);
export const decode = (bytes: Uint8Array): OidbBase<FlashCommitFileResp> =>
protobuf_decode<OidbBase<FlashCommitFileResp>>(bytes);
export const invoke = (deps: Deps, params: Params): Promise<FlashCommitFileResp> =>
invokeOidb(deps, CommitFile, params);
}
@@ -0,0 +1,38 @@
// OIDB 0x93db_1 — fileSet 完成。请求 f1=filesetUuid, f2=""。响应 ack。sub=1, reserved=0。
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type {
FlashCompleteFilesetReq,
FlashCompleteFilesetResp,
} from '@snowluma/proto-defs/oidb-actions/flash-transfer';
import { invokeOidb, type OidbSender } from '../../oidb-service';
export namespace CompleteFileset {
export const command = 0x93db;
export const subCommand = 1;
export interface Params {
filesetUuid: string;
}
export type Deps = OidbSender;
export const serialize = (_ctx: Deps, p: Params): FlashCompleteFilesetReq => ({
filesetUuid: p.filesetUuid,
field2: '',
});
export const deserialize = (_ctx: Deps, _body: FlashCompleteFilesetResp): void => {
// 成功靠 envelope errorCode=0。
};
export const encode = (env: OidbBase<FlashCompleteFilesetReq>): Uint8Array =>
protobuf_encode<OidbBase<FlashCompleteFilesetReq>>(env);
export const decode = (bytes: Uint8Array): OidbBase<FlashCompleteFilesetResp> =>
protobuf_decode<OidbBase<FlashCompleteFilesetResp>>(bytes);
export const invoke = (deps: Deps, params: Params): Promise<void> =>
invokeOidb(deps, CompleteFileset, params);
}
@@ -0,0 +1,40 @@
// OIDB 0x9407_1 — 删除闪传文件(OneBot 标准未定义,QQ 面板有此操作)。
// 请求 f1=filesetUuid, f2="", f3=7。响应短 ack(envelope errorCode=0 即成功)。
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type {
FlashDeleteFileReq,
FlashDeleteFileResp,
} from '@snowluma/proto-defs/oidb-actions/flash-transfer';
import { invokeOidb, type OidbSender } from '../../oidb-service';
export namespace DeleteFlashFile {
export const command = 0x9407;
export const subCommand = 1;
export interface Params {
filesetUuid: string;
}
export type Deps = OidbSender;
export const serialize = (_ctx: Deps, p: Params): FlashDeleteFileReq => ({
filesetUuid: p.filesetUuid,
field2: '',
field3: 7,
});
export const deserialize = (_ctx: Deps, _body: FlashDeleteFileResp): void => {
// 成功靠 envelope errorCode=0(invokeOidb 已校验),业务体空。
};
export const encode = (env: OidbBase<FlashDeleteFileReq>): Uint8Array =>
protobuf_encode<OidbBase<FlashDeleteFileReq>>(env);
export const decode = (bytes: Uint8Array): OidbBase<FlashDeleteFileResp> =>
protobuf_decode<OidbBase<FlashDeleteFileResp>>(bytes);
export const invoke = (deps: Deps, params: Params): Promise<void> =>
invokeOidb(deps, DeleteFlashFile, params);
}
@@ -0,0 +1,78 @@
// OIDB 0x93d4_1 — 拉取下载URL(完整参数 + fldc)。
// 响应下载URL: multimedia.qfile.qq.com/download?appid=14902&client_type=win
// &client_ver=...&fileid=...&fldc=...(无 rkey,用 fldc)。
// 响应结构与 0x93d3 不同:downloadUrl 在 f1.f3.f13.f2.f2(非 f9.fileIdWrap)。
// 用于 get_flash_file_url / download_fileset 的完整链接变体。
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type {
FlashGetDownloadUrlReq,
FlashGetDownloadUrlResp,
} from '@snowluma/proto-defs/oidb-actions/flash-transfer';
import { invokeOidb, type OidbSender } from '../../oidb-service';
export namespace GetDownloadUrl {
export const command = 0x93d4;
export const subCommand = 1;
export interface Params {
filesetUuid: string;
/** 指定下载 fileset 内第几个文件(1-based)。默认 1(主文件)。 */
fileIndex?: number;
}
/** 单个文件的下载元信息;无主文件 fileId 时该条目 null。 */
export type FileMeta = {
fileIndex: number;
fileId: string;
filesetUuid: string;
fileUuid: string;
fileName: string;
fileSize: number;
};
/** fileset 内所有文件元信息(按 fileIndex 升序)。 */
export type Result = FileMeta[];
export type Deps = OidbSender;
export const serialize = (_ctx: Deps, p: Params): FlashGetDownloadUrlReq => ({
filesetUuid: p.filesetUuid,
inner: {
field1: '',
field2: 1,
field3: 18,
field4: '',
field5: { field1: 0 },
field6: { field1: 0, field2: 0 },
},
field3: 7,
field4: 1,
});
export const deserialize = (_ctx: Deps, body: FlashGetDownloadUrlResp): Result => {
// f1.f3 是 repeated fileInfo,多文件 fileset 时每个文件一条(f6=序号,f14=主文件 fileId)。
// f13 是缩略图(appid=14902),主文件下载 URL 需 0x12a9 sub=200 拿。
const infos = body.entry?.fileInfo ?? [];
return infos.map((info, idx) => {
const fileId = info?.mainFile?.fileId ?? '';
const fileIndex = info?.field6 ?? idx + 1;
return {
fileIndex,
fileId,
filesetUuid: info?.filesetUuid ?? '',
fileUuid: info?.fileUuid ?? '',
fileName: info?.fileName ?? '',
fileSize: Number(info?.fileSize ?? 0),
};
});
};
export const encode = (env: OidbBase<FlashGetDownloadUrlReq>): Uint8Array =>
protobuf_encode<OidbBase<FlashGetDownloadUrlReq>>(env);
export const decode = (bytes: Uint8Array): OidbBase<FlashGetDownloadUrlResp> =>
protobuf_decode<OidbBase<FlashGetDownloadUrlResp>>(bytes);
export const invoke = (deps: Deps, params: Params): Promise<Result> =>
invokeOidb(deps, GetDownloadUrl, params);
}
@@ -0,0 +1,42 @@
// OIDB 0x93d3_1 — 拉取文件集详情(点"分享"显示链接时触发)。
// 请求 f1=filesetUuid, f2=7。响应 f1=repeated FlashFileEntry(含文件名/大小/
// 上传分享URL qfile.qq.com/q/<code> / fileId / 下载URL,URL 里已含 rkey)。
// 用于 get_fileset_info / get_flash_file_list / get_flash_file_url / get_share_link。
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type {
FlashGetDetailReq,
FlashGetDetailResp,
FlashFileEntry,
} from '@snowluma/proto-defs/oidb-actions/flash-transfer';
import { invokeOidb, type OidbSender } from '../../oidb-service';
export namespace GetFilesetDetail {
export const command = 0x93d3;
export const subCommand = 1;
export interface Params {
filesetUuid: string;
}
export type Result = FlashFileEntry[];
export type Deps = OidbSender;
export const serialize = (_ctx: Deps, p: Params): FlashGetDetailReq => ({
filesetUuid: p.filesetUuid,
field2: 7,
});
export const deserialize = (_ctx: Deps, body: FlashGetDetailResp): Result =>
body.entries ?? [];
export const encode = (env: OidbBase<FlashGetDetailReq>): Uint8Array =>
protobuf_encode<OidbBase<FlashGetDetailReq>>(env);
export const decode = (bytes: Uint8Array): OidbBase<FlashGetDetailResp> =>
protobuf_decode<OidbBase<FlashGetDetailResp>>(bytes);
export const invoke = (deps: Deps, params: Params): Promise<Result> =>
invokeOidb(deps, GetFilesetDetail, params);
}
@@ -0,0 +1,82 @@
// OIDB 0x12a9_200 — get-download(拿主文件下载直链)。
// 请求 payload @ f3(不同于 sub=100 的 f2 / sub=103 的 f12)。响应 f3 含 host + path
// (主文件下载 URL,appid=14901 + 主文件fileId + fldc + rkey)。
// 主文件 fileId 来自 0x93d4 f14.f1。0x93d3/0x93d4 的 downloadUrl 是缩略图(appid=14903/14902),
// 主文件下载 URL 必须走 sub=200。
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type {
FlashGetDownloadReq,
FlashGetDownloadResp,
} from '@snowluma/proto-defs/oidb-actions/flash-transfer';
import { invokeOidb, type OidbSender } from '../../oidb-service';
let seqCounter = 300;
export namespace GetFlashDownload {
export const command = 0x12a9;
export const subCommand = 200;
export const uinForm = true;
export interface Params {
filesetUuid: string;
fileUuid: string; // 主文件 fileUuid(0x93d4 f1.f3.f2)
fileId: string; // 主文件 fileId(0x93d4 f14.f1)
fileName: string;
}
export type Result = string | null; // 主文件下载 URL
export type Deps = OidbSender;
export const serialize = (_ctx: Deps, p: Params): FlashGetDownloadReq => ({
head: {
sub: { seq: seqCounter++, sub: 200 },
config: { field101: 2, field102: 4, field103: 22, field200: 5 }, // mp4 f103=22
field3: { field1: 1 },
},
payload: {
wrapper: {
fileInfo: {
field1: 0,
field4: p.fileName,
field5: { field1: 0, field2: 0, field3: 0, field4: 0 },
field6: 0, field7: 0, field8: 0, field9: 0,
},
fileId: p.fileId,
field3: 0, field4: 0, field5: 0, field6: 0,
},
field2: {
// 固定下载参数(QQ 客户端实测值,未观察到随文件变化)。
field2: { field1: 4294967294, field3: 4294967295, field5: 111, field6: { field1: 3403722988 } },
field4: { field1: 0 },
// field3 必须是主文件类型码 26;用 2 会被服务端拒(170019002 Service Failure)。
filesetWrap: { filesetUuid: p.filesetUuid, fileUuid: p.fileUuid, field3: 26, field4: p.fileUuid },
},
field3: 0,
},
});
export const deserialize = (_ctx: Deps, body: FlashGetDownloadResp): Result => {
// 响应 f3 含 rkey + host(multimedia.qfile.qq.com)+ path(/download?appid=14901...&fldc=...)。
// rkey 在 f3 单独字段(path 不含 rkey),拼完整 URL 需拼接 &rkey=。
const raw = body.body;
if (!raw || raw.length === 0) return null;
const text = Buffer.from(raw).toString('latin1');
const host = /multimedia\.qfile\.qq\.com/.exec(text);
const path = /\/download\?appid=14901[\x20-\x7e]*/.exec(text);
const rkey = /rkey=([A-Za-z0-9_-]+)/.exec(text);
if (!host || !path) return null;
const base = `https://${host[0]}${path[0]}`;
return rkey ? `${base}&${rkey[0]}` : base;
};
export const encode = (env: OidbBase<FlashGetDownloadReq>): Uint8Array =>
protobuf_encode<OidbBase<FlashGetDownloadReq>>(env);
export const decode = (bytes: Uint8Array): OidbBase<FlashGetDownloadResp> =>
protobuf_decode<OidbBase<FlashGetDownloadResp>>(bytes);
export const invoke = (deps: Deps, params: Params): Promise<Result> =>
invokeOidb(deps, GetFlashDownload, params);
}
@@ -0,0 +1,42 @@
// OIDB 0x93d2_1 — 查询 fileset 列表(全部 fileset,无 UUID 入参)。
// 请求 f1=3, f2="", f3=10。响应 f1=repeated FlashFileEntry。
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type {
FlashListFilesetsReq,
FlashListFilesetsResp,
FlashFileEntry,
} from '@snowluma/proto-defs/oidb-actions/flash-transfer';
import { invokeOidb, type OidbSender } from '../../oidb-service';
export namespace ListFilesets {
export const command = 0x93d2;
export const subCommand = 1;
export interface Params {
field1?: number; // 默认 3
field3?: number; // 默认 10
}
export type Result = FlashFileEntry[];
export type Deps = OidbSender;
export const serialize = (_ctx: Deps, p: Params): FlashListFilesetsReq => ({
field1: p.field1 ?? 3,
field2: '',
field3: p.field3 ?? 10,
});
export const deserialize = (_ctx: Deps, body: FlashListFilesetsResp): Result =>
body.entries ?? [];
export const encode = (env: OidbBase<FlashListFilesetsReq>): Uint8Array =>
protobuf_encode<OidbBase<FlashListFilesetsReq>>(env);
export const decode = (bytes: Uint8Array): OidbBase<FlashListFilesetsResp> =>
protobuf_decode<OidbBase<FlashListFilesetsResp>>(bytes);
export const invoke = (deps: Deps, params: Params = {}): Promise<Result> =>
invokeOidb(deps, ListFilesets, params);
}
@@ -0,0 +1,103 @@
// OIDB 0x12a9_100 — prepare-upload(大文件分片上传前申请 sliceupload rkey)。
// sub=100,uinForm=true。sub=100 的 payload 在 f2(sub=103 在 f12),结构完全不同。
// 响应 f2.f1 是 sliceupload rkey;秒传(文件已在服务端)时 f1 缺失,deserialize 返回 null。
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type {
FlashPrepareUploadReq,
FlashPrepareUploadResp,
} from '@snowluma/proto-defs/oidb-actions/flash-transfer';
import { invokeOidb, type OidbSender } from '../../oidb-service';
let seqCounter = 200;
export namespace PrepareUpload {
export const command = 0x12a9;
export const subCommand = 100;
export const uinForm = true;
export interface Params {
filesetUuid: string;
fileUuid: string;
fileName: string;
fileSize: number;
sha1: string; // 40 hex
/** fileset 内序号(1,2,3...),与 0x93d0 commit f6 一致。缩略图序号在主文件之后递增。 */
fileIndex: number;
/** 格式码:与 commit f7 一致(mp4=2, rar/zip=4)。主文件 filesetWrap.f7 用此值;
* 缩略图固定 png=26/jpg=2。 */
formatCode: number;
/** 缩略图类型:undefined=主文件, 'png'=png 缩略图, 'jpg'=jpg 缩略图。
* 主文件下载入口需要缩略图关联才会被服务端填充,缩略图字段差异据此切换。 */
thumbType?: 'png' | 'jpg';
width?: number; // 缩略图宽(主文件=0)
height?: number; // 缩略图高(主文件=0)
}
export type Deps = OidbSender;
export const serialize = (_ctx: Deps, p: Params): FlashPrepareUploadReq => {
// 缩略图与主文件字段差异:config.f103、FileInfo.f5.f1/f6/f7/f9、filesetWrap.f6/f7。
// filesetWrap.f4 统一用 fileIndex(主文件和缩略图都从 facade 传入,保证与 commit f6 一致)。
const isThumb = p.thumbType !== undefined;
const isJpg = p.thumbType === 'jpg';
return {
head: {
sub: { seq: seqCounter++, sub: 100 },
config: { field101: 2, field102: 4, field103: isThumb ? (isJpg ? 24 : 23) : 22, field200: 5 },
field3: { field1: 1 },
},
payload: {
wrapper: {
fileInfo: {
fileSize: p.fileSize,
md5: '', // sub=100 不带 MD5
sha1: p.sha1,
fileName: p.fileName,
field5: { field1: isJpg ? 1 : 0, field2: 0, field3: 0, field4: 0 },
field6: p.width ?? 0,
field7: p.height ?? 0,
field8: 0,
field9: isJpg ? 0 : 1,
},
field2: 0, // wrapper.f2=0(varint,不是 fileId)
},
field2: 1,
field3: 0,
field4: 0,
field5: 0,
field6: {
field1: { field1: 0, field2: {} },
field2: { field3: {} },
field3: { field11: {}, field12: {} },
field10: 0,
},
field7: 0,
field8: 0,
filesetWrap: {
filesetUuid: p.filesetUuid,
uploadKey: p.filesetUuid,
fileUuid: p.fileUuid,
field4: p.fileIndex,
field5: 0,
field6: isThumb ? 1 : 0, // 缩略图=1, 主文件=0
field7: isThumb ? (isJpg ? 2 : 26) : p.formatCode, // 主文件=formatCode(mp4=2), png缩略图=26, jpg缩略图=2
field8: {},
field9: 1, field10: 0, field11: 0, field12: 0, field13: 0, field14: 0,
},
},
};
};
export const deserialize = (_ctx: Deps, body: FlashPrepareUploadResp): string | null => {
// sub-100 resp f2={f1:rkey}(正常上传,CAES/CAIS/CAQS/CAMS)。
// 秒传(文件已在服务端)时 f2 无 f1(rkey),返回 null,调用方跳过 sliceupload。
return body.rkeyWrap?.rkey ?? null;
};
export const encode = (env: OidbBase<FlashPrepareUploadReq>): Uint8Array =>
protobuf_encode<OidbBase<FlashPrepareUploadReq>>(env);
export const decode = (bytes: Uint8Array): OidbBase<FlashPrepareUploadResp> =>
protobuf_decode<OidbBase<FlashPrepareUploadResp>>(bytes);
export const invoke = (deps: Deps, params: Params): Promise<string | null> =>
invokeOidb(deps, PrepareUpload, params);
}
@@ -0,0 +1,45 @@
// OIDB 0x9427_0 — 重命名闪传文件(OneBot 标准未定义,QQ 面板有此操作)。
// 请求 f1=filesetUuid, f2={f1=新文件名, f2=显示名}, f3={f1=0}。
// 注意 envelope 与其他闪传 cmd 不同:subCommand=0(不是 1)+ uinForm=true(reserved=1)。
// 不能按 0x93cf_1 类推,用 sub=1 会被服务端拒(no privilege)。
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type {
FlashRenameFileReq,
FlashRenameFileResp,
} from '@snowluma/proto-defs/oidb-actions/flash-transfer';
import { invokeOidb, type OidbSender } from '../../oidb-service';
export namespace RenameFlashFile {
export const command = 0x9427;
export const subCommand = 0;
export const uinForm = true;
export interface Params {
filesetUuid: string;
/** 新文件名(同时用作显示名,与 QQ 面板行为一致)。 */
newName: string;
}
export type Deps = OidbSender;
export const serialize = (_ctx: Deps, p: Params): FlashRenameFileReq => ({
filesetUuid: p.filesetUuid,
name: { newName: p.newName, displayName: p.newName },
flag: { field1: 0 },
});
export const deserialize = (_ctx: Deps, _body: FlashRenameFileResp): void => {
// 成功靠 envelope errorCode=0。
};
export const encode = (env: OidbBase<FlashRenameFileReq>): Uint8Array =>
protobuf_encode<OidbBase<FlashRenameFileReq>>(env);
export const decode = (bytes: Uint8Array): OidbBase<FlashRenameFileResp> =>
protobuf_decode<OidbBase<FlashRenameFileResp>>(bytes);
export const invoke = (deps: Deps, params: Params): Promise<void> =>
invokeOidb(deps, RenameFlashFile, params);
}
@@ -0,0 +1,52 @@
// OIDB 0x93d7_1 — 发送闪传文件给用户(send_flash_msg)。
// 请求 f1={f1:1, f2:{f1:targetUid}}, f2=filesetUuid。响应仅回显目标 uid(无 message_id)。
// 0x93d7 是「分享 fileset 给用户」(对端通过 fileset 链接下载),非传统消息。
// envelope 用 0x93xx 默认的 sub=1/reserved=0,实测通过。
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type {
FlashSendReq,
FlashSendResp,
} from '@snowluma/proto-defs/oidb-actions/flash-transfer';
import { invokeOidb, type OidbSender } from '../../oidb-service';
export namespace SendFlashMsg {
export const command = 0x93d7;
export const subCommand = 1;
export interface Params {
targetUid?: string; // 私聊(与 groupId 二选一)
groupId?: number; // 群聊
filesetUuid: string;
}
export type Deps = OidbSender;
export const serialize = (_ctx: Deps, p: Params): FlashSendReq => {
// 群聊:f1={f1:2, f3:{f1:groupId}}(groupId 直接用群号,无需转 uid)。
if (p.groupId !== undefined) {
return {
target: { field1: 2, targetGroup: { groupId: p.groupId } },
filesetUuid: p.filesetUuid,
};
}
// 私聊:f1={f1:1, f2:{f1:targetUid}}。
return {
target: { field1: 1, targetUid: { targetUid: p.targetUid! } },
filesetUuid: p.filesetUuid,
};
};
export const deserialize = (_ctx: Deps, _body: FlashSendResp): void => {
// 响应仅回显目标 uid,无 message_id。
};
export const encode = (env: OidbBase<FlashSendReq>): Uint8Array =>
protobuf_encode<OidbBase<FlashSendReq>>(env);
export const decode = (bytes: Uint8Array): OidbBase<FlashSendResp> =>
protobuf_decode<OidbBase<FlashSendResp>>(bytes);
export const invoke = (deps: Deps, params: Params): Promise<void> =>
invokeOidb(deps, SendFlashMsg, params);
}
@@ -0,0 +1,39 @@
// OIDB 0x93d1_1 — 设置 fileSet 状态。请求 f1=filesetUuid, f2=6(状态码)。响应 ack。sub=1, reserved=0。
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type {
FlashSetStatusReq,
FlashSetStatusResp,
} from '@snowluma/proto-defs/oidb-actions/flash-transfer';
import { invokeOidb, type OidbSender } from '../../oidb-service';
export namespace SetFilesetStatus {
export const command = 0x93d1;
export const subCommand = 1;
export interface Params {
filesetUuid: string;
status?: number; // 默认 6
}
export type Deps = OidbSender;
export const serialize = (_ctx: Deps, p: Params): FlashSetStatusReq => ({
filesetUuid: p.filesetUuid,
status: p.status ?? 6,
});
export const deserialize = (_ctx: Deps, _body: FlashSetStatusResp): void => {
// 成功靠 envelope errorCode=0。
};
export const encode = (env: OidbBase<FlashSetStatusReq>): Uint8Array =>
protobuf_encode<OidbBase<FlashSetStatusReq>>(env);
export const decode = (bytes: Uint8Array): OidbBase<FlashSetStatusResp> =>
protobuf_decode<OidbBase<FlashSetStatusResp>>(bytes);
export const invoke = (deps: Deps, params: Params): Promise<void> =>
invokeOidb(deps, SetFilesetStatus, params);
}