mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 16:18:26 +00:00
27 lines
727 B
TypeScript
27 lines
727 B
TypeScript
import path from "node:path";
|
|
import { resolveStateDir } from "../config/paths.js";
|
|
|
|
export { createAsyncLock, readJsonFile, writeJsonAtomic } from "./json-files.js";
|
|
|
|
export function resolvePairingPaths(baseDir: string | undefined, subdir: string) {
|
|
const root = baseDir ?? resolveStateDir();
|
|
const dir = path.join(root, subdir);
|
|
return {
|
|
dir,
|
|
pendingPath: path.join(dir, "pending.json"),
|
|
pairedPath: path.join(dir, "paired.json"),
|
|
};
|
|
}
|
|
|
|
export function pruneExpiredPending<T extends { ts: number }>(
|
|
pendingById: Record<string, T>,
|
|
nowMs: number,
|
|
ttlMs: number,
|
|
) {
|
|
for (const [id, req] of Object.entries(pendingById)) {
|
|
if (nowMs - req.ts > ttlMs) {
|
|
delete pendingById[id];
|
|
}
|
|
}
|
|
}
|