-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.js
61 lines (51 loc) · 1.71 KB
/
utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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")
}
function nextRssRefresh() {
return returnUpdatedDate(global.rssRefreshTime, config.RSSFeedRefreshMins)
}
function nextLinkCheck() {
return returnUpdatedDate(global.linkCheckTime, config.JDPostLinksMins)
}
function get_last_downloaded() {
history = JSON.parse(fs.readFileSync('./cache/downloadHistory.json'))
last = history.slice(-1)[0]
return last
}
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'));
}
}
function create_empty_cache_files() {
create_empty_downloadHistory()
create_empty_retry_cache()
create_empty_shows_file()
}
module.exports = {
nextRssRefresh, nextLinkCheck, get_last_downloaded, create_empty_cache_files
}