diff --git a/.gitignore b/.gitignore index 9be5eda..26f9300 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,7 @@ node_modules/ *.sqllite testStuff/ chache.bin -key.cfg \ No newline at end of file +key.cfg +database2.sqlite +database.sqlite +old.sqlite diff --git a/database.sqlite b/database.sqlite index f474932..adca4ba 100644 Binary files a/database.sqlite and b/database.sqlite differ diff --git a/index.js b/index.js index 515cc8c..9be3817 100644 --- a/index.js +++ b/index.js @@ -3,13 +3,12 @@ const Eta = require("eta"); const fs = require("fs"); const request = require("request"); const imdb = require("imdb-api"); -const sqlite3 = require("sqlite3"); const requestSync = require("sync-request"); var Config = require('config-js'); const app = express(); const PrismaClient = require('@prisma/client').PrismaClient; const port = 4000; -const eanConvAdress = "http://192.168.178.51:9999/" +const eanConvAdress = "http://127.0.0.1:9999/" const typeIndex = {0: "Physical", 1: "Digital - Maxdome", 2: "Digital - Amazon Prime Video", 3: "Digital - DVR"} @@ -19,17 +18,6 @@ var responseBuffer = { allBufferd: [] }; responseBuffer = JSON.parse(fs.readFileSync("chache.bin", "utf8")); -var db = new sqlite3.Database("database.sqlite"); -if (!fs.existsSync("database.sqlite")) { - console.log("Creating table."); - db.serialize(() => { - db.run(initalTableSQL); - //db.run(initalTableSQL2); - }); -} -db.close(); -var db = new sqlite3.Database("database.sqlite"); - var config = new Config('key.cfg'); @@ -55,10 +43,13 @@ app.get("/add", function (req, res) { }); app.get("/delete", function (req, res) { + console.log(req.query.id) prisma.movieInfo.delete({ where: { - movieID: req.query.id + id: parseInt(req.query.id) } + }).then(function handleFinishDelete(result) { + console.log(result) }) console.log("Deleted entries") res.send("Done."); @@ -99,6 +90,41 @@ app.get("/showDetails", async function (req, res) { ) }); +app.get("/editDetails", async function (req, res) { + const data = fs.readFileSync("template/editDetails.html", "utf8"); + console.log(req.query["id"]) + const movie = await prisma.movieInfo.findFirst({ + where: { + movieID: req.query["id"] + } + }) + res.send( + Eta.render(data, { + internalID: movie.id, + id: movie.movieID, + cover: movie.posterUrl, + titleByAPI: movie.movieTitel, + type: typeIndex[movie.type], + typeId: movie.type + }) + ) +}); + +app.get("/api/edit", function handleEdit(req, res){ + console.log(req.query) + prisma.movieInfo.update({ + where: { + id: parseInt(req.query["id"]) + }, + data: { + type: parseInt(req.query["type"]) + } + }).then(function handleFinishEdit(result) { + console.log(result) + }) + res.send("Done."); +}) + app.get("/apiCallBack", function (req, res) { //console.log(req.query); if (!responseBuffer.allBufferd.includes(req.query["ean"])) { @@ -166,6 +192,7 @@ app.get("/apiCallBack", function (req, res) { } }); + app.get("/save", async function handleSave(req, res) { responseJson = responseBuffer[req.query["reponseID"]]; const type = parseInt(req.query["type"]) || 0; @@ -184,6 +211,8 @@ app.get("/save", async function handleSave(req, res) { type: type, posterUrl: responseJson.coverImage } + }).then(function handleFinishCreate(result) { + console.log(result) }) res.send({ status: "OK" }); }else{ diff --git a/template/editDetails.html b/template/editDetails.html new file mode 100644 index 0000000..44ba7cc --- /dev/null +++ b/template/editDetails.html @@ -0,0 +1,125 @@ + + + + + + OpenMovieDB - Bookshelf - Edit + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+ +
+
+
+

OpenMovieDB - Edit a movie

+
+ Cover image
+
<%= it.titleByAPI %>
<%= it.id %>
+ Type: +
+
+ + +
+
+
+ + + + \ No newline at end of file diff --git a/template/movieDetails.html b/template/movieDetails.html index aac9c3f..77f0daf 100644 --- a/template/movieDetails.html +++ b/template/movieDetails.html @@ -93,8 +93,9 @@
Cover image
<%= it.titleByAPI %>
<%= it.id %>
- Art: <%= it.type %>
-
+ Type: <%= it.type %> +
+ @@ -111,6 +112,11 @@ document.getElementById("overlay2").style.display = "none"; } + function handleEdit(){ + console.log("Editing movie") + window.location.href = '/editDetails?id=<%= it.id %>'; + } + function sureDelete(){ console.log("Deleting movie") url = "/delete?id=<%= it.internalID %>";