From f4d7afc468fcc77e196e779bc4b1cc640c3ff533 Mon Sep 17 00:00:00 2001 From: Nikhil Nawgiri Date: Sun, 27 Oct 2024 01:19:21 +0200 Subject: [PATCH] Improve fsHelper for reading wishlist --- be/src/fsHelper.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/be/src/fsHelper.ts b/be/src/fsHelper.ts index 7508d2d..30d8673 100644 --- a/be/src/fsHelper.ts +++ b/be/src/fsHelper.ts @@ -8,13 +8,16 @@ const saveToDisk = (path: string, content: any) => fs.writeFileSync(path, JSON.s export const saveJfItemsToDisk = (content: {}) => saveToDisk(JELLYFIN_CONTENT_PATH, content); export const saveWishlistToDisk = (content: {}) => saveToDisk(WISHLIST_PATH, content); -export const readWishlistFromDisk = () => { - let wishlistContent: string[] = []; - if (fs.existsSync(WISHLIST_PATH)) { - const fileContent = JSON.parse(fs.readFileSync(WISHLIST_PATH, "utf8")); - wishlistContent = fileContent.wishlistContent; +export const readWishlistFromDisk = async () => { + let wishlistItems: string[] = []; + + if (await fs.existsSync(WISHLIST_PATH)) { + const fileContent = JSON.parse(await fs.readFileSync(WISHLIST_PATH, "utf8")); + wishlistItems = fileContent.wishlistItems; } else { - saveWishlistToDisk({ wishlistContent }); + // create empty wishlist file + saveWishlistToDisk({ wishlistItems }); } - return wishlistContent; + + return wishlistItems; }