Compare commits
No commits in common. "40a5088513ca4c2fb47af008c9fb09473aac618e" and "738cd98618266a6e198e63157bc77425a4b1f9c8" have entirely different histories.
40a5088513
...
738cd98618
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,6 +1,5 @@
|
|||
be/config.ts
|
||||
jellyfin_content.json
|
||||
wishlist.json
|
||||
database.json
|
||||
|
||||
# Logs
|
||||
logs
|
||||
|
|
|
@ -1,23 +1,6 @@
|
|||
import * as fs from "fs";
|
||||
|
||||
const JELLYFIN_CONTENT_PATH = "../jellyfin_content.json";
|
||||
const WISHLIST_PATH = "../wishlist.json";
|
||||
|
||||
const saveToDisk = (path: string, content: any) => fs.writeFileSync(path, JSON.stringify(content));
|
||||
|
||||
export const saveJfItemsToDisk = (content: {}) => saveToDisk(JELLYFIN_CONTENT_PATH, content);
|
||||
export const saveWishlistToDisk = (content: {}) => saveToDisk(WISHLIST_PATH, content);
|
||||
|
||||
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 {
|
||||
// create empty wishlist file
|
||||
saveWishlistToDisk({ wishlistItems });
|
||||
}
|
||||
|
||||
return wishlistItems;
|
||||
export const saveJsonToDisk = (content: {}) => {
|
||||
const outputPath = `../database.json`;
|
||||
fs.writeFileSync(outputPath, JSON.stringify(content));
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { fetchFromJellyfinApi } from "./jellyfinApiHelper.ts";
|
||||
import { readWishlistFromDisk, saveJfItemsToDisk } from "./fsHelper.ts";
|
||||
import { saveJsonToDisk } from "./fsHelper.ts";
|
||||
import { transformItems } from "./itemHelper.ts";
|
||||
import { app } from "./expressHelper.ts";
|
||||
|
||||
|
@ -16,31 +16,22 @@ const run = async () => {
|
|||
}: JellyfinApiResponse = await fetchFromJellyfinApi();
|
||||
|
||||
const transformedItems = transformItems(items);
|
||||
const jellyfinExistingItems = transformedItems.map(item => item.imdbId);
|
||||
console.log("transformedItems:", transformedItems);
|
||||
const arrayOfExistingImdbIds = transformedItems.map(item => item.imdbId);
|
||||
console.log("arrayOfExistingImdbIds:", arrayOfExistingImdbIds);
|
||||
|
||||
// saveJfItemsToDisk({ totalItemCount, jellyfinItems: transformedItems });
|
||||
// saveJsonToDisk({ totalItemCount, jellyfinItems: transformedItems });
|
||||
|
||||
// app.get("/items", (req, res) => {
|
||||
// res.json(transformedItems)
|
||||
// });
|
||||
app.get("/dingle", (req, res) => {
|
||||
res.json(transformedItems)
|
||||
});
|
||||
|
||||
// improve this endpoint to handle array of imdbIds
|
||||
app.get("/check/:imdbId", async (req, res) => {
|
||||
const { imdbId } = req.params;
|
||||
const wishlistItems = await readWishlistFromDisk();
|
||||
if (jellyfinExistingItems.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" });
|
||||
}
|
||||
})
|
||||
// to do: endpoint to check single items against arrayOfExistingImdbIds
|
||||
|
||||
app.post("/add", (req, res) => {
|
||||
app.post("/bob", (req, res) => {
|
||||
const { imdbId: requestedImdbId } = req.body;
|
||||
|
||||
if (jellyfinExistingItems.includes(requestedImdbId)) {
|
||||
if (arrayOfExistingImdbIds.includes(requestedImdbId)) {
|
||||
res.send("DUP\n");
|
||||
} else {
|
||||
// to do: push to wishlist array
|
||||
|
@ -50,6 +41,8 @@ const run = async () => {
|
|||
})
|
||||
|
||||
app.listen(1312);
|
||||
|
||||
// Add logic to endpoints
|
||||
}
|
||||
|
||||
run();
|
||||
|
|
Loading…
Reference in a new issue