Add /check endpoint to check single imdb against jf and wishlist
This commit is contained in:
parent
f4d7afc468
commit
75d046c934
|
@ -1,5 +1,5 @@
|
|||
import { fetchFromJellyfinApi } from "./jellyfinApiHelper.ts";
|
||||
import { saveJsonToDisk } from "./fsHelper.ts";
|
||||
import { readWishlistFromDisk, saveJfItemsToDisk } from "./fsHelper.ts";
|
||||
import { transformItems } from "./itemHelper.ts";
|
||||
import { app } from "./expressHelper.ts";
|
||||
|
||||
|
@ -16,19 +16,31 @@ const run = async () => {
|
|||
}: JellyfinApiResponse = await fetchFromJellyfinApi();
|
||||
|
||||
const transformedItems = transformItems(items);
|
||||
console.log("transformedItems:", transformedItems);
|
||||
const arrayOfExistingImdbIds = transformedItems.map(item => item.imdbId);
|
||||
console.log("arrayOfExistingImdbIds:", arrayOfExistingImdbIds);
|
||||
|
||||
// saveJsonToDisk({ totalItemCount, jellyfinItems: transformedItems });
|
||||
// saveJfItemsToDisk({ totalItemCount, jellyfinItems: transformedItems });
|
||||
|
||||
app.get("/dingle", (req, res) => {
|
||||
res.json(transformedItems)
|
||||
});
|
||||
// app.get("/items", (req, res) => {
|
||||
// res.json(transformedItems)
|
||||
// });
|
||||
|
||||
// to do: endpoint to check single items against arrayOfExistingImdbIds
|
||||
// const handleCheck = async (imdbId: string, res: any) => {
|
||||
// }
|
||||
|
||||
app.post("/bob", (req, res) => {
|
||||
// improve this endpoint to handle array of imdbId
|
||||
app.get("/check/:imdbId", async (req, res) => {
|
||||
const { imdbId } = req.params;
|
||||
const wishlistItems = await readWishlistFromDisk();
|
||||
if (arrayOfExistingImdbIds.includes(imdbId)) {
|
||||
res.json({ imdbId, status: "ON_JF" });
|
||||
} else if (wishlistItems.includes(imdbId)) {
|
||||
res.json({ imdbId, status: "ON_WISHLIST" });
|
||||
} else {
|
||||
res.json({ imdbId, status: "NO_MATCH" });
|
||||
}
|
||||
})
|
||||
|
||||
app.post("/add", (req, res) => {
|
||||
const { imdbId: requestedImdbId } = req.body;
|
||||
|
||||
if (arrayOfExistingImdbIds.includes(requestedImdbId)) {
|
||||
|
@ -41,8 +53,6 @@ const run = async () => {
|
|||
})
|
||||
|
||||
app.listen(1312);
|
||||
|
||||
// Add logic to endpoints
|
||||
}
|
||||
|
||||
run();
|
||||
|
|
Loading…
Reference in a new issue