Compare commits
7 commits
738cd98618
...
40a5088513
Author | SHA1 | Date | |
---|---|---|---|
40a5088513 | |||
01291a74fa | |||
75d046c934 | |||
f4d7afc468 | |||
45fb46efa5 | |||
48314d97b0 | |||
ca880154bf |
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,5 +1,6 @@
|
|||
be/config.ts
|
||||
database.json
|
||||
jellyfin_content.json
|
||||
wishlist.json
|
||||
|
||||
# Logs
|
||||
logs
|
||||
|
|
|
@ -1,6 +1,23 @@
|
|||
import * as fs from "fs";
|
||||
|
||||
export const saveJsonToDisk = (content: {}) => {
|
||||
const outputPath = `../database.json`;
|
||||
fs.writeFileSync(outputPath, JSON.stringify(content));
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -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,22 +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);
|
||||
const jellyfinExistingItems = transformedItems.map(item => item.imdbId);
|
||||
|
||||
// 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
|
||||
// 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" });
|
||||
}
|
||||
})
|
||||
|
||||
app.post("/bob", (req, res) => {
|
||||
app.post("/add", (req, res) => {
|
||||
const { imdbId: requestedImdbId } = req.body;
|
||||
|
||||
if (arrayOfExistingImdbIds.includes(requestedImdbId)) {
|
||||
if (jellyfinExistingItems.includes(requestedImdbId)) {
|
||||
res.send("DUP\n");
|
||||
} else {
|
||||
// to do: push to wishlist array
|
||||
|
@ -41,8 +50,6 @@ const run = async () => {
|
|||
})
|
||||
|
||||
app.listen(1312);
|
||||
|
||||
// Add logic to endpoints
|
||||
}
|
||||
|
||||
run();
|
||||
|
|
Loading…
Reference in a new issue