@@ -31,6 +31,12 @@ const options = yargs(hideBin(process.argv))
3131 type : 'string' ,
3232 description : 'mode'
3333 } )
34+ . option ( 'cacheMode' , {
35+ demandOption : false ,
36+ alias : 'f' ,
37+ type : 'string' ,
38+ description : 'Cache mode for fetching data'
39+ } )
3440 . epilog ( 'Pulls GetCapabilities XML and linked metadata from configured locations' )
3541
3642const { argv } = options
@@ -39,6 +45,7 @@ if (!argv.config && !argv.getcapabilities) {
3945}
4046const configFile = argv . config
4147const outputDir = argv . getcapabilities
48+ const cacheMode = argv . cacheMode
4249const colormaps = { }
4350const vectorstyles = { }
4451const vectordata = { }
@@ -49,6 +56,17 @@ const vectordataDir = path.join(outputDir, 'vectordata')
4956const configData = fs . readFileSync ( configFile )
5057const config = JSON . parse ( configData )
5158
59+ let headers = { }
60+
61+ if ( cacheMode === 'no-store' ) {
62+ const noCacheHeaders = {
63+ 'Cache-Control' : 'no-cache no-store' ,
64+ Pragma : 'no-cache' ,
65+ Expires : '0'
66+ }
67+ headers = Object . assign ( headers , noCacheHeaders )
68+ }
69+
5270async function main ( ) {
5371 if ( ! fs . existsSync ( outputDir ) ) {
5472 fs . mkdirSync ( outputDir )
@@ -81,17 +99,17 @@ async function getCapabilities () {
8199// convert to superagent and use promises
82100async function fetchConfigs ( inputFile , outputFile ) {
83101 const writer = await fs . createWriteStream ( outputFile )
84- if ( argv . mode === 'verbose' ) console . warn ( ` ${ prog } : Fetching ${ inputFile } ...`)
85- return axios ( {
102+ if ( argv . mode === 'verbose' ) console . trace ( ` Fetching ${ inputFile } ...`)
103+ const response = await axios ( {
86104 method : 'get' ,
87105 url : inputFile ,
88106 responseType : 'stream' ,
89- timeout : 100000
90- } ) . then ( async ( response ) => {
91- if ( argv . mode === 'verbose' ) console . warn ( `${ prog } : Writing ${ outputFile } ...` )
92- await response . data . pipe ( writer )
93- return finished ( writer )
107+ timeout : 100000 ,
108+ headers
94109 } )
110+ if ( argv . mode === 'verbose' ) console . trace ( `Writing ${ outputFile } ...` )
111+ await response . data . pipe ( writer )
112+ return finished ( writer )
95113}
96114
97115async function handleException ( error , link , dir , ext , count ) {
@@ -113,7 +131,7 @@ async function processVectorData (layer) {
113131 Object . values ( layer [ 'ows:Metadata' ] ) . forEach ( ( item ) => {
114132 const schemaVersion = item . _attributes [ 'xlink:role' ]
115133 if ( schemaVersion === 'http://earthdata.nasa.gov/gibs/metadata-type/layer/1.0' ) {
116- if ( argv . mode === 'verbose' ) console . warn ( ` Processing Metadata: ${ item . _attributes [ 'xlink:href' ] } ` )
134+ if ( argv . mode === 'verbose' ) console . trace ( ` Processing Metadata: ${ item . _attributes [ 'xlink:href' ] } ` )
117135 const vectorDataLink = item . _attributes [ 'xlink:href' ]
118136 const vectorDataFile = path . basename ( vectorDataLink )
119137 const vectorDataId = path . parse ( vectorDataFile ) . name
@@ -125,13 +143,13 @@ async function processVectorData (layer) {
125143
126144async function processLayer ( layer ) {
127145 const ident = layer [ 'ows:Identifier' ] . _text
128- if ( argv . mode === 'verbose' ) console . warn ( `Processing layer ${ ident } ...` )
146+ if ( argv . mode === 'verbose' ) console . trace ( `Processing layer ${ ident } ...` )
129147 if ( layer [ 'ows:Metadata' ] ) {
130148 if ( config . skipPalettes ) {
131149 console . warn ( `${ prog } : WARN: Skipping palette for ${ ident } \n` )
132150 } else {
133151 Object . values ( layer [ 'ows:Metadata' ] ) . forEach ( ( item ) => {
134- if ( argv . mode === 'verbose' ) console . warn ( ` Processing pallette: ${ item . _attributes [ 'xlink:href' ] } ` )
152+ if ( argv . mode === 'verbose' ) console . trace ( ` Processing pallette: ${ item . _attributes [ 'xlink:href' ] } ` )
135153 const schemaVersion = item . _attributes [ 'xlink:role' ]
136154 if ( schemaVersion === 'http://earthdata.nasa.gov/gibs/metadata-type/colormap/1.3' ) {
137155 const colormapLink = item . _attributes [ 'xlink:href' ]
0 commit comments