Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

update package-lock.json

Ed Platoa42f9c4bf397
diff --git a/.gitignore b/.gitignore
index d0212959c..a1c926980 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,6 +3,7 @@
/dist
/node_modules
/web/ext/node_modules/*
+/tasks/link-check/results
python
.python/
.node-virtualenv/
diff --git a/package-lock.json b/package-lock.json
index a4e4829d7..04abf924f 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -4,6 +4,12 @@
"lockfileVersion": 1,
"requires": true,
"dependencies": {
+ "@types/node": {
+ "version": "10.3.2",
+ "resolved": "https://registry.npmjs.org/@types/node/-/node-10.3.2.tgz",
+ "integrity": "sha512-9NfEUDp3tgRhmoxzTpTo+lq+KIVFxZahuRX0LHF/9IzKHaWuoWsIrrJ61zw5cnnlGINX8lqJzXYfQTOICS5Q+A==",
+ "dev": true
+ },
"JSONStream": {
"version": "1.3.2",
"resolved": "https://registry.npmjs.org/JSONStream/-/JSONStream-1.3.2.tgz",
@@ -1470,6 +1476,12 @@
"integrity": "sha512-ItfYfPLkWHUjckQCk8xC+LwxgK8NYcXywGigJgSwOP8Y2iyWT4f2vsZnoOXTTbo+o5yXmIUJ4gn5538SO5S3gA==",
"dev": true
},
+ "boolbase": {
+ "version": "1.0.0",
+ "resolved": "https://registry.npmjs.org/boolbase/-/boolbase-1.0.0.tgz",
+ "integrity": "sha1-aN/1++YMUes3cl6p4+0xDcwed24=",
+ "dev": true
+ },
"boom": {
"version": "4.3.1",
"resolved": "https://registry.npmjs.org/boom/-/boom-4.3.1.tgz",
@@ -2482,6 +2494,31 @@
"integrity": "sha1-tUc7M9yXxCTl2Y3IfVXU2KKci/I=",
"dev": true
},
+ "cheerio": {
+ "version": "1.0.0-rc.2",
+ "resolved": "https://registry.npmjs.org/cheerio/-/cheerio-1.0.0-rc.2.tgz",
+ "integrity": "sha1-S59TqBsn5NXawxwP/Qz6A8xoMNs=",
+ "dev": true,
+ "requires": {
+ "css-select": "~1.2.0",
+ "dom-serializer": "~0.1.0",
+ "entities": "~1.1.1",
+ "htmlparser2": "^3.9.1",
+ "lodash": "^4.15.0",
+ "parse5": "^3.0.1"
+ },
+ "dependencies": {
+ "parse5": {
+ "version": "3.0.3",
+ "resolved": "https://registry.npmjs.org/parse5/-/parse5-3.0.3.tgz",
+ "integrity": "sha512-rgO9Zg5LLLkfJF9E6CCmXlSE4UVceloys8JrFqCcHloC3usd/kJCyPDwH2SOlzix2j3xaP9sUX3e8+kvkuleAA==",
+ "dev": true,
+ "requires": {
+ "@types/node": "*"
+ }
+ }
+ }
+ },
"chokidar": {
"version": "1.7.0",
"resolved": "https://registry.npmjs.org/chokidar/-/chokidar-1.7.0.tgz",
@@ -3424,6 +3461,18 @@
}
}
},
+ "css-select": {
+ "version": "1.2.0",
+ "resolved": "https://registry.npmjs.org/css-select/-/css-select-1.2.0.tgz",
+ "integrity": "sha1-KzoRBTnFNV8c2NMUYj6HCxIeyFg=",
+ "dev": true,
+ "requires": {
+ "boolbase": "~1.0.0",
+ "css-what": "2.1",
+ "domutils": "1.5.1",
+ "nth-check": "~1.0.1"
+ }
+ },
"css-tokenize": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/css-tokenize/-/css-tokenize-1.0.1.tgz",
@@ -3434,6 +3483,12 @@
"readable-stream": "^1.0.33"
}
},
+ "css-what": {
+ "version": "2.1.0",
+ "resolved": "https://registry.npmjs.org/css-what/-/css-what-2.1.0.tgz",
+ "integrity": "sha1-lGfQMsOM+u+58teVASUwYvh/ob0=",
+ "dev": true
+ },
"cssnano": {
"version": "3.10.0",
"resolved": "https://registry.npmjs.org/cssnano/-/cssnano-3.10.0.tgz",
@@ -4447,13 +4502,11 @@
"integrity": "sha1-rT/0yG7C0CkyL1oCw6mmBslbP1k=",
"dev": true
},
- "encoding": {
- "version": "0.1.12",
- "resolved": "https://registry.npmjs.org/encoding/-/encoding-0.1.12.tgz",
- "integrity": "sha1-U4tm8+5izRq1HsMjgp0flIDHS+s=",
- "requires": {
- "iconv-lite": "~0.4.13"
- }
+ "entities": {
+ "version": "1.1.1",
+ "resolved": "https://registry.npmjs.org/entities/-/entities-1.1.1.tgz",
+ "integrity": "sha1-blwtClYhtdra7O+AuQ7ftc13cvA=",
+ "dev": true
},
"error-ex": {
"version": "1.3.1",
@@ -7666,6 +7719,52 @@
"integrity": "sha1-OgPtwiFLyjtmQko+eVk0lQnLA1E=",
"dev": true
},
+ "htmlparser2": {
+ "version": "3.9.2",
+ "resolved": "https://registry.npmjs.org/htmlparser2/-/htmlparser2-3.9.2.tgz",
+ "integrity": "sha1-G9+HrMoPP55T+k/M6w9LTLsAszg=",
+ "dev": true,
+ "requires": {
+ "domelementtype": "^1.3.0",
+ "domhandler": "^2.3.0",
+ "domutils": "^1.5.1",
+ "entities": "^1.1.1",
+ "inherits": "^2.0.1",
+ "readable-stream": "^2.0.2"
+ },
+ "dependencies": {
+ "isarray": {
+ "version": "1.0.0",
+ "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
+ "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=",
+ "dev": true
+ },
+ "readable-stream": {
+ "version": "2.3.6",
+ "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz",
+ "integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==",
+ "dev": true,
+ "requires": {
+ "core-util-is": "~1.0.0",
+ "inherits": "~2.0.3",
+ "isarray": "~1.0.0",
+ "process-nextick-args": "~2.0.0",
+ "safe-buffer": "~5.1.1",
+ "string_decoder": "~1.1.1",
+ "util-deprecate": "~1.0.1"
+ }
+ },
+ "string_decoder": {
+ "version": "1.1.1",
+ "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz",
+ "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==",
+ "dev": true,
+ "requires": {
+ "safe-buffer": "~5.1.0"
+ }
+ }
+ }
+ },
"http-basic": {
"version": "2.5.1",
"resolved": "https://registry.npmjs.org/http-basic/-/http-basic-2.5.1.tgz",
@@ -8332,7 +8431,8 @@
"is-stream": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz",
- "integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ="
+ "integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ=",
+ "dev": true
},
"is-supported-regexp-flag": {
"version": "1.0.1",
@@ -8408,7 +8508,6 @@
"resolved": "https://registry.npmjs.org/isomorphic-fetch/-/isomorphic-fetch-2.2.1.tgz",
"integrity": "sha1-YRrhrPFPXoH3KVB0coGf6XM1WKk=",
"requires": {
- "node-fetch": "^1.0.1",
"whatwg-fetch": ">=0.10.0"
}
},
@@ -9831,13 +9930,10 @@
}
},
"node-fetch": {
- "version": "1.7.3",
- "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-1.7.3.tgz",
- "integrity": "sha512-NhZ4CsKx7cYm2vSrBAr2PvFOe6sWDf0UYLRqA6svUYg7+/TSfVAu49jYC4BvQ4Sms9SZgdqGBgroqfDhJdTyKQ==",
- "requires": {
- "encoding": "^0.1.11",
- "is-stream": "^1.0.1"
- }
+ "version": "2.1.2",
+ "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.1.2.tgz",
+ "integrity": "sha1-q4hOjn5X44qUR1POxwb3iNF2i7U=",
+ "dev": true
},
"node-ssh": {
"version": "5.1.1",
@@ -10209,6 +10305,15 @@
"uid-number": "0.0.5"
}
},
+ "nth-check": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/nth-check/-/nth-check-1.0.1.tgz",
+ "integrity": "sha1-mSms32KPwsQQmN6rgqxYDPFJquQ=",
+ "dev": true,
+ "requires": {
+ "boolbase": "~1.0.0"
+ }
+ },
"num2fraction": {
"version": "1.2.2",
"resolved": "https://registry.npmjs.org/num2fraction/-/num2fraction-1.2.2.tgz",
@@ -13111,14 +13216,6 @@
"requires": {
"psl": "^1.1.24",
"punycode": "^1.4.1"
- },
- "dependencies": {
- "psl": {
- "version": "1.1.28",
- "resolved": "https://registry.npmjs.org/psl/-/psl-1.1.28.tgz",
- "integrity": "sha512-+AqO1Ae+N/4r7Rvchrdm432afjT9hqJRyBN3DQv9At0tPz4hIFSGKbq64fN9dVoCow4oggIIax5/iONx0r9hZw==",
- "dev": true
- }
}
},
"tunnel-agent": {
diff --git a/package.json b/package.json
index 5eef0daae..10b4451e3 100644
--- a/package.json
+++ b/package.json
@@ -38,6 +38,7 @@
"e2e:chrome": "nightwatch -e chrome",
"e2e:firefox": "nightwatch -e firefox --skiptags wip",
"getcapabilities": "bash -c 'FETCH_GC=1 tasks/buildOptions.sh ${1}' 0",
+ "linkcheck": "node ./tasks/linkcheck",
"lint": "run-s lint:*",
"lint:css": "stylelint ./web/css/**/*.css",
"lint:js": "eslint .",
@@ -80,6 +81,7 @@
"browserstack-capabilities": "^0.4.0",
"browserstack-local": "^1.3.0",
"buster": "github:busterjs/buster#v0.8.0",
+ "cheerio": "^1.0.0-rc.2",
"chromedriver": "2.25.1",
"cssnano": "^3.10.0",
"eslint": "^4.13.0",
@@ -101,6 +103,8 @@
"minimist": "^1.2.0",
"moment": "2.13.x",
"nightwatch": "^0.9.16",
+ "node-fetch": "^2.1.2",
+ "node-ssh": "^5.1.1",
"npm-run-all": "^4.1.1",
"npm-watch": "^0.3.0",
"phantomjs-prebuilt": "2.1.x",
diff --git a/tasks/link-check/html-url-extract.js b/tasks/link-check/html-url-extract.js
new file mode 100644
index 000000000..e733483b3
--- /dev/null
+++ b/tasks/link-check/html-url-extract.js
@@ -0,0 +1,62 @@
+const cheerio = require('cheerio');
+const fs = require('fs');
+// walk through directory to collect html file paths, parse for links, and return array of link objects
+
+// create collection of HTML file addresses from directory
+const walk = (dir) => {
+ let results = [];
+ let list = fs.readdirSync(dir);
+ list.forEach(function(file) {
+ file = dir + '/' + file;
+ let stat = fs.statSync(file);
+ if (stat && stat.isDirectory()) {
+ /* Recurse into a subdirectory */
+ results = results.concat(walk(file));
+ } else {
+ // results.push(file);
+ file_type = file.split(".").pop();
+ file_name = file.split(/(\\|\/)/g).pop();
+ if (file_type == "html") {
+ results.push(file);
+ }
+ }
+ });
+ return results;
+}
+
+// get URLS from HTML in ./build/options using cheerio
+const getUrls = (htmlArray) => {
+ // skip exact (rel and href) doubles of links
+ const trackDoubles = {};
+ const scrapedHTML = [];
+
+ for (let i = 0; i < htmlArray.length; i++) {
+ let $ = cheerio.load(fs.readFileSync(htmlArray[i]));
+ let links = $('a');
+
+ // create url object:
+ // { 'AIRS - The AIRS instrument suite physical retrievals': 'http://airs.jpl.nasa.gov/data/physical_retrievals' }
+ $(links).each(function(i, link) {
+ let linkRel = $(link).text() || 'EMPTY';
+ let linkHref = $(link).attr('href');
+
+ if (trackDoubles[linkRel] !== linkHref) {
+ scrapedHTML.push({[linkRel]: linkHref});
+ trackDoubles[linkRel] = linkHref;
+ }
+ })
+ }
+ return scrapedHTML;
+}
+
+// get URLS from HTML files
+// scraped URLs are saved in an array of objects with a key value pair of link text and href:
+// 'Wildfire MB-CE042, Manitoba, Canada': 'https://eonet.sci.gsfc.nasa.gov/api/v2.1/events/EONET_3518'
+const initExtractor = async () => {
+ // any html file with a url will be scraped and added
+ const htmlFiles = await walk('./build/options');
+ const htmlUrls = await getUrls(htmlFiles);
+ return htmlUrls;
+};
+
+module.exports = initExtractor;
\ No newline at end of file
diff --git a/tasks/link-check/natural-event-url-extract.js b/tasks/link-check/natural-event-url-extract.js
new file mode 100644
index 000000000..81f320cd2
--- /dev/null
+++ b/tasks/link-check/natural-event-url-extract.js
@@ -0,0 +1,73 @@
+const fetch = require('node-fetch');
+
+// delay helper to prevent too many requests at once
+const sleeper = (ms) => (x) => new Promise(resolve => setTimeout(() => resolve(x), ms));
+
+// helper function to find target key in nested object
+const findProp = async (obj, keys, out) => {
+ let i;
+ let proto = Object.prototype;
+ let ts = proto.toString;
+ let hasOwn = proto.hasOwnProperty.bind(obj);
+
+ if ('[object Array]' !== ts.call(out)) {
+ out = [];
+ }
+ for (i in obj) {
+ if (hasOwn(i)) {
+ if (keys.includes(i)) {
+ let title = obj['title'] ? obj['title'] : obj['id'];
+ if (title) {
+ out.push({[title]: obj[i]});
+ }
+ } else if ('[object Array]' === ts.call(obj[i]) || '[object Object]' === ts.call(obj[i])) {
+ findProp(obj[i], keys, out);
+ }
+ }
+ }
+ return out;
+}
+
+const scrapeLinks = async (htmlLinks) => {
+ // skip exact (rel and href) doubles of links
+ const trackDoubles = {};
+ const addedUrls = [];
+
+ for (let i = 0; i < htmlLinks.length; i++) {
+ let htmlLink = htmlLinks[i];
+ const status = await fetch(htmlLink)
+ .then(async (res) => {
+ let status = await res.json();
+ let urls = await findProp(status, ['url', 'link', 'source']);
+ for (let j = 0; j < urls.length; j++) {
+ let url = urls[j];
+ let linkRel = Object.keys(url)[0];
+ let linkHref = Object.values(url)[0];
+
+ if (trackDoubles[linkRel] !== linkHref) {
+ addedUrls.push({[linkRel]: linkHref});
+ trackDoubles[linkRel] = linkHref;
+ }
+ }
+ }).then(sleeper(500))
+ .catch((err) => {
+ // will get inital errors if on - TURN ON FOR LOGGING/FURTHER DEBUGGING
+ // console.log(htmlLink, err);
+ })
+ }
+ return await addedUrls;
+}
+
+// get URLs from natural events EONET
+// scraped URLs are saved in an array of objects with a key value pair of link text and href:
+// 'Wildfire MB-CE042, Manitoba, Canada': 'https://eonet.sci.gsfc.nasa.gov/api/v2.1/events/EONET_3518'
+const initExtractor = async () => {
+ // target EONET sources from natural events
+ const links = ['https://eonet.sci.gsfc.nasa.gov/api/v2.1/sources',
+ 'https://eonet.sci.gsfc.nasa.gov/api/v2.1/events',
+ 'https://eonet.sci.gsfc.nasa.gov/api/v2.1/categories'];
+ const results = await scrapeLinks(links);
+ return results;
+}
+
+module.exports = initExtractor;
\ No newline at end of file
diff --git a/tasks/link-check/url-check.js b/tasks/link-check/url-check.js
new file mode 100644
index 000000000..c2c090c3a
--- /dev/null
+++ b/tasks/link-check/url-check.js
@@ -0,0 +1,59 @@
+const fetch = require('node-fetch');
+// URL status check function makes GET requests to provided list of URLs to get status codes / errors
+
+// Delay helper to prevent too many requests at once
+const sleeper = (ms) => (x) => new Promise(resolve => setTimeout(() => resolve(x), ms));
+
+// Checks status code of provided links and return object organized by errors / statuscodes
+const requestCheck = async (urls) => {
+ const parsedUrls = {
+ ERROR: [],
+ STATUSCODE: {}
+ };
+ for (let i = 0; i < urls.length; i++) {
+ let linkName = Object.keys(urls[i])[0];
+ let url = Object.values(urls[i])[0];
+
+ // Skip for mailto email links
+ if(url[0] !== 'h') {
+ continue;
+ }
+ const status = await fetch(url, { timeout: 10000})
+ .then(async (res) => {
+ let statusCode = await res.status;
+ if(!parsedUrls['STATUSCODE'][statusCode]) {
+ parsedUrls['STATUSCODE'][statusCode] = [];
+ }
+ parsedUrls['STATUSCODE'][statusCode].push({[linkName]: url});
+ })
+ .then(sleeper(500))
+ .catch((err) => {
+ parsedUrls['ERROR'].push({[linkName]: url});
+ })
+ }
+ return await parsedUrls;
+}
+
+// Get urls with errors/status codes organized into an object
+const getURLStatusCodeCollection = async function(urls) {
+ // const parsedUrls = await getUrlLinks(urls);
+ const checkStatus = await requestCheck(urls);
+ // Log out number of links with errors/status codes
+ console.log(`
+URL STATUSCODE RESULTS:
+${'-'.repeat(66)}
+ ERRORS: \x1b[31m${checkStatus['ERROR'].length}\x1b[0m
+ STATUSCODE:`);
+ for(let code in checkStatus['STATUSCODE']) {
+ let preColor = '\x1b[33m';
+ if (code == '200') {
+ preColor = '\x1b[32m';
+ } else if (Number(code) >= 400) {
+ preColor = '\x1b[31m';
+ }
+ console.log(` ${code}: ${preColor + checkStatus['STATUSCODE'][code].length}\x1b[0m`);
+ }
+ return checkStatus;
+};
+
+module.exports = getURLStatusCodeCollection;
\ No newline at end of file
diff --git a/tasks/linkCheck.js b/tasks/linkCheck.js
new file mode 100644
index 000000000..9aa053838
--- /dev/null
+++ b/tasks/linkCheck.js
@@ -0,0 +1,49 @@
+// *************************************************************************
+// Scrape Worldview then process URLs to organize by errors and status codes
+//
+// Current version 1.0 targets urls collected from:
+// ./build/options metadata and EONET natural events
+// *************************************************************************
+const getUrlStatusCodeCollection = require('./link-check/url-check');
+const getHtmlUrls = require('./link-check/html-url-extract.js')
+const getNaturalEventsUrls = require('./link-check/natural-event-url-extract.js');
+
+const fs = require('fs');
+const makeLine = (msg) => {
+ return console.log(`${'-'.repeat(66)}
+\x1b[36m${msg}\x1b[0m`);
+}
+
+// Prevent majority of TLS SSL related errors
+process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"
+
+// Make get requests with URLs with node-fetch to check status codes and organize by errors and codes
+const organizeURLStatus = async (scrapedUrls) => {
+ let timeEstimate = (scrapedUrls.length * 1000 / 60000).toFixed(0);
+ makeLine(`Checking url status codes will take approximately ${timeEstimate} minutes...`);
+ // Initiate status code check
+ let results = await getUrlStatusCodeCollection(scrapedUrls);
+ // Wait for URLs to be analyzed then stringify and save to JSON file
+ let stringified = await JSON.stringify(results, null, 2);
+ let now = new Date();
+
+ // Check for 'results' directory or make new one
+ fs.existsSync('./tasks/link-check/results') || fs.mkdirSync('./tasks/link-check/results');
+
+ let fileName = `./tasks/link-check/results/WV-link-check-${now.getFullYear()}-${now.getMonth() + 1}-${now.getDate()}.json`;
+ fs.writeFile(fileName, stringified, 'utf8', function() {
+ makeLine(`Results file created: ${fileName}`);
+ process.exit();
+ });
+}
+
+const main = async () => {
+ makeLine('Starting by collecting urls to check...');
+ // get natural event urls
+ let naturalEventsUrls = await getNaturalEventsUrls();
+ // get metadata layers and about page urls
+ let htmlUrls = await getHtmlUrls();
+ organizeURLStatus(htmlUrls.concat(naturalEventsUrls));
+}
+
+main();
\ No newline at end of file