From 12d8c65c3954abd750bccb36df9e688caebbbc63 Mon Sep 17 00:00:00 2001 From: Karl0ss Date: Wed, 26 Oct 2022 10:15:08 +0100 Subject: [PATCH] move shows to own file --- FeedFilter.js | 2 +- apiFunctions.js | 18 +++++++++--------- routes/root.js | 7 ++++--- routes/shows.js | 4 ++-- shows.json | 1 + views/layout.pug | 2 +- 6 files changed, 18 insertions(+), 16 deletions(-) create mode 100644 shows.json diff --git a/FeedFilter.js b/FeedFilter.js index 3bb61d8..3739e8d 100644 --- a/FeedFilter.js +++ b/FeedFilter.js @@ -5,8 +5,8 @@ const { checkFileName } = require('./checkFileName') const { checkDownloadHistory } = require('./checkDownloadHistory') async function filterFeed() { - let myshowlist = JSON.parse(fs.readFileSync('config.json')).Shows let hevcSwitch = JSON.parse(fs.readFileSync('config.json')).OnlyHEVC + let myshowlist = JSON.parse(fs.readFileSync('shows.json')) let feed = JSON.parse(fs.readFileSync('./feedCache.json')); let retryShowCache = [] let urlsToCheck = [] diff --git a/apiFunctions.js b/apiFunctions.js index 81e7ac3..2683b70 100644 --- a/apiFunctions.js +++ b/apiFunctions.js @@ -1,10 +1,10 @@ const fs = require('fs'); -const { config } = require('process'); + async function addNewShow(showData) { - let config = JSON.parse(fs.readFileSync('config.json')) + let shows = JSON.parse(fs.readFileSync('shows.json')) let exist = false - for (let show of config.Shows) { + for (let show of shows) { if (show.Name == showData.showName) { exist = true } @@ -12,12 +12,12 @@ async function addNewShow(showData) { if (exist) { log.error(showData.showName + ' Already exists in list and not added') } else { - config.Shows.push({ + shows.push({ "Name": showData.showName, "Quality": showData.quality }) try { - fs.writeFileSync('config.json', JSON.stringify(config)); + fs.writeFileSync('shows.json', JSON.stringify(shows)); log.info(showData.showName + ' Added to the list, checking for ' + showData.quality + 'p') } catch (err) { console.error(err); @@ -26,15 +26,15 @@ async function addNewShow(showData) { } async function removeShow(showData) { - let config = JSON.parse(fs.readFileSync('config.json')) + let shows = JSON.parse(fs.readFileSync('shows.json')) - myArray = config.Shows.filter(function (obj) { + myArray = shows.filter(function (obj) { return obj.Name !== showData.showName; }); - config.Shows = myArray + shows = myArray try { - fs.writeFileSync('config.json', JSON.stringify(config)); + fs.writeFileSync('shows.json', JSON.stringify(shows)); log.info(showData.showName + ' Removed from tracking list.') } catch (err) { console.error(err); diff --git a/routes/root.js b/routes/root.js index ec52316..1fc5cae 100644 --- a/routes/root.js +++ b/routes/root.js @@ -4,8 +4,9 @@ const { nextLinkCheck, nextRssRefresh } = require('.././utils') module.exports = function (app) { app.get("/", (req, res) => { - showListLength = JSON.parse(fs.readFileSync('config.json')).Shows.length - a = - res.render("index", { title: "Home", showListLength: showListLength, version: global.version, rssTime: nextRssRefresh(), linkCheck: nextLinkCheck() }); + 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 }); }); } \ No newline at end of file diff --git a/routes/shows.js b/routes/shows.js index 96369c6..53243e7 100644 --- a/routes/shows.js +++ b/routes/shows.js @@ -3,7 +3,7 @@ const { addNewShow, removeShow } = require('.././apiFunctions') module.exports = function (app) { app.get("/shows", (req, res) => { - showList = JSON.parse(fs.readFileSync('config.json')).Shows + showList = JSON.parse(fs.readFileSync('shows.json')) res.render("shows", { title: "Show List", showList: showList }); }); @@ -12,7 +12,7 @@ module.exports = function (app) { }); app.get("/shows/remove", (req, res) => { - showList = JSON.parse(fs.readFileSync('config.json')).Shows + showList = JSON.parse(fs.readFileSync('shows.json')) res.render("removeshow", { title: "Remove Show", showList: showList }); }); diff --git a/shows.json b/shows.json new file mode 100644 index 0000000..0637a08 --- /dev/null +++ b/shows.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/views/layout.pug b/views/layout.pug index 508cfc0..f8d555b 100644 --- a/views/layout.pug +++ b/views/layout.pug @@ -4,7 +4,7 @@ html head meta(charset="utf-8") link(rel="shortcut icon", href="/favicon.ico") - meta(name="viewport", content="width=device-width, initial-scale=1, shrink-to-fit=no") + meta(name="viewport", content="width=device-width, initial-scale=1, shrink-to-fit=yes") meta(name="theme-color", content="#000000") title #{title} | JDRssDownloader link(rel="stylesheet" href="/style.css")