mirror of
				https://github.com/karl0ss/JDRssDownloader.git
				synced 2025-10-30 06:04:29 +00:00 
			
		
		
		
	express updated and telegram fixes
This commit is contained in:
		
							parent
							
								
									c3ff742bd5
								
							
						
					
					
						commit
						69460fe659
					
				| @ -3,7 +3,6 @@ const { linkAdder } = require('./JDLinkAdder'); | ||||
| const { getLinksFromURL } = require('./LinkGrabber') | ||||
| const { checkFileName } = require('./checkFileName') | ||||
| const { checkDownloadHistory } = require('./checkDownloadHistory') | ||||
| const { telegrambot } = require('./telegramCommunication') | ||||
| 
 | ||||
| async function filterFeed() { | ||||
|     let myshowlist = JSON.parse(fs.readFileSync('config.json')).Shows | ||||
| @ -54,9 +53,6 @@ async function filterFeed() { | ||||
|                             break | ||||
|                         } else { | ||||
|                             log.info(download_list.length + ' links for ' + urlObj.fileName + ' have been sent to JDdownloader.') | ||||
|                             if (TelegramBotConfig) { | ||||
|                                 telegrambot(download_list.length + ' links for ' + urlObj.fileName + ' have been sent to JDdownloader.') | ||||
|                             } | ||||
|                             linkAdder(download_list) | ||||
|                         } | ||||
|                     } else { | ||||
|  | ||||
| @ -2,21 +2,97 @@ const fs = require("fs"); | ||||
| const { feedUpdater } = require('./FeedUpdater') | ||||
| const { filterFeed } = require('./FeedFilter') | ||||
| const { telegrambot } = require('./telegramCommunication') | ||||
| const { addNewShow, removeShow } = require('./apiFunctions') | ||||
| const version = require('./package.json').version; | ||||
| 
 | ||||
| global.TelegramBotConfig = JSON.parse(fs.readFileSync('config.json')).TelegramBot | ||||
| config = JSON.parse(fs.readFileSync('config.json')) | ||||
| const express = require('express'); | ||||
| const bodyParser = require('body-parser'); | ||||
| const cors = require('cors'); | ||||
| const path = require("path"); | ||||
| const basicAuth = require('express-basic-auth') | ||||
| const app = express(); | ||||
| app.set("views", path.join(__dirname, "views")); | ||||
| app.set("view engine", "pug"); | ||||
| app.use(express.static(path.join(__dirname, "public"))); | ||||
| app.use(cors()); | ||||
| app.use(bodyParser.urlencoded({ extended: false })); | ||||
| app.use(bodyParser.json()); | ||||
| pass = config.AdminPassword | ||||
| app.use(basicAuth({ | ||||
|     users: { 'admin': pass }, | ||||
|     challenge: true, | ||||
| })) | ||||
| const port = config.WebUIPort; | ||||
| 
 | ||||
| global.log = require('simple-node-logger').createSimpleLogger({ | ||||
|     logFilePath: 'jdrssdownloader.log', | ||||
|     timestampFormat: 'YYYY-MM-DD HH:mm:ss.SSS' | ||||
| }); | ||||
| 
 | ||||
| log.info = function() { | ||||
|     var args = Array.prototype.slice.call( arguments ), | ||||
|         entry = log.log('info', args); | ||||
|     process.nextTick(function() { | ||||
|         if (config.TelegramBot) { | ||||
|             telegrambot(entry.msg[0]) | ||||
|     } | ||||
|     }); | ||||
| }; | ||||
| 
 | ||||
| log.error = function() { | ||||
|     var args = Array.prototype.slice.call( arguments ), | ||||
|         entry = log.log('error', args); | ||||
|     process.nextTick(function() { | ||||
|         if (config.TelegramBot) { | ||||
|             telegrambot(entry.msg[0]) | ||||
|     } | ||||
|     }); | ||||
| }; | ||||
| 
 | ||||
| app.get("/", (req, res) => { | ||||
|     showListLength = JSON.parse(fs.readFileSync('config.json')).Shows.length | ||||
|     res.render("index", { title: "Home", showListLength:showListLength, version:version }); | ||||
| }); | ||||
| 
 | ||||
| app.get("/shows", (req, res) => { | ||||
|     showList = JSON.parse(fs.readFileSync('config.json')).Shows | ||||
|     res.render("shows", { title: "Show List", showList: showList }); | ||||
| }); | ||||
| 
 | ||||
| app.get("/shows/add", (req, res) => { | ||||
|     res.render("addshow", { title: "Add Show" }); | ||||
| }); | ||||
| 
 | ||||
| app.get("/shows/remove", (req, res) => { | ||||
|     showList = JSON.parse(fs.readFileSync('config.json')).Shows | ||||
|     res.render("removeshow", { title: "Remove Show",  showList: showList }); | ||||
| }); | ||||
| 
 | ||||
| app.get("/logs", (req, res) => { | ||||
|     const lineReader = require("line-reader"); | ||||
|     const Promise = require("bluebird"); | ||||
|     logFile = [] | ||||
|     const eachLine = Promise.promisify(lineReader.eachLine); | ||||
|     eachLine('jdrssdownloader.log', function (line) { | ||||
|         logFile.push(line) | ||||
|     }).then(() => { | ||||
|         logFile = logFile.slice((logFile.length - 50), logFile.length) | ||||
|      res.render("logs", { title: "App Logs",  logFile: logFile }); | ||||
|     }); | ||||
| }); | ||||
| 
 | ||||
| app.post('/addNewShow', (req, res) => { | ||||
|     addNewShow(req.body) | ||||
|     res.redirect("/shows"); | ||||
| }); | ||||
| 
 | ||||
| app.post('/removeShow', (req, res) => { | ||||
|     removeShow(req.body) | ||||
|     res.redirect("/shows"); | ||||
| }); | ||||
| 
 | ||||
| async function main() { | ||||
|     log.info('Running JDRssDownloader version ' + version) | ||||
| 
 | ||||
|     if (TelegramBotConfig) { | ||||
|         telegrambot('Running JDRssDownloader version ' + version) | ||||
|     } | ||||
|     try { | ||||
|         RSSFeedRefreshMins = JSON.parse(fs.readFileSync('config.json')).RSSFeedRefreshMins | ||||
|         JDPostLinksMins = JSON.parse(fs.readFileSync('config.json')).JDPostLinksMins | ||||
| @ -24,14 +100,8 @@ async function main() { | ||||
|         log.error('config.json file is missing.') | ||||
|     } | ||||
|     log.info('Refreshing RSS Items every ' + RSSFeedRefreshMins + ' Minutes') | ||||
|     if (TelegramBotConfig) { | ||||
|         telegrambot('Refreshing RSS Items every ' + RSSFeedRefreshMins + ' Minutes') | ||||
|     } | ||||
|     log.info('Checking for links and sending to JDdownloader every ' + JDPostLinksMins + ' Minutes') | ||||
|     if (TelegramBotConfig) { | ||||
|         telegrambot('Checking for links and sending to JDdownloader every ' + JDPostLinksMins + ' Minutes') | ||||
|     } | ||||
| 
 | ||||
|     app.listen(port, () => log.info(`WebUi is listening on ${port}!`)) | ||||
|     setInterval(await feedUpdater, RSSFeedRefreshMins * 60000); | ||||
|     setInterval(await filterFeed, JDPostLinksMins * 60000); | ||||
| } | ||||
|  | ||||
							
								
								
									
										47
									
								
								apiFunctions.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										47
									
								
								apiFunctions.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,47 @@ | ||||
| const fs = require('fs'); | ||||
| const { config } = require('process'); | ||||
| 
 | ||||
| async function addNewShow(showData) { | ||||
|     let config = JSON.parse(fs.readFileSync('config.json')) | ||||
|     let exist = false | ||||
|     for (let show of config.Shows) { | ||||
|         if (show.Name == showData.showName) { | ||||
|             exist = true | ||||
|         } | ||||
|     } | ||||
|     if (exist) { | ||||
|         log.error(showData.showName + ' Already exists in list and not added') | ||||
|     } else { | ||||
|         config.Shows.push({ | ||||
|             "Name": showData.showName, | ||||
|             "Quality": showData.quality | ||||
|         }) | ||||
|         try { | ||||
|             fs.writeFileSync('config.json', JSON.stringify(config)); | ||||
|             log.info(showData.showName + ' Added to the list, checking for ' + showData.quality + 'p' ) | ||||
|         } catch (err) { | ||||
|             console.error(err); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| async function removeShow(showData) { | ||||
|     let config = JSON.parse(fs.readFileSync('config.json')) | ||||
| 
 | ||||
|     myArray = config.Shows.filter(function (obj) { | ||||
|         return obj.Name !== showData.showName; | ||||
|     }); | ||||
| 
 | ||||
|     config.Shows = myArray | ||||
|     try { | ||||
|         fs.writeFileSync('config.json', JSON.stringify(config)); | ||||
|         log.info(showData.showName + ' Removed from tracking list.' ) | ||||
|     } catch (err) { | ||||
|         console.error(err); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| module.exports = { | ||||
|     addNewShow, removeShow | ||||
| } | ||||
| 
 | ||||
| @ -1,6 +1,8 @@ | ||||
| { | ||||
|     "JDUserName": "", | ||||
|     "JDPassword": "", | ||||
|     "AdminPassword":"", | ||||
|     "WebUIPort": 3100, | ||||
|     "RSSFeed": "", | ||||
|     "RSSFeedRefreshMins": 10, | ||||
|     "JDPostLinksMins": 180, | ||||
|  | ||||
| @ -12,9 +12,14 @@ | ||||
|   "dependencies": { | ||||
|     "axios": "^0.27.2", | ||||
|     "cheerio": "^1.0.0-rc.11", | ||||
|     "cors": "^2.8.5", | ||||
|     "express": "^4.18.2", | ||||
|     "express-basic-auth": "^1.2.1", | ||||
|     "jdownloader-client": "^1.0.0", | ||||
|     "line-reader": "^0.4.0", | ||||
|     "lodash": "^4.17.21", | ||||
|     "node-telegram-bot-api": "^0.59.0", | ||||
|     "pug": "^3.0.2", | ||||
|     "rss-parser": "^3.12.0", | ||||
|     "simple-node-logger": "^21.8.12" | ||||
|   }, | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user