From df44638771be2e9619c2dc31ad0d868f32659143 Mon Sep 17 00:00:00 2001 From: Karl0ss Date: Thu, 27 Oct 2022 10:43:33 +0100 Subject: [PATCH] edit show quality + last downloaded file --- FeedFilter.js | 1 + JDRssDownloader.js | 1 + apiFunctions.js | 24 ++++++++++++++++++++++-- routes/root.js | 2 +- routes/shows.js | 12 +++++++++++- views/editShow.pug | 20 ++++++++++++++++++++ views/index.pug | 4 ++++ 7 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 views/editShow.pug diff --git a/FeedFilter.js b/FeedFilter.js index bd88791..6a31f80 100644 --- a/FeedFilter.js +++ b/FeedFilter.js @@ -55,6 +55,7 @@ async function filterFeed() { log.tele(downloadList.length + ' links for ' + urlObj.fileName + ' have been sent to JDdownloader.') linkAdder(downloadList) global.linkCheckTime = new Date(); + global.lastDownloadedLink = urlObj.fileName } } else { // No HEVC links found diff --git a/JDRssDownloader.js b/JDRssDownloader.js index fbf05ad..f329814 100644 --- a/JDRssDownloader.js +++ b/JDRssDownloader.js @@ -25,6 +25,7 @@ app.use(basicAuth({ global.rssRefreshTime = new Date(); global.linkCheckTime = new Date(); global.version = require('./package.json').version; +global.lastDownloadedLink = 'None' global.log = require('simple-node-logger').createSimpleLogger({ logFilePath: 'jdrssdownloader.log', diff --git a/apiFunctions.js b/apiFunctions.js index 2683b70..e76809a 100644 --- a/apiFunctions.js +++ b/apiFunctions.js @@ -41,7 +41,27 @@ async function removeShow(showData) { } } -module.exports = { - addNewShow, removeShow + +async function editShow(showData) { + let shows = JSON.parse(fs.readFileSync('shows.json')) + for (let index = 0; index < shows.length; index++) { + const element = shows[index]; + if (element.Name == showData.showName) { + shows[index] = { + "Name": showData.showName, + "Quality": showData.quality + } + } + } + try { + fs.writeFileSync('shows.json', JSON.stringify(shows)); + log.info(showData.showName + ' Quality modified to ' + showData.quality + 'p') + } catch (err) { + console.error(err); + } +} + +module.exports = { + addNewShow, removeShow, editShow } diff --git a/routes/root.js b/routes/root.js index 1fc5cae..4f62cb2 100644 --- a/routes/root.js +++ b/routes/root.js @@ -7,6 +7,6 @@ module.exports = function (app) { showListLength = JSON.parse(fs.readFileSync('shows.json')).length rssTime = nextRssRefresh() linkCheck = nextLinkCheck() - res.render("index", { title: "Home", showListLength: showListLength, version: global.version, rssTime: rssTime, linkCheck: linkCheck }); + res.render("index", { title: "Home", showListLength: showListLength, version: global.version, rssTime: rssTime, linkCheck: linkCheck, lastDownloaded: global.lastDownloadedLink }); }); } \ No newline at end of file diff --git a/routes/shows.js b/routes/shows.js index 53243e7..d94474f 100644 --- a/routes/shows.js +++ b/routes/shows.js @@ -1,5 +1,5 @@ const fs = require("fs"); -const { addNewShow, removeShow } = require('.././apiFunctions') +const { addNewShow, removeShow, editShow } = require('.././apiFunctions') module.exports = function (app) { app.get("/shows", (req, res) => { @@ -16,6 +16,11 @@ module.exports = function (app) { res.render("removeshow", { title: "Remove Show", showList: showList }); }); + app.get("/shows/edit", (req, res) => { + showList = JSON.parse(fs.readFileSync('shows.json')) + res.render("editShow", { title: "Edit Show", showList: showList }); + }); + app.post('/addNewShow', (req, res) => { addNewShow(req.body) res.redirect("/shows"); @@ -25,4 +30,9 @@ module.exports = function (app) { removeShow(req.body) res.redirect("/shows"); }); + + app.post('/editShow', (req, res) => { + editShow(req.body) + res.redirect("/shows"); + }); } diff --git a/views/editShow.pug b/views/editShow.pug new file mode 100644 index 0000000..e5d16b1 --- /dev/null +++ b/views/editShow.pug @@ -0,0 +1,20 @@ +extends layout + +block layout-content + div.View + h1.Banner Edit Show + div.Message + form(action="/editShow" method="POST") + p Show Name: + select(name="showName") + each show in showList + option(value=show.Name) #{show.Name} + p Quality: + select(name="quality") + option(value='720') #{'720p'} + option(value='1080') #{'1080p'} + option(value='2160') #{'2160p'} + input(type="submit", value="Edit Show") + div.NavButtons + a(href="/") + div.NavButton Home \ No newline at end of file diff --git a/views/index.pug b/views/index.pug index b94462d..6736900 100644 --- a/views/index.pug +++ b/views/index.pug @@ -7,6 +7,8 @@ block layout-content div.Message h3 Number of Tracked Shows h1 #{showListLength} + h3 Last Downloaded + h1 #{lastDownloaded} h3 Next RSS Refresh h1 #{rssTime} h3 Next Link Check @@ -16,6 +18,8 @@ block layout-content div.NavButton Show List a(href="/shows/add") div.NavButton Add New Show + a(href="/shows/edit") + div.NavButton Edit Show a(href="/shows/remove") div.NavButton Remove Show a(href="/logFile")