JDRssDownloader/utils.js

62 lines
1.7 KiB
JavaScript
Raw Normal View History

2022-10-25 16:41:45 +01:00
const fs = require('fs');
config = JSON.parse(fs.readFileSync('config.json'))
var moment = require('moment');
function returnUpdatedDate(date, offset) {
var newDate = moment(date);
newDate.add(offset, 'm');
return new moment(newDate).format("ddd, LTS")
}
2022-10-25 16:41:45 +01:00
function nextRssRefresh() {
return returnUpdatedDate(global.rssRefreshTime, config.RSSFeedRefreshMins)
2022-10-25 16:41:45 +01:00
}
function nextLinkCheck() {
return returnUpdatedDate(global.linkCheckTime, config.JDPostLinksMins)
2022-10-25 16:41:45 +01:00
}
2023-01-24 12:04:14 +00:00
function get_last_downloaded() {
history = JSON.parse(fs.readFileSync('./cache/downloadHistory.json'))
2023-01-24 12:04:14 +00:00
last = history.slice(-1)[0]
return last
}
2023-01-24 12:04:14 +00:00
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_shows_file() {
try {
return JSON.parse(fs.readFileSync('./shows.json'));
} catch (error) {
fs.writeFileSync('./shows.json', JSON.stringify([]));
return JSON.parse(fs.readFileSync('./shows.json'));
}
}
2023-01-24 12:04:14 +00:00
function create_empty_cache_files() {
create_empty_downloadHistory()
create_empty_retry_cache()
create_empty_shows_file()
2023-01-24 12:04:14 +00:00
}
2022-10-25 16:41:45 +01:00
module.exports = {
2023-01-24 12:04:14 +00:00
nextRssRefresh, nextLinkCheck, get_last_downloaded, create_empty_cache_files
2022-10-25 16:41:45 +01:00
}