@@ -7,6 +7,14 @@ const fetch = (...args) => import('node-fetch').then(({
7
7
let databaseLanguages = [ ] ;
8
8
let frontendLanguages = [ ] ;
9
9
10
+ let info = { }
11
+
12
+ let access_token = '' ;
13
+
14
+ if ( process . argv . length >= 3 ) {
15
+ info = JSON . parse ( process . argv [ 2 ] ) ;
16
+ }
17
+
10
18
function hasChanges ( objectOne , objectTwo ) {
11
19
var len ;
12
20
const ref = [ "conceptName" , "conceptURI" , "conceptSource" , "_standard" , "_fulltext" , "facetTerm" , "frontendLanguage" ] ;
@@ -19,6 +27,28 @@ function hasChanges(objectOne, objectTwo) {
19
27
return false ;
20
28
}
21
29
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
+
22
52
main = ( payload ) => {
23
53
switch ( payload . action ) {
24
54
case "start_update" :
@@ -186,61 +216,71 @@ outputErr = (err2) => {
186
216
187
217
process . stdin . setEncoding ( 'utf8' ) ;
188
218
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
+
246
286
} ) ( ) ;
0 commit comments