refactor(protocol): compose group-file URLs in the OIDB namespaces

Move retCode checks and URL assembly into GetGroupFileUrl,
GetPrivateFileUrl, and ListGroupFilesPage so GroupFileApi only
loops pages and resolves display names.
This commit is contained in:
DrSmoothl committed 2026-08-16 21:56:21 +08:00
1 parent 3fc521fb8b
commit 55a2a24fc2
9 files changed
+104 -82

No files matched your search

@@ -1,7 +1,7 @@
// 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.
// requires (Lagrange has the same constant). This namespace owns the
// `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.
@@ -10,9 +10,9 @@ 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';
import { toInt } from '../shared';
const TIMEOUT_MS = 5000;
@@ -39,10 +39,16 @@ export namespace GetPrivateFileUrl {
field99999: new Uint8Array([0xC0, 0x85, 0x2C, 0x01]),
});
export const deserialize = (_ctx: Deps, body: OidbPrivateFileDownloadResp): OidbPrivateFileDownloadRespResult => {
export const deserialize = (_ctx: Deps, body: OidbPrivateFileDownloadResp): string => {
const result = body.body?.result;
if (!result) throw new Error('private file url response invalid');
return result;
const server = typeof result.server === 'string' ? result.server : '';
const port = toInt(result.port);
const url = typeof result.url === 'string' ? result.url : '';
if (!server || !port || !url) {
throw new Error('private file url response invalid');
}
return `http://${server}:${port}${url}&isthumb=0`;
};
export const encode = (env: OidbBase<OidbPrivateFileDownloadReq>): Uint8Array =>
@@ -51,6 +57,6 @@ export namespace GetPrivateFileUrl {
export const decode = (bytes: Uint8Array): OidbBase<OidbPrivateFileDownloadResp> =>
protobuf_decode<OidbBase<OidbPrivateFileDownloadResp>>(bytes);
export const invoke = (deps: Deps, params: Params): Promise<OidbPrivateFileDownloadRespResult> =>
export const invoke = (deps: Deps, params: Params): Promise<string> =>
invokeOidb(deps, GetPrivateFileUrl, params, TIMEOUT_MS);
}