-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from mwood77/qol-tweaks
Qol tweaks
- Loading branch information
Showing
487 changed files
with
86,313 additions
and
55 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* eslint-disable no-underscore-dangle */ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import { fileURLToPath } from 'url'; | ||
|
||
// Helpers | ||
const __filename = fileURLToPath(import.meta.url); | ||
const __dirname = path.dirname(__filename); | ||
|
||
const distDir = path.join(__dirname, 'dist'); | ||
|
||
// Cleanup old dist folder | ||
if (fs.existsSync(distDir)) fs.rmSync(distDir, { recursive: true, force: true }); | ||
|
||
// List of files and folders to include in the build | ||
const includePaths = ['cors', 'datagenerators', 'server', 'views', 'public', 'index.js']; | ||
|
||
// Function to copy files/folders | ||
const copy = (src, dest) => { | ||
if (!fs.existsSync(src)) return; | ||
|
||
const stats = fs.lstatSync(src); | ||
if (stats.isDirectory()) { | ||
fs.mkdirSync(dest, { recursive: true }); | ||
fs.readdirSync(src).forEach((file) => copy(path.join(src, file), path.join(dest, file))); | ||
} else { | ||
fs.copyFileSync(src, dest); | ||
} | ||
}; | ||
|
||
// Copy each included file/folder | ||
includePaths.forEach((item) => copy(path.join(__dirname, item), path.join(distDir, item))); | ||
|
||
console.log('✅ Build completed: Files copied to dist/'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// pass through api requests | ||
|
||
// http(s) modules | ||
const https = require('https'); | ||
|
||
// url parsing | ||
const queryString = require('querystring'); | ||
|
||
// return an express router | ||
module.exports = (req, res) => { | ||
// add out-going headers | ||
const headers = {}; | ||
headers['user-agent'] = '(WeatherStar 4000+, [email protected])'; | ||
headers.accept = req.headers.accept; | ||
|
||
// get query paramaters if the exist | ||
const queryParams = Object.keys(req.query).reduce((acc, key) => { | ||
// skip the paramater 'u' | ||
if (key === 'u') return acc; | ||
// add the paramter to the resulting object | ||
acc[key] = req.query[key]; | ||
return acc; | ||
}, {}); | ||
let query = queryString.encode(queryParams); | ||
if (query.length > 0) query = `?${query}`; | ||
|
||
// get the page | ||
https.get(`https://api.weather.gov${req.path}${query}`, { | ||
headers, | ||
}, (getRes) => { | ||
// pull some info | ||
const { statusCode } = getRes; | ||
// pass the status code through | ||
res.status(statusCode); | ||
|
||
// set headers | ||
res.header('content-type', getRes.headers['content-type']); | ||
// pipe to response | ||
getRes.pipe(res); | ||
}).on('error', (e) => { | ||
console.error(e); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// pass through api requests | ||
|
||
// http(s) modules | ||
const https = require('https'); | ||
|
||
// url parsing | ||
const queryString = require('querystring'); | ||
|
||
// return an express router | ||
module.exports = (req, res) => { | ||
// add out-going headers | ||
const headers = {}; | ||
headers['user-agent'] = '(WeatherStar 4000+, [email protected])'; | ||
headers.accept = req.headers.accept; | ||
|
||
// get query paramaters if the exist | ||
const queryParams = Object.keys(req.query).reduce((acc, key) => { | ||
// skip the paramater 'u' | ||
if (key === 'u') return acc; | ||
// add the paramter to the resulting object | ||
acc[key] = req.query[key]; | ||
return acc; | ||
}, {}); | ||
let query = queryString.encode(queryParams); | ||
if (query.length > 0) query = `?${query}`; | ||
|
||
// get the page | ||
https.get(`https://www.cpc.ncep.noaa.gov/${req.path}${query}`, { | ||
headers, | ||
}, (getRes) => { | ||
// pull some info | ||
const { statusCode } = getRes; | ||
// pass the status code through | ||
res.status(statusCode); | ||
|
||
// set headers | ||
res.header('content-type', getRes.headers['content-type']); | ||
res.header('last-modified', getRes.headers['last-modified']); | ||
// pipe to response | ||
getRes.pipe(res); | ||
}).on('error', (e) => { | ||
console.error(e); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// pass through api requests | ||
|
||
// http(s) modules | ||
const https = require('https'); | ||
|
||
// url parsing | ||
const queryString = require('querystring'); | ||
|
||
// return an express router | ||
module.exports = (req, res) => { | ||
// add out-going headers | ||
const headers = {}; | ||
headers['user-agent'] = '(WeatherStar 4000+, [email protected])'; | ||
headers.accept = req.headers.accept; | ||
|
||
// get query paramaters if the exist | ||
const queryParams = Object.keys(req.query).reduce((acc, key) => { | ||
// skip the paramater 'u' | ||
if (key === 'u') return acc; | ||
// add the paramter to the resulting object | ||
acc[key] = req.query[key]; | ||
return acc; | ||
}, {}); | ||
let query = queryString.encode(queryParams); | ||
if (query.length > 0) query = `?${query}`; | ||
|
||
// get the page | ||
https.get(`https://radar.weather.gov${req.path}${query}`, { | ||
headers, | ||
}, (getRes) => { | ||
// pull some info | ||
const { statusCode } = getRes; | ||
// pass the status code through | ||
res.status(statusCode); | ||
|
||
// set headers | ||
res.header('content-type', getRes.headers['content-type']); | ||
res.header('last-modified', getRes.headers['last-modified']); | ||
// pipe to response | ||
getRes.pipe(res); | ||
}).on('error', (e) => { | ||
console.error(e); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// turn a long array into a set of smaller chunks | ||
|
||
const chunk = (data, chunkSize = 10) => { | ||
const chunks = []; | ||
|
||
let thisChunk = []; | ||
|
||
data.forEach((d) => { | ||
if (thisChunk.length >= chunkSize) { | ||
chunks.push(thisChunk); | ||
thisChunk = []; | ||
} | ||
thisChunk.push(d); | ||
}); | ||
|
||
// final chunk | ||
if (thisChunk.length > 0) chunks.push(thisChunk); | ||
|
||
return chunks; | ||
}; | ||
|
||
module.exports = chunk; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// async https wrapper | ||
|
||
const https = require('https'); | ||
|
||
module.exports = (url) => new Promise((resolve, reject) => { | ||
const headers = {}; | ||
headers['user-agent'] = '(WeatherStar 4000+ data generator, [email protected])'; | ||
|
||
https.get(url, { | ||
headers, | ||
}, (res) => { | ||
if (res.statusCode === 200) { | ||
const buffers = []; | ||
res.on('data', (data) => buffers.push(data)); | ||
res.on('end', () => resolve(Buffer.concat(buffers).toString())); | ||
} else { | ||
console.log(res); | ||
reject(new Error(`Unable to get: ${url}`)); | ||
} | ||
}).on('error', (e) => { | ||
console.log(e); | ||
reject(e); | ||
}); | ||
}); |
Oops, something went wrong.