Interactive interface for browsing global, full-resolution satellite imagery
fix lint errors
Ed Platoc49795a9ff17
diff --git a/tasks/link-check/html-url-extract.js b/tasks/link-check/html-url-extract.jsindex e733483b3..b6e3816b9 100644--- a/tasks/link-check/html-url-extract.js+++ b/tasks/link-check/html-url-extract.js@@ -9,20 +9,18 @@ const walk = (dir) => {list.forEach(function(file) {file = dir + '/' + file;let stat = fs.statSync(file);- if (stat && stat.isDirectory()) {+ 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") {+ } else {+ let fileType = file.split('.').pop();+ if (fileType === 'html') {results.push(file);}}});return results;-}+};// get URLS from HTML in ./build/options using cheerioconst getUrls = (htmlArray) => {@@ -41,13 +39,13 @@ const getUrls = (htmlArray) => {let linkHref = $(link).attr('href');if (trackDoubles[linkRel] !== linkHref) {- scrapedHTML.push({[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:@@ -59,4 +57,4 @@ const initExtractor = async () => {return htmlUrls;};-module.exports = initExtractor;\ No newline at end of file+module.exports = initExtractor;diff --git a/tasks/link-check/natural-event-url-extract.js b/tasks/link-check/natural-event-url-extract.jsindex 81f320cd2..7496806b7 100644--- a/tasks/link-check/natural-event-url-extract.js+++ b/tasks/link-check/natural-event-url-extract.js@@ -10,23 +10,24 @@ const findProp = async (obj, keys, out) => {let ts = proto.toString;let hasOwn = proto.hasOwnProperty.bind(obj);- if ('[object Array]' !== ts.call(out)) {+ if (ts.call(out) !== '[object Array]') {out = [];- }+ }for (i in obj) {if (hasOwn(i)) {if (keys.includes(i)) {+ // handle different title formats from EONETlet title = obj['title'] ? obj['title'] : obj['id'];if (title) {- out.push({[title]: obj[i]});+ out.push({ [title]: obj[i] });}- } else if ('[object Array]' === ts.call(obj[i]) || '[object Object]' === ts.call(obj[i])) {+ } else if (ts.call(obj[i]) === '[object Array]' || ts.call(obj[i]) === '[object Object]') {findProp(obj[i], keys, out);}}}return out;-}+};const scrapeLinks = async (htmlLinks) => {// skip exact (rel and href) doubles of links@@ -35,7 +36,7 @@ const scrapeLinks = async (htmlLinks) => {for (let i = 0; i < htmlLinks.length; i++) {let htmlLink = htmlLinks[i];- const status = await fetch(htmlLink)+ fetch(htmlLink).then(async (res) => {let status = await res.json();let urls = await findProp(status, ['url', 'link', 'source']);@@ -45,18 +46,18 @@ const scrapeLinks = async (htmlLinks) => {let linkHref = Object.values(url)[0];if (trackDoubles[linkRel] !== linkHref) {- addedUrls.push({[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);- })+ console.log(htmlLink, err);+ });}- return await addedUrls;-}+ return 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:@@ -64,10 +65,10 @@ const scrapeLinks = async (htmlLinks) => {const initExtractor = async () => {// target EONET sources from natural eventsconst 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'];+ '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+module.exports = initExtractor;diff --git a/tasks/link-check/url-check.js b/tasks/link-check/url-check.jsindex c2c090c3a..b1649c2bb 100644--- a/tasks/link-check/url-check.js+++ b/tasks/link-check/url-check.js@@ -15,28 +15,28 @@ const requestCheck = async (urls) => {let url = Object.values(urls[i])[0];// Skip for mailto email links- if(url[0] !== 'h') {+ if (url[0] !== 'h') {continue;}- const status = await fetch(url, { timeout: 10000})+ fetch(url, { timeout: 10000 }).then(async (res) => {let statusCode = await res.status;- if(!parsedUrls['STATUSCODE'][statusCode]) {+ if (!parsedUrls['STATUSCODE'][statusCode]) {parsedUrls['STATUSCODE'][statusCode] = [];}- parsedUrls['STATUSCODE'][statusCode].push({[linkName]: url});+ parsedUrls['STATUSCODE'][statusCode].push({ [linkName]: url });}).then(sleeper(500)).catch((err) => {- parsedUrls['ERROR'].push({[linkName]: url});- })+ console.log(err);+ parsedUrls['ERROR'].push({ [linkName]: url });+ });}- return await parsedUrls;-}+ return parsedUrls;+};// Get urls with errors/status codes organized into an object-const getURLStatusCodeCollection = async function(urls) {- // const parsedUrls = await getUrlLinks(urls);+const getURLStatusCodeCollection = async function(urls) {const checkStatus = await requestCheck(urls);// Log out number of links with errors/status codesconsole.log(`@@ -44,9 +44,9 @@ URL STATUSCODE RESULTS:${'-'.repeat(66)}ERRORS: \x1b[31m${checkStatus['ERROR'].length}\x1b[0mSTATUSCODE:`);- for(let code in checkStatus['STATUSCODE']) {+ for (let code in checkStatus['STATUSCODE']) {let preColor = '\x1b[33m';- if (code == '200') {+ if (code === '200') {preColor = '\x1b[32m';} else if (Number(code) >= 400) {preColor = '\x1b[31m';@@ -56,4 +56,4 @@ ${'-'.repeat(66)}return checkStatus;};-module.exports = getURLStatusCodeCollection;\ No newline at end of file+module.exports = getURLStatusCodeCollection;diff --git a/tasks/linkCheck.js b/tasks/linkCheck.jsindex 9aa053838..ee69865d8 100644--- a/tasks/linkCheck.js+++ b/tasks/linkCheck.js@@ -1,21 +1,21 @@// *************************************************************************// 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 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"+process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';// Make get requests with URLs with node-fetch to check status codes and organize by errors and codesconst organizeURLStatus = async (scrapedUrls) => {@@ -35,7 +35,7 @@ const organizeURLStatus = async (scrapedUrls) => {makeLine(`Results file created: ${fileName}`);process.exit();});-}+};const main = async () => {makeLine('Starting by collecting urls to check...');@@ -44,6 +44,6 @@ const main = async () => {// get metadata layers and about page urlslet htmlUrls = await getHtmlUrls();organizeURLStatus(htmlUrls.concat(naturalEventsUrls));-}+};-main();\ No newline at end of file+main();