From bb2e58e624d14fd875ba39146ed784549a4dda71 Mon Sep 17 00:00:00 2001 From: Karl0ss Date: Thu, 27 Oct 2022 13:58:36 +0100 Subject: [PATCH] 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