-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapiFunctions.js
84 lines (71 loc) · 2.22 KB
/
apiFunctions.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
const fs = require('fs');
async function addNewShow(showData) {
let shows = JSON.parse(fs.readFileSync('shows.json'))
let exist = false
for (let show of shows) {
if (show.Name == showData.showName) {
exist = true
}
}
if (exist) {
log.error(showData.showName + ' Already exists in list and not added')
} else {
shows.push({
"Name": showData.showName,
"Quality": showData.quality
})
try {
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);
}
}
}
async function removeShow(showData) {
let shows = JSON.parse(fs.readFileSync('shows.json'))
myArray = shows.filter(function (obj) {
return obj.Name !== showData.showName;
});
shows = myArray
try {
fs.writeFileSync('shows.json', JSON.stringify(shows));
log.info(showData.showName + ' Removed from tracking list.')
} catch (err) {
console.error(err);
}
}
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);
}
}
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
}