Skip to content

Commit e1c4b13

Browse files
committed
update timerange check for updater
1 parent 30c66bc commit e1c4b13

1 file changed

Lines changed: 39 additions & 27 deletions

File tree

src/updater/GFBIOUpdater.js

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ let info = {}
1414
let access_token = '';
1515

1616
if (process.argv.length >= 3) {
17-
info = JSON.parse(process.argv[2])
17+
info = JSON.parse(process.argv[2])
1818
}
1919

2020
function hasChanges(objectOne, objectTwo) {
@@ -30,25 +30,37 @@ function hasChanges(objectOne, objectTwo) {
3030
}
3131

3232
function getConfigFromAPI() {
33-
return new Promise((resolve, reject) => {
34-
var url = 'http://fylr.localhost:8081/api/v1/config?access_token=' + access_token
35-
fetch(url, {
36-
headers: {
37-
'Accept': 'application/json'
38-
},
39-
})
40-
.then(response => {
41-
if (response.ok) {
42-
resolve(response.json());
43-
} else {
44-
console.error("DANTE-Updater: Fehler bei der Anfrage an /config ");
45-
}
46-
})
47-
.catch(error => {
48-
console.error(error);
49-
console.error("DANTE-Updater: Fehler bei der Anfrage an /config");
50-
});
51-
});
33+
return new Promise((resolve, reject) => {
34+
var url = 'http://fylr.localhost:8081/api/v1/config?access_token=' + access_token
35+
fetch(url, {
36+
headers: {
37+
'Accept': 'application/json'
38+
},
39+
})
40+
.then(response => {
41+
if (response.ok) {
42+
resolve(response.json());
43+
} else {
44+
console.error("DANTE-Updater: Fehler bei der Anfrage an /config ");
45+
}
46+
})
47+
.catch(error => {
48+
console.error(error);
49+
console.error("DANTE-Updater: Fehler bei der Anfrage an /config");
50+
});
51+
});
52+
}
53+
54+
function isInTimeRange(currentHour, fromHour, toHour) {
55+
if (fromHour === toHour) {
56+
return true;
57+
}
58+
59+
if (fromHour < toHour) { // same day
60+
return currentHour >= fromHour && currentHour < toHour;
61+
} else { // through the night
62+
return currentHour >= fromHour || currentHour < toHour;
63+
}
5264
}
5365

5466
main = (payload) => {
@@ -98,7 +110,7 @@ main = (payload) => {
98110
requestUrls.push(hierarchieRequest);
99111
});
100112

101-
Promise.all(requestUrls).then(function(responses) {
113+
Promise.all(requestUrls).then(function (responses) {
102114
let results = [];
103115
// Get a JSON object from each of the responses
104116
responses.forEach((response, index) => {
@@ -120,7 +132,7 @@ main = (payload) => {
120132
results.push(result);
121133
});
122134
return Promise.all(results.map(result => result.data));
123-
}).then(function(data) {
135+
}).then(function (data) {
124136
let results = [];
125137
data.forEach((data, index) => {
126138
let url = requests[index].url;
@@ -160,7 +172,7 @@ main = (payload) => {
160172
if (resultJSON) {
161173
// get desired language for preflabel. This is frontendlanguage from original data...
162174
let desiredLanguage = 'de';
163-
if(originalCdata?.frontendLanguage?.length == 2) {
175+
if (originalCdata?.frontendLanguage?.length == 2) {
164176
desiredLanguage = originalCdata.frontendLanguage;
165177
}
166178
// save conceptName
@@ -272,21 +284,21 @@ outputErr = (err2) => {
272284
const now = new Date();
273285
const hour = now.getHours();
274286
// check if hours do not match
275-
if (hour < gfbio_config.from_time && hour >= gfbio_config.to_time) {
287+
if (!isInTimeRange(hour, gfbio_config.from_time, gfbio_config.to_time)) {
276288
// exit if hours do not match
277289
outputData({
278290
"state": {
279291
"theend": 2,
280292
"log": ["hours do not match, cancel update"]
281293
}
282294
});
283-
}
295+
}
284296
}
285297
}
286-
298+
287299
access_token = info && info.plugin_user_access_token;
288300

289-
if(access_token) {
301+
if (access_token) {
290302

291303
////////////////////////////////////////////////////////////////////////////
292304
// get config and read the languages

0 commit comments

Comments
 (0)