aboutsummaryrefslogtreecommitdiff
path: root/hash_script/index.js
diff options
context:
space:
mode:
authorNateN1222 <nathannichols454@gmail.com>2017-09-03 17:38:26 -0500
committerNateN1222 <nathannichols454@gmail.com>2017-09-03 17:38:26 -0500
commitd324474467727fa31c76c206acb027acd8925fa1 (patch)
tree85093616781ce3705568153c1a09d0e2b7ec5a4e /hash_script/index.js
parent7ea4ef16ca69ea37b87ca9a9306d2fd9c136539d (diff)
Implemented a default whitelist
Diffstat (limited to 'hash_script/index.js')
-rw-r--r--hash_script/index.js40
1 files changed, 40 insertions, 0 deletions
diff --git a/hash_script/index.js b/hash_script/index.js
new file mode 100644
index 0000000..60066e5
--- /dev/null
+++ b/hash_script/index.js
@@ -0,0 +1,40 @@
+const fetch = require("node-fetch")
+const crypto = require("crypto")
+const obj = {}
+
+const fetch_arr = ["jquery"]
+
+function promise_wrapping(promise, ...rest) {
+ return new Promise((res, rej) => {
+ promise
+ .then(x => res([x, ...rest]))
+ .catch(x => rej())
+ })
+}
+
+Promise.all(fetch_arr.map(value => fetch(`https://api.cdnjs.com/libraries/${value}`)))
+.then(res => Promise.all(res.map(x => x.json())))
+//.then(libs => Promise.all(libs.assets.map(asset => asset.files.map(file => fetch(`https://api.cdnjs.com/${libs.name}/${asset.version}/${file}`)))))
+.then(result => {
+ let x = [];
+ result.map(single => {
+ single.assets.map(version => {
+ version.files.filter(file => {
+ if (file.endsWith(".js")) { return file }
+ }).map(file => {
+ x.push([`https://cdnjs.cloudflare.com/ajax/libs/${single.name}/${version.version}/${file}`, file, version.version, single.name])
+ })
+ })
+ })
+ return Promise.all(x.map(z => promise_wrapping(fetch(z[0]), z[1], z[2], z[3])))
+})
+.then(x => Promise.all(x.map(a => promise_wrapping(a[0].text(), a[1], a[2], a[3]))))
+.then(q => {
+ q.map(single => {
+ if (!obj[single[3]]) obj[single[3]] = []
+ const hash = crypto.createHash("sha256")
+ const updated = hash.update(single[0]).digest("hex")
+ obj[single[3]].push({ "filename": single[1], "version": single[2], "hash": updated })
+ })
+ console.log(JSON.stringify(obj))
+})