Add /add endpoint with logic
This commit is contained in:
parent
1d60f1e04f
commit
fb56525685
|
@ -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" });
|
||||
}
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in a new issue