wiseService/wiseSource.js
/**
   * Download a url and save to a file, if we already have the file and less than a minute old use that file.
   *
   * @param {string} url - The URL to download
   * @param {string} file - The file to save the results to
   * @param {function} cb - (statusCode) The stats code result from the download
   */
Download a url and save to a file, if we already have the file and less than a minute old use that file.
@param {string} url - The URL to download
@param {string} file - The file to save the results to
@param {function} cb - (statusCode) The stats code result from the download
Download a url and save to a file if we already have the file and less than a minute old use that file . @param { string } url - The URL to download @param { string } file - The file to save the results to @param { function } cb - ( statusCode ) The stats code result from the download
static request (url, file, cb) {
    const headers = {};
    if (file) {
      if (fs.existsSync(file)) {
        const stat = fs.statSync(file);
        if (Date.now() - stat.mtime.getTime() < 60000) {
          return setImmediate(cb, 304);
        }
        headers['If-Modified-Since'] = stat.mtime.toUTCString();
      }
    }
    let statusCode;
    console.log(url);
    request({ url: url, headers: headers })
      .on('response', function (response) {
        statusCode = response.statusCode;
        if (response.statusCode === 200) {
          this.pipe(fs.createWriteStream(file));
        }
      })
      .on('error', (error) => {
        console.log(error);
      })
      .on('end', () => {
        setTimeout(cb, 100, statusCode);
      });
  }
static request ( url , file , cb ) { const headers = { } ; if ( file ) { if ( fs . existsSync ( file ) ) { const stat = fs . statSync ( file ) ; if ( Date . now ( ) - stat . mtime . getTime ( ) < 60000 ) { return setImmediate ( cb , 304 ) ; } headers [ 'If-Modified-Since' ] = stat . mtime . toUTCString ( ) ; } } let statusCode ; console . log ( url ) ; request ( { url : url , headers : headers } ) . on ( 'response' , function ( response ) { statusCode = response . statusCode ; if ( response . statusCode === 200 ) { this . pipe ( fs . createWriteStream ( file ) ) ; } } ) . on ( 'error' , ( error ) => { console . log ( error ) ; } ) . on ( 'end' , ( ) => { setTimeout ( cb , 100 , statusCode ) ; } ) ; }
Download a url and save to a file, if we already have the file and less than a minute old use that file.
Download a url and save to a file if we already have the file and less than a minute old use that file .
// Don't download again if file is less then 1 minutes old