feat(protocol): complete system face catalog lifecycle

Persist and validate the shared system face catalog, refresh it once when the first account connects, and coalesce concurrent loads. Resolve outgoing face metadata from the catalog so startup races, unknown IDs, and incomplete entries fail before sending.
This commit is contained in:
DrSmoothl committed 2026-08-04 23:13:32 +08:00
1 parent 938975dd45
commit 8e9a4d878e
11 files changed
+776 -65

No files matched your search

+40
View File
@@ -0,0 +1,40 @@
import path from 'node:path';
import { createLogger } from '@snowluma/common/logger';
import {
SysFaceStore,
sysFaceStore,
type SysFaceCatalogStorage,
} from '@snowluma/protocol/sys-face-store';
import { JsonSysFaceCatalogStorage } from '@snowluma/protocol/sys-face-storage';
import type { BridgeManager } from './bridge/manager';
const log = createLogger('SysFace');
export interface SystemFaceCatalogBindingOptions {
store?: SysFaceStore;
storage?: SysFaceCatalogStorage;
dataRoot?: string;
}
/** Attach the shared system-face catalog to Bridge login edges. The first
* account restores + refreshes it; later accounts reuse the same result. */
export function bindSystemFaceCatalog(
manager: BridgeManager,
options: SystemFaceCatalogBindingOptions = {},
): void {
const store = options.store ?? sysFaceStore;
const storage = options.storage ?? new JsonSysFaceCatalogStorage(
path.join(options.dataRoot ?? 'data', 'sys-face-catalog.json'),
);
store.configureStorage(storage);
manager.addSessionStartedListener((uin, bridge) => {
void store.prewarm(bridge).catch((error) => {
log.error(
'system face catalog login prewarm failed: uin=%s error=%s',
uin,
error instanceof Error ? (error.stack ?? error.message) : String(error),
);
});
});
}