Skip to content

Commit 60bd10c

Browse files
fixed updater after 6.8.1 info removal
1 parent bf1de14 commit 60bd10c

File tree

2 files changed

+99
-57
lines changed

2 files changed

+99
-57
lines changed

manifest.master.yml

100644100755
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ custom_types:
4141
type: text
4242

4343
update:
44+
plugin_user:
45+
reference: system:root
4446
exec:
4547
service: "node"
4648
commands:

src/updater/k10plusUpdater.js

100644100755
Lines changed: 97 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ const fetch = (...args) => import('node-fetch').then(({
77
let databaseLanguages = [];
88
let frontendLanguages = [];
99

10+
let info = {}
11+
12+
let access_token = '';
13+
14+
if (process.argv.length >= 3) {
15+
info = JSON.parse(process.argv[2]);
16+
}
17+
1018
function hasChanges(objectOne, objectTwo) {
1119
var len;
1220
const ref = ["conceptName", "conceptURI", "conceptSource", "_standard", "_fulltext", "facetTerm", "frontendLanguage"];
@@ -19,6 +27,28 @@ function hasChanges(objectOne, objectTwo) {
1927
return false;
2028
}
2129

30+
function getConfigFromAPI() {
31+
return new Promise((resolve, reject) => {
32+
var url = 'http://fylr.localhost:8081/api/v1/config?access_token=' + access_token
33+
fetch(url, {
34+
headers: {
35+
'Accept': 'application/json'
36+
},
37+
})
38+
.then(response => {
39+
if (response.ok) {
40+
resolve(response.json());
41+
} else {
42+
console.error("Getty-Updater: Fehler bei der Anfrage an /config ");
43+
}
44+
})
45+
.catch(error => {
46+
console.error(error);
47+
console.error("Getty-Updater: Fehler bei der Anfrage an /config");
48+
});
49+
});
50+
}
51+
2252
main = (payload) => {
2353
switch (payload.action) {
2454
case "start_update":
@@ -186,61 +216,71 @@ outputErr = (err2) => {
186216

187217
process.stdin.setEncoding('utf8');
188218

189-
////////////////////////////////////////////////////////////////////////////
190-
// get config and read the languages
191-
////////////////////////////////////////////////////////////////////////////
192-
193-
let config = JSON.parse(process.argv[2]);
194-
195-
// database-languages
196-
databaseLanguages = config.config.system.config.languages.database;
197-
databaseLanguages = databaseLanguages.map((value, key, array) => {
198-
return value.value;
199-
});
200-
201-
// frontend-languages
202-
frontendLanguages = config.config.system.config.languages.frontend;
203-
204-
////////////////////////////////////////////////////////////////////////////
205-
// availabilityCheck for k10plus-api
206-
////////////////////////////////////////////////////////////////////////////
207-
let testURL = 'https://ws.gbv.de/suggest/csl2?query=pica.tit=Nacht&citationstyle=ieee&language=de&count=3';
208-
209-
https.get(testURL, res => {
210-
let testData = [];
211-
res.on('data', chunk => {
212-
testData.push(chunk);
213-
});
214-
res.on('end', () => {
215-
testData = Buffer.concat(testData).toString();
216-
const testJSON = JSON.parse(testData);
217-
if (testJSON && testData.includes('Nacht')) {
218-
////////////////////////////////////////////////////////////////////////////
219-
// test successfull --> continue with custom-data-type-update
220-
////////////////////////////////////////////////////////////////////////////
221-
process.stdin.on('readable', () => {
222-
let chunk;
223-
while ((chunk = process.stdin.read()) !== null) {
224-
data = data + chunk
225-
}
226-
});
227-
process.stdin.on('end', () => {
228-
///////////////////////////////////////
229-
// continue with update-routine
230-
///////////////////////////////////////
231-
try {
232-
let payload = JSON.parse(data)
233-
main(payload)
234-
} catch (error) {
235-
console.error("caught error", error)
236-
outputErr(error)
237-
}
238-
});
239-
} else {
240-
console.error('Error while interpreting data from k10plus-API.');
241-
}
242-
});
243-
}).on('error', err => {
244-
console.error('Error while receiving data from k10plus-API: ', err.message);
245-
});
219+
access_token = info && info.plugin_user_access_token;
220+
221+
if(access_token) {
222+
223+
////////////////////////////////////////////////////////////////////////////
224+
// get config and read the languages
225+
////////////////////////////////////////////////////////////////////////////
226+
227+
getConfigFromAPI().then(config => {
228+
databaseLanguages = config.system.config.languages.database;
229+
databaseLanguages = databaseLanguages.map((value, key, array) => {
230+
return value.value;
231+
});
232+
233+
frontendLanguages = config.system.config.languages.frontend;
234+
235+
236+
////////////////////////////////////////////////////////////////////////////
237+
// availabilityCheck for k10plus-api
238+
////////////////////////////////////////////////////////////////////////////
239+
let testURL = 'https://ws.gbv.de/suggest/csl2?query=pica.tit=Nacht&citationstyle=ieee&language=de&count=3';
240+
241+
https.get(testURL, res => {
242+
let testData = [];
243+
res.on('data', chunk => {
244+
testData.push(chunk);
245+
});
246+
res.on('end', () => {
247+
testData = Buffer.concat(testData).toString();
248+
const testJSON = JSON.parse(testData);
249+
if (testJSON && testData.includes('Nacht')) {
250+
////////////////////////////////////////////////////////////////////////////
251+
// test successfull --> continue with custom-data-type-update
252+
////////////////////////////////////////////////////////////////////////////
253+
process.stdin.on('readable', () => {
254+
let chunk;
255+
while ((chunk = process.stdin.read()) !== null) {
256+
data = data + chunk
257+
}
258+
});
259+
process.stdin.on('end', () => {
260+
///////////////////////////////////////
261+
// continue with update-routine
262+
///////////////////////////////////////
263+
try {
264+
let payload = JSON.parse(data)
265+
main(payload)
266+
} catch (error) {
267+
console.error("caught error", error)
268+
outputErr(error)
269+
}
270+
});
271+
} else {
272+
console.error('Error while interpreting data from k10plus-API.');
273+
}
274+
});
275+
}).on('error', err => {
276+
console.error('Error while receiving data from k10plus-API: ', err.message);
277+
});
278+
}).catch(error => {
279+
console.error('Es gab einen Fehler beim Laden der Konfiguration:', error);
280+
});
281+
}
282+
else {
283+
console.error("kein Accesstoken gefunden");
284+
}
285+
246286
})();

0 commit comments

Comments
 (0)