diff --git a/be/src/main.ts b/be/src/main.ts index b330ec4..aed5bdf 100644 --- a/be/src/main.ts +++ b/be/src/main.ts @@ -1,5 +1,5 @@ import { fetchFromJellyfinApi } from "./jellyfinApiHelper.ts"; -import { readWishlistFromDisk, saveJfItemsToDisk } from "./fsHelper.ts"; +import { readWishlistFromDisk, saveJfItemsToDisk, saveWishlistToDisk } from "./fsHelper.ts"; import { transformItems } from "./itemHelper.ts"; import { app } from "./expressHelper.ts"; @@ -37,15 +37,17 @@ const run = async () => { } }) - app.post("/add", (req, res) => { + app.post("/add", async (req, res) => { const { imdbId: requestedImdbId } = req.body; + const wishlistItems = await readWishlistFromDisk(); - if (jellyfinExistingItems.includes(requestedImdbId)) { - res.send("DUP\n"); + if (jellyfinExistingItems.includes(requestedImdbId) + || wishlistItems.includes(requestedImdbId)) { + res.json({ requestedImdbId, status: "REJECTED" }); } else { - // to do: push to wishlist array - // to do: save wishlist array to disk - res.send("OK\n"); + wishlistItems.push(requestedImdbId) + saveWishlistToDisk({ wishlistItems }); + res.json({ requestedImdbId, status: "OK" }); } })