From 12d8c65c3954abd750bccb36df9e688caebbbc63 Mon Sep 17 00:00:00 2001 From: Karl0ss Date: Wed, 26 Oct 2022 10:15:08 +0100 Subject: [PATCH 1/7] 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") From 085e64cb344a5e752a890613a8a3078242131185 Mon Sep 17 00:00:00 2001 From: Karl0ss Date: Wed, 26 Oct 2022 10:15:35 +0100 Subject: [PATCH 2/7] ignore my show updates --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index a75cf9d..1f8a2b8 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ dist/jdrssdownloader-linux dist/jdrssdownloader-win.exe dist/jdrssdownloader-macos downloadHistory.json +shows.json From e5987247feb029be0871bace56cff8d79e11ea5b Mon Sep 17 00:00:00 2001 From: Karl0ss Date: Wed, 26 Oct 2022 10:19:43 +0100 Subject: [PATCH 3/7] 2160p option --- views/addshow.pug | 1 + 1 file changed, 1 insertion(+) diff --git a/views/addshow.pug b/views/addshow.pug index 3bf8c4c..c6b4176 100644 --- a/views/addshow.pug +++ b/views/addshow.pug @@ -11,6 +11,7 @@ block layout-content select(name="quality") option(value='720') #{'720p'} option(value='1080') #{'1080p'} + option(value='2160') #{'2160p'} input(type="submit", value="Add Show") div.NavButtons a(href="/") From 0cc32b18c999dbd80bf13c9678b67b2ddc765357 Mon Sep 17 00:00:00 2001 From: Karl0ss Date: Wed, 26 Oct 2022 10:36:17 +0100 Subject: [PATCH 4/7] move some bits to cache folder --- FeedFilter.js | 4 ++-- FeedUpdater.js | 6 +++--- checkDownloadHistory.js | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/FeedFilter.js b/FeedFilter.js index 3739e8d..bd88791 100644 --- a/FeedFilter.js +++ b/FeedFilter.js @@ -7,7 +7,7 @@ const { checkDownloadHistory } = require('./checkDownloadHistory') async function filterFeed() { 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 feed = JSON.parse(fs.readFileSync('./cache/feedCache.json')); let retryShowCache = [] let urlsToCheck = [] @@ -75,7 +75,7 @@ async function filterFeed() { } } log.info('Wiping feed cache') - fs.writeFileSync('./feedCache.json', JSON.stringify(retryShowCache)); + fs.writeFileSync('./cache/feedCache.json', JSON.stringify(retryShowCache)); global.linkCheckTime = new Date(); } diff --git a/FeedUpdater.js b/FeedUpdater.js index 6905fb2..8e9268a 100644 --- a/FeedUpdater.js +++ b/FeedUpdater.js @@ -11,15 +11,15 @@ async function feedUpdater() { let items = []; - if (fs.existsSync('./feedCache.json')) { - items = JSON.parse(fs.readFileSync('./feedCache.json')) + if (fs.existsSync('./cache/feedCache.json')) { + items = JSON.parse(fs.readFileSync('./cache/feedCache.json')) } // Compare existing cache and new items and merge differences let updatedArray = lodash.unionBy(feed.items, items, 'title'); // Save the file log.info(updatedArray.length + ' items in file cache') - fs.writeFileSync('./feedCache.json', JSON.stringify(updatedArray)); + fs.writeFileSync('./cache/feedCache.json', JSON.stringify(updatedArray)); global.rssRefreshTime = new Date(); } diff --git a/checkDownloadHistory.js b/checkDownloadHistory.js index e3c923b..9496b9e 100644 --- a/checkDownloadHistory.js +++ b/checkDownloadHistory.js @@ -2,16 +2,16 @@ const fs = require('fs') function checkDownloadHistory(urlObj) { try { - history = JSON.parse(fs.readFileSync('./downloadHistory.json')); + history = JSON.parse(fs.readFileSync('./cache/downloadHistory.json')); } catch (error) { - fs.writeFileSync('./downloadHistory.json', JSON.stringify([])); + fs.writeFileSync('./cache/downloadHistory.json', JSON.stringify([])); } - history = JSON.parse(fs.readFileSync('./downloadHistory.json')); + history = JSON.parse(fs.readFileSync('./cache/downloadHistory.json')); if (history.includes(urlObj.fileName)) { return true } else { history.push(urlObj.fileName) - fs.writeFileSync('./downloadHistory.json', JSON.stringify(history)); + fs.writeFileSync('./cache/downloadHistory.json', JSON.stringify(history)); return false } } From df44638771be2e9619c2dc31ad0d868f32659143 Mon Sep 17 00:00:00 2001 From: Karl0ss Date: Thu, 27 Oct 2022 10:43:33 +0100 Subject: [PATCH 5/7] 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") From bb2e58e624d14fd875ba39146ed784549a4dda71 Mon Sep 17 00:00:00 2001 From: Karl0ss Date: Thu, 27 Oct 2022 13:58:36 +0100 Subject: [PATCH 6/7] post validation, rework last downloaded, upversion --- FeedFilter.js | 1 - JDRssDownloader.js | 1 - package.json | 3 ++- public/style.css | 8 +++++++- routes/root.js | 4 ++-- routes/shows.js | 19 +++++++++++++++---- utils.js | 10 ++++++++-- views/index.pug | 16 ++++++++-------- 8 files changed, 42 insertions(+), 20 deletions(-) diff --git a/FeedFilter.js b/FeedFilter.js index 6a31f80..bd88791 100644 --- a/FeedFilter.js +++ b/FeedFilter.js @@ -55,7 +55,6 @@ 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 f329814..fbf05ad 100644 --- a/JDRssDownloader.js +++ b/JDRssDownloader.js @@ -25,7 +25,6 @@ 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/package.json b/package.json index 4b72bf3..5498df0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jdrssdownloader", - "version": "1.1.0", + "version": "1.1.1", "description": "", "main": "JDRssDownloader.js", "bin": "JDRssDownloader.js", @@ -15,6 +15,7 @@ "cors": "^2.8.5", "express": "^4.18.2", "express-basic-auth": "^1.2.1", + "express-validator": "^6.14.2", "jdownloader-client": "^1.0.0", "line-reader": "^0.4.0", "lodash": "^4.17.21", diff --git a/public/style.css b/public/style.css index dd4012f..8b73dba 100644 --- a/public/style.css +++ b/public/style.css @@ -97,9 +97,15 @@ a { .Message { background: white; - padding: 30px; + border-radius: 5px; + padding: 20px; border-bottom: var(--ui-shadow-border); box-shadow: var(--ui-shadow); + overflow-x: hidden; + overflow-y: auto; + /* text-align: center; */ + margin-top:10px; + margin-bottom:10px; } .Message > .Title { diff --git a/routes/root.js b/routes/root.js index 4f62cb2..a687c36 100644 --- a/routes/root.js +++ b/routes/root.js @@ -1,5 +1,5 @@ const fs = require("fs"); -const { nextLinkCheck, nextRssRefresh } = require('.././utils') +const { nextLinkCheck, nextRssRefresh, get_last_downloaded } = require('.././utils') module.exports = function (app) { @@ -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, lastDownloaded: global.lastDownloadedLink }); + res.render("index", { title: "Home", showListLength: showListLength, version: global.version, rssTime: rssTime, linkCheck: linkCheck, lastDownloaded: get_last_downloaded() }); }); } \ No newline at end of file diff --git a/routes/shows.js b/routes/shows.js index d94474f..ad05fc0 100644 --- a/routes/shows.js +++ b/routes/shows.js @@ -1,5 +1,7 @@ const fs = require("fs"); const { addNewShow, removeShow, editShow } = require('.././apiFunctions') +const { check, validationResult } = require('express-validator'); + module.exports = function (app) { app.get("/shows", (req, res) => { @@ -21,10 +23,19 @@ module.exports = function (app) { res.render("editShow", { title: "Edit Show", showList: showList }); }); - app.post('/addNewShow', (req, res) => { - addNewShow(req.body) - res.redirect("/shows"); - }); + app.post('/addNewShow', [ + check('showName') + .isLength({ min: 1 }) + ], (req, res) => { + if (validationResult(req).isEmpty()) { + addNewShow(req.body) + res.redirect("/shows"); + } else { + log.error('You cannot add a show without a name.') + res.redirect("/shows"); + } + } + ); app.post('/removeShow', (req, res) => { removeShow(req.body) diff --git a/utils.js b/utils.js index 0ceaf32..92bc34c 100644 --- a/utils.js +++ b/utils.js @@ -16,7 +16,13 @@ function nextLinkCheck() { return returnUpdatedDate(global.linkCheckTime, config.JDPostLinksMins) } -module.exports = { - nextRssRefresh, nextLinkCheck +function get_last_downloaded(){ + history = JSON.parse(fs.readFileSync('./cache/downloadHistory.json')) + last = history.slice(-1)[0] + return last +} + +module.exports = { + nextRssRefresh, nextLinkCheck, get_last_downloaded } diff --git a/views/index.pug b/views/index.pug index 6736900..6420fa7 100644 --- a/views/index.pug +++ b/views/index.pug @@ -5,14 +5,14 @@ block layout-content h1.Banner JDRssDownloader #{version} body div.Message - h3 Number of Tracked Shows - h1 #{showListLength} - h3 Last Downloaded - h1 #{lastDownloaded} - h3 Next RSS Refresh - h1 #{rssTime} - h3 Next Link Check - h1 #{linkCheck} + h2 Number of Tracked Shows + h3 #{showListLength} + h2 Last Downloaded + h3 #{lastDownloaded} + h2 Next RSS Refresh + h3 #{rssTime} + h2 Next Link Check + h3 #{linkCheck} div.NavButtons a(href="/shows") div.NavButton Show List From 73b2f98cb51089d028b3d82e85fc2de4bce2d7f9 Mon Sep 17 00:00:00 2001 From: Karl0ss Date: Tue, 24 Jan 2023 12:04:14 +0000 Subject: [PATCH 7/7] latest updates --- .gitignore | 2 ++ FeedFilter.js | 12 +++++++----- JDRssDownloader.js | 3 ++- apiFunctions.js | 21 +++++++++++++++++++-- checkDownloadHistory.js | 5 ----- package.json | 2 +- retryCache.js | 21 +++++++++++++++++++++ routes/cache.js | 25 +++++++++++++++++++++++++ routes/root.js | 2 ++ utils.js | 31 +++++++++++++++++++++++++++---- views/feedCache.pug | 26 ++++++++++++++++++++++++++ views/index.pug | 11 +++++++++-- views/retryCache.pug | 26 ++++++++++++++++++++++++++ 13 files changed, 167 insertions(+), 20 deletions(-) create mode 100644 retryCache.js create mode 100644 routes/cache.js create mode 100644 views/feedCache.pug create mode 100644 views/retryCache.pug diff --git a/.gitignore b/.gitignore index 1f8a2b8..dbf8bde 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,5 @@ dist/jdrssdownloader-win.exe dist/jdrssdownloader-macos downloadHistory.json shows.json +shows.json +cache/retryCache.json diff --git a/FeedFilter.js b/FeedFilter.js index bd88791..45c9196 100644 --- a/FeedFilter.js +++ b/FeedFilter.js @@ -3,12 +3,14 @@ const { linkAdder } = require('./JDLinkAdder'); const { getLinksFromURL } = require('./LinkGrabber') const { checkFileName } = require('./checkFileName') const { checkDownloadHistory } = require('./checkDownloadHistory') +const { retryCache } = require('./retryCache') async function filterFeed() { let hevcSwitch = JSON.parse(fs.readFileSync('config.json')).OnlyHEVC let myshowlist = JSON.parse(fs.readFileSync('shows.json')) - let feed = JSON.parse(fs.readFileSync('./cache/feedCache.json')); - let retryShowCache = [] + let rssFeed = JSON.parse(fs.readFileSync('./cache/feedCache.json')); + let retryCacheData = retryCache() + let fullFeedToCheck = retryCacheData.concat(rssFeed) let urlsToCheck = [] @@ -16,7 +18,7 @@ async function filterFeed() { try { // Find show on feed - let listFilteredForShow = feed.filter(item => item.title.includes(show.Name)) + let listFilteredForShow = fullFeedToCheck.filter(item => item.title.includes(show.Name)) if (listFilteredForShow.length > 0) { for (let match of listFilteredForShow) { // If show is found get url then return all links on that page @@ -60,7 +62,7 @@ async function filterFeed() { // No HEVC links found log.info(downloadList.length + ' links for ' + show.Name + ' have been found, will recheck next time.') for (let feedItem of listFilteredForShow) { - retryShowCache.push(feedItem) + retryCache(feedItem) } global.linkCheckTime = new Date(); } @@ -75,7 +77,7 @@ async function filterFeed() { } } log.info('Wiping feed cache') - fs.writeFileSync('./cache/feedCache.json', JSON.stringify(retryShowCache)); + fs.writeFileSync('./cache/feedCache.json', JSON.stringify([])); global.linkCheckTime = new Date(); } diff --git a/JDRssDownloader.js b/JDRssDownloader.js index fbf05ad..5ef072b 100644 --- a/JDRssDownloader.js +++ b/JDRssDownloader.js @@ -1,9 +1,9 @@ const fs = require("fs"); config = JSON.parse(fs.readFileSync('config.json')) - const { feedUpdater } = require('./FeedUpdater') const { filterFeed } = require('./FeedFilter') const { telegrambot } = require('./telegramCommunication') +const { create_empty_cache_files } = require('./utils') const express = require('express'); const bodyParser = require('body-parser'); const cors = require('cors'); @@ -52,6 +52,7 @@ async function main() { log.tele('Refreshing RSS Items every ' + RSSFeedRefreshMins + ' Minutes') log.tele('Checking for links and sending to JDdownloader every ' + JDPostLinksMins + ' Minutes') app.listen(config.WebUIPort, () => log.info(`WebUi is listening on ${config.WebUIPort}!`)) + create_empty_cache_files() setInterval(await feedUpdater, RSSFeedRefreshMins * 60000); setInterval(await filterFeed, JDPostLinksMins * 60000); } diff --git a/apiFunctions.js b/apiFunctions.js index e76809a..fb4a0b1 100644 --- a/apiFunctions.js +++ b/apiFunctions.js @@ -61,7 +61,24 @@ async function editShow(showData) { } } -module.exports = { - addNewShow, removeShow, editShow +async function removeShowFromCache(showData) { + let shows = JSON.parse(fs.readFileSync('./cache/retryCache.json')) + + myArray = shows.filter(function (obj) { + return obj.title !== showData; + }); + + shows = myArray + try { + fs.writeFileSync('./cache/retryCache.json', JSON.stringify(shows)); + log.info(showData + ' Removed from retry cache.') + } catch (err) { + console.error(err); + } +} + + +module.exports = { + addNewShow, removeShow, editShow, removeShowFromCache } diff --git a/checkDownloadHistory.js b/checkDownloadHistory.js index 9496b9e..010f592 100644 --- a/checkDownloadHistory.js +++ b/checkDownloadHistory.js @@ -1,11 +1,6 @@ const fs = require('fs') function checkDownloadHistory(urlObj) { - try { - history = JSON.parse(fs.readFileSync('./cache/downloadHistory.json')); - } catch (error) { - fs.writeFileSync('./cache/downloadHistory.json', JSON.stringify([])); - } history = JSON.parse(fs.readFileSync('./cache/downloadHistory.json')); if (history.includes(urlObj.fileName)) { return true diff --git a/package.json b/package.json index 5498df0..c2358c0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jdrssdownloader", - "version": "1.1.1", + "version": "1.1.2", "description": "", "main": "JDRssDownloader.js", "bin": "JDRssDownloader.js", diff --git a/retryCache.js b/retryCache.js new file mode 100644 index 0000000..c4d2e6e --- /dev/null +++ b/retryCache.js @@ -0,0 +1,21 @@ +const fs = require('fs') + +function retryCache(cache) { + if (cache == null) { + retryCacheData = JSON.parse(fs.readFileSync('./cache/retryCache.json')); + return retryCacheData + } + retryCacheData = JSON.parse(fs.readFileSync('./cache/retryCache.json')); + if (retryCacheData.some(e => e.title === cache.title)) { + log.info(cache.title + ' is already in the retry cache.') + } + else { + cache.retryCount = 5 + retryCacheData.push(cache) + fs.writeFileSync('./cache/retryCache.json', JSON.stringify(retryCacheData)); + log.info(cache.title + ' written to retry cache.') + return retryCacheData + } +} + +module.exports = { retryCache } \ No newline at end of file diff --git a/routes/cache.js b/routes/cache.js new file mode 100644 index 0000000..c4d4641 --- /dev/null +++ b/routes/cache.js @@ -0,0 +1,25 @@ +const fs = require("fs"); +const {removeShowFromCache} = require('../apiFunctions') + +module.exports = function (app) { + app.get("/feedCache", (req, res) => { + feedCache = JSON.parse(fs.readFileSync('./cache/feedCache.json')) + res.render("feedCache", { title: "Feed Cache", feedCache: feedCache }); + }); + + app.get("/retryCache", (req, res) => { + retryCache = JSON.parse(fs.readFileSync('./cache/retryCache.json')) + for (let index = 0; index < retryCache.length; index++) { + const item = retryCache[index]; + retryCache[index].newtitle = item.title.replace(/ /g, "‡"); + } + res.render("retryCache", { title: "Retry Cache", retryCache: retryCache }); + }); + + app.get('/retryCache/remove', (req, res) => { + const showName = req.query.name.replaceAll("‡", " "); + console.log(req) + removeShowFromCache(showName) + res.redirect("/retryCache"); + }); +} diff --git a/routes/root.js b/routes/root.js index a687c36..f78f57e 100644 --- a/routes/root.js +++ b/routes/root.js @@ -5,6 +5,8 @@ module.exports = function (app) { app.get("/", (req, res) => { showListLength = JSON.parse(fs.readFileSync('shows.json')).length + feedCacheLength = JSON.parse(fs.readFileSync('./cache/feedCache.json')).length + retryCacheLength = JSON.parse(fs.readFileSync('./cache/retryCache.json')).length rssTime = nextRssRefresh() linkCheck = nextLinkCheck() res.render("index", { title: "Home", showListLength: showListLength, version: global.version, rssTime: rssTime, linkCheck: linkCheck, lastDownloaded: get_last_downloaded() }); diff --git a/utils.js b/utils.js index 92bc34c..a1731e1 100644 --- a/utils.js +++ b/utils.js @@ -16,13 +16,36 @@ function nextLinkCheck() { return returnUpdatedDate(global.linkCheckTime, config.JDPostLinksMins) } -function get_last_downloaded(){ +function get_last_downloaded() { history = JSON.parse(fs.readFileSync('./cache/downloadHistory.json')) - last = history.slice(-1)[0] + last = history.slice(-1)[0] return last } -module.exports = { - nextRssRefresh, nextLinkCheck, get_last_downloaded +function create_empty_downloadHistory() { + try { + return JSON.parse(fs.readFileSync('./cache/downloadHistory.json')); + } catch (error) { + fs.writeFileSync('./cache/downloadHistory.json', JSON.stringify([])); + return JSON.parse(fs.readFileSync('./cache/downloadHistory.json')); + } +} + +function create_empty_retry_cache() { + try { + return JSON.parse(fs.readFileSync('./cache/retryCache.json')); + } catch (error) { + fs.writeFileSync('./cache/retryCache.json', JSON.stringify([])); + return JSON.parse(fs.readFileSync('./cache/retryCache.json')); + } +} + +function create_empty_cache_files() { + create_empty_downloadHistory() + create_empty_retry_cache() +} + +module.exports = { + nextRssRefresh, nextLinkCheck, get_last_downloaded, create_empty_cache_files } diff --git a/views/feedCache.pug b/views/feedCache.pug new file mode 100644 index 0000000..4cd5b39 --- /dev/null +++ b/views/feedCache.pug @@ -0,0 +1,26 @@ +extends layout + +block layout-content + div.View + h1.Banner Feed Cache + if (feedCache.length==0) + div.Message + h2 No shows in Feed Cache + else + div.Message + table + thead + tr + th Show Name + //- th Remove + tbody + each val, key in feedCache + tr + td + a(href=val.link + target="_blank") #{val.title} + //- td + //- a(href='/retryCache/remove?name=' + val.newtitle) Remove + div.NavButtons + a(href="/") + div.NavButton Home \ No newline at end of file diff --git a/views/index.pug b/views/index.pug index 6420fa7..c61cf0a 100644 --- a/views/index.pug +++ b/views/index.pug @@ -8,11 +8,18 @@ block layout-content h2 Number of Tracked Shows h3 #{showListLength} h2 Last Downloaded - h3 #{lastDownloaded} + h3 #{lastDownloaded} + div.Message + h2 + a(href='/feedCache') RSS Feed Cache Size + h3 #{feedCacheLength} + h2 + a(href='/retryCache') Retry Cache Size + h3 #{retryCacheLength} h2 Next RSS Refresh h3 #{rssTime} h2 Next Link Check - h3 #{linkCheck} + h3 #{linkCheck} div.NavButtons a(href="/shows") div.NavButton Show List diff --git a/views/retryCache.pug b/views/retryCache.pug new file mode 100644 index 0000000..19cbec3 --- /dev/null +++ b/views/retryCache.pug @@ -0,0 +1,26 @@ +extends layout + +block layout-content + div.View + h1.Banner Retry Cache + if (retryCache.length==0) + div.Message + h2 No shows in Retry Cache + else + div.Message + table + thead + tr + th Show Name + th Remove + tbody + each val, key in retryCache + tr + td + a(href=val.link + target="_blank") #{val.title} + td + a(href='/retryCache/remove?name=' + val.newtitle) Remove + div.NavButtons + a(href="/") + div.NavButton Home \ No newline at end of file