@@ -3,32 +3,31 @@ const yargs = require('yargs');
3
3
const fs = require ( 'fs' ) ;
4
4
const linksProcess = require ( './sitemapIndex' ) ;
5
5
const axios = require ( 'axios' ) ;
6
- const axiosRetry = require ( 'axios-retry' ) ;
7
6
const https = require ( 'https' ) ;
8
7
9
8
10
9
const argv = yargs
11
- . option ( 'api' , {
12
- alias : 'a' ,
13
- description : 'Base URL for the catalog search api, e.g. http://localhost/onestop-search' ,
14
- type : 'string' ,
15
- required : true
16
- } )
17
- . option ( 'website' , {
18
- alias : 'w' ,
19
- description : 'Base URL for the catalog web page, e.g. http://localhost/onestop' ,
20
- type : 'string' ,
21
- required : true
22
- } )
23
- . option ( 'pageSize' , {
24
- alias : 'n' ,
25
- description : 'Number of collections to request at a time' ,
26
- type : 'number' ,
27
- default : 10
28
- } )
29
- . help ( )
30
- . alias ( 'help' , 'h' )
31
- . argv ;
10
+ . option ( 'api' , {
11
+ alias : 'a' ,
12
+ description : 'Base URL for the catalog search api, e.g. http://localhost/onestop-search' ,
13
+ type : 'string' ,
14
+ required : true
15
+ } )
16
+ . option ( 'website' , {
17
+ alias : 'w' ,
18
+ description : 'Base URL for the catalog web page, e.g. http://localhost/onestop' ,
19
+ type : 'string' ,
20
+ required : true
21
+ } )
22
+ . option ( 'pageSize' , {
23
+ alias : 'n' ,
24
+ description : 'Number of collections to request at a time' ,
25
+ type : 'number' ,
26
+ default : 10
27
+ } )
28
+ . help ( )
29
+ . alias ( 'help' , 'h' )
30
+ . argv ;
32
31
33
32
34
33
//TODO - When pulling from cedar devs update API URL new path
@@ -48,46 +47,51 @@ let options = {
48
47
} ,
49
48
data : {
50
49
"summary" : false ,
51
- "sort" : [ { "stagedDate" : "asc" } ] ,
50
+ "sort" : [ {
51
+ "stagedDate" : "asc"
52
+ } ] ,
52
53
"search_after" : [ 0 ] ,
53
54
"queries" : [ ] ,
54
- "page" : { "max" : pageSize }
55
+ "page" : {
56
+ "max" : pageSize
57
+ }
55
58
}
56
59
} ;
57
60
58
61
//recursively pages API
59
- let pageApi = async function ( options , collectionList ) {
62
+ let pageApi = async function ( options , collectionList ) {
60
63
console . log ( "Requesting page for data after: " + options . data . search_after [ 0 ] ) ;
61
64
await axios ( options )
62
- . then ( ( response ) => {
63
- console . log ( "Response status: " + response . status ) ;
64
- if ( response . status == 200 ) {
65
- let body = response . data ;
66
- //If we got data back, process it and then keep going until we dont have anymore data
67
- // TODO catch body.error
68
- if ( body && body . data . length > 0 ) {
69
- //grab the last staged date, we will need it for the subsequent request
70
- const lastStagedDate = body . data [ body . data . length - 1 ] . attributes . stagedDate ;
71
- //update the options
72
- options . data . search_after = [ lastStagedDate ] ;
73
- //create the data structure we need for the sitemap tool
74
- var bodyDataObjectList = processBodyData ( body ) ;
75
- //add it to the list
76
- collectionList = [ ...collectionList , ...bodyDataObjectList ] ;
77
- console . log ( "Received " + body . data . length + " items, continue paging..." ) ;
78
- //get the next page
79
- collectionList = pageApi ( options , collectionList )
80
- } else {
81
- console . log ( "No more data. Generating sitemap..." ) ;
82
- }
65
+ . then ( ( response ) => {
66
+ console . log ( "Response status: " + response . status ) ;
67
+ if ( response . status == 200 ) {
68
+ let body = response . data ;
69
+ //If we got data back, process it and then keep going until we dont have anymore data
70
+ // TODO catch body.error. Check if response status is not 200
71
+ if ( body && body . data . length > 0 ) {
72
+ //grab the last staged date, we will need it for the subsequent request
73
+ const lastStagedDate = body . data [ body . data . length - 1 ] . attributes . stagedDate ;
74
+ //update the options
75
+ options . data . search_after = [ lastStagedDate ] ;
76
+ //create the data structure we need for the sitemap tool
77
+ var bodyDataObjectList = processBodyData ( body ) ;
78
+ //add it to the list
79
+ collectionList = [ ...collectionList , ...bodyDataObjectList ] ;
80
+ console . log ( "Received " + body . data . length + " items, continue paging..." ) ;
81
+ //get the next page
82
+ collectionList = pageApi ( options , collectionList )
83
+ } else {
84
+ console . log ( "No more data. Generating sitemap..." ) ;
83
85
}
84
- } )
85
- . catch ( function ( error ) {
86
- console . log ( "ERROR" ) ;
87
- console . log ( error ) ;
88
- } ) ;
89
- return collectionList ;
86
+ }
87
+ } )
88
+ //TODO - Future story more error handling
89
+ . catch ( function ( error ) {
90
+ console . log ( "ERROR" ) ;
91
+ console . log ( error ) ;
92
+ } ) ;
93
+ return collectionList ;
90
94
}
91
95
92
96
//page the api, create sitemap
93
- pageApi ( options , [ ] ) . then ( ( listOfLinks ) => linksProcess ( listOfLinks ) ) ;
97
+ pageApi ( options , [ ] ) . then ( ( listOfLinks ) => linksProcess ( listOfLinks ) ) ;
0 commit comments