kimi-code/apps/kimi-code/src/cli/update/cache.ts
2026-05-22 15:54:50 +08:00

31 lines
840 B
TypeScript

import { z } from 'zod';
import { getUpdateStateFile } from '#/utils/paths';
import { readJsonFile, writeJsonFile } from '#/utils/persistence';
import { emptyUpdateCache, type UpdateCache } from './types';
const UpdateCacheSchema: z.ZodType<UpdateCache> = z
.object({
source: z.literal('cdn'),
checkedAt: z.string().min(1).nullable(),
latest: z.string().min(1).nullable(),
})
.strict();
export async function readUpdateCache(
filePath: string = getUpdateStateFile(),
): Promise<UpdateCache> {
try {
return await readJsonFile(filePath, UpdateCacheSchema, emptyUpdateCache());
} catch {
return emptyUpdateCache();
}
}
export async function writeUpdateCache(
value: UpdateCache,
filePath: string = getUpdateStateFile(),
): Promise<void> {
await writeJsonFile(filePath, UpdateCacheSchema, value);
}