MCPcopy Create free account
hub / github.com/FlashpointProject/launcher / readOrCreateFile

Function readOrCreateFile

src/back/PlaylistFile.ts:29–45  ·  view source on GitHub ↗
(filePath: string, onError?: (error: string) => void)

Source from the content-addressed store, hash-verified

27 }
28
29 export async function readOrCreateFile(filePath: string, onError?: (error: string) => void): Promise<Playlist> {
30 let error: Error | undefined;
31 let data: Playlist | undefined;
32
33 try {
34 data = await readFile(filePath, onError);
35 } catch (e: any) {
36 error = e;
37 }
38
39 if (error || !data) {
40 data = deepCopy(DEFAULT_PLAYLIST_DATA);
41 saveFile(filePath, data).catch(() => console.log('Failed to save default config file!'));
42 }
43
44 return data;
45 }
46
47 export function readOrCreateFileSync(filePath: string, onError?: (error: string) => void): Playlist {
48 let error: Error | undefined;

Callers

nothing calls this directly

Calls 3

deepCopyFunction · 0.90
readFileFunction · 0.70
saveFileFunction · 0.70

Tested by

no test coverage detected