import { readFile, writeFile } from "fs/promises"; import type { AppleMusicPlaybackEvent } from "../types"; const cacheFilePath = "cache/progress.json"; export type CacheRecord = { songName: string; timestamp: string; }; export async function getCache(): Promise { try { const data = await readFile(cacheFilePath, "utf-8"); return JSON.parse(data); } catch (error) { return []; } } export async function updateCache( event: AppleMusicPlaybackEvent, ): Promise { const cache = await getCache(); cache.push({ songName: event["Song Name"], timestamp: event["Event End Timestamp"], }); await writeFile(cacheFilePath, JSON.stringify(cache, null, 2)); }