Files
SnowLuma/packages/protocol/src/oidb-services/group-file/finalize-offline-file.ts
T
DrSmoothl 5d39cf5782 fix(core): finalize c2c file upload so the recipient can download (#157)
Private (c2c) file sends uploaded the bytes (apply 0xE37_1700 + Highway)
and PbSendMsg returned ok, but the receiver saw "文件传输失败": the message
carried only FileExtra.file (metadata) and not the server-issued download
routing. Group files use a different element, hence c2c-only.

Port NapCat's upload→finalize→send sequence:
- add 0xE37_800 (FinalizeOfflineFile) OIDB service, run after the Highway
  PUT to fetch the download metadata (field30)
- extend FileExtra with field6 (PrivateFileExtra.field2) and populate it
  from that metadata in sendC2cFile; covers both the url-upload and the
  file_id-resend send paths (both funnel through sendC2cFile)

Tests: byte-oracle locks the 0xE37_800 request + FileExtra.field6 tags;
core routing test now asserts finalize runs and field6 is populated.
Needs real-machine verification (send a private file, confirm download).
2026-06-28 20:11:17 +08:00

61 lines
2.1 KiB
TypeScript

// 0xE37_800 — c2c (private) offline-file finalize.
//
// Runs AFTER the Highway PUT for a private file. The apply (0xE37_1700)
// + Highway upload get the bytes onto the server, but the recipient
// can't download the file until this call returns the server-issued
// download routing (metadata). Those fields ride along in the outgoing
// PbSendMsg as `FileExtra.field6` — without them the receiver's client
// shows "文件传输失败" even though PbSendMsg returned ok.
//
// NapCat runs this unconditionally (even when the apply reports the file
// already exists). Ported from NapCat `highway/DownloadOfflineFile`.
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type {
OidbOfflineFileFinalizeReq,
OidbOfflineFileFinalizeResp,
OidbOfflineFileMetadata,
} from '@snowluma/proto-defs/oidb-actions/media';
import { invokeOidb, type OidbSender } from '../../oidb-service';
export namespace FinalizeOfflineFile {
export const command = 0xE37;
export const subCommand = 800;
export interface Params {
senderUid: string;
receiverUid: string;
fileUuid: string;
fileHash: string;
}
export type Deps = OidbSender;
export const serialize = (_ctx: Deps, p: Params): OidbOfflineFileFinalizeReq => ({
subCommand: 800,
field2: 0,
body: {
senderUid: p.senderUid,
receiverUid: p.receiverUid,
fileUuid: p.fileUuid,
fileHash: p.fileHash,
},
field101: 3,
field102: 1,
field200: 1,
});
export const deserialize = (_ctx: Deps, body: OidbOfflineFileFinalizeResp): OidbOfflineFileMetadata =>
body.body?.metadata ?? {};
export const encode = (env: OidbBase<OidbOfflineFileFinalizeReq>): Uint8Array =>
protobuf_encode<OidbBase<OidbOfflineFileFinalizeReq>>(env);
export const decode = (bytes: Uint8Array): OidbBase<OidbOfflineFileFinalizeResp> =>
protobuf_decode<OidbBase<OidbOfflineFileFinalizeResp>>(bytes);
export const invoke = (deps: Deps, params: Params): Promise<OidbOfflineFileMetadata> =>
invokeOidb(deps, FinalizeOfflineFile, params);
}