Prettify everything
This commit is contained in:
@ -1,23 +1,23 @@
|
||||
const AuthAPI = require("../server/AuthAPI")
|
||||
const AuthAPI = require("../server/AuthAPI");
|
||||
|
||||
const scopes = {
|
||||
blacklist: {
|
||||
read: true
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
AuthAPI.createToken(scopes).then(
|
||||
token => {
|
||||
// Verify it, just to be sure.
|
||||
AuthAPI.verifyToken(token).then(payload => {
|
||||
console.log(token, "\n")
|
||||
console.log(JSON.stringify(payload, null, 2), "\n")
|
||||
console.log(AuthAPI.getPublicKey())
|
||||
process.exit()
|
||||
})
|
||||
console.log(token, "\n");
|
||||
console.log(JSON.stringify(payload, null, 2), "\n");
|
||||
console.log(AuthAPI.getPublicKey());
|
||||
process.exit();
|
||||
});
|
||||
},
|
||||
error => {
|
||||
console.error(error)
|
||||
process.exit(1)
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
@ -1,15 +1,21 @@
|
||||
require("isomorphic-fetch")
|
||||
const invariant = require("invariant")
|
||||
require("isomorphic-fetch");
|
||||
const invariant = require("invariant");
|
||||
|
||||
const CloudflareEmail = process.env.CLOUDFLARE_EMAIL
|
||||
const CloudflareKey = process.env.CLOUDFLARE_KEY
|
||||
const RayID = process.argv[2]
|
||||
const CloudflareEmail = process.env.CLOUDFLARE_EMAIL;
|
||||
const CloudflareKey = process.env.CLOUDFLARE_KEY;
|
||||
const RayID = process.argv[2];
|
||||
|
||||
invariant(CloudflareEmail, "Missing the $CLOUDFLARE_EMAIL environment variable")
|
||||
invariant(
|
||||
CloudflareEmail,
|
||||
"Missing the $CLOUDFLARE_EMAIL environment variable"
|
||||
);
|
||||
|
||||
invariant(CloudflareKey, "Missing the $CLOUDFLARE_KEY environment variable")
|
||||
invariant(CloudflareKey, "Missing the $CLOUDFLARE_KEY environment variable");
|
||||
|
||||
invariant(RayID, "Missing the RAY_ID argument; use `heroku run node show-log.js RAY_ID`")
|
||||
invariant(
|
||||
RayID,
|
||||
"Missing the RAY_ID argument; use `heroku run node show-log.js RAY_ID`"
|
||||
);
|
||||
|
||||
function getZones(domain) {
|
||||
return fetch(`https://api.cloudflare.com/client/v4/zones?name=${domain}`, {
|
||||
@ -20,21 +26,24 @@ function getZones(domain) {
|
||||
}
|
||||
})
|
||||
.then(res => res.json())
|
||||
.then(data => data.result)
|
||||
.then(data => data.result);
|
||||
}
|
||||
|
||||
function getLog(zoneId, rayId) {
|
||||
return fetch(`https://api.cloudflare.com/client/v4/zones/${zoneId}/logs/requests/${rayId}`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"X-Auth-Email": CloudflareEmail,
|
||||
"X-Auth-Key": CloudflareKey
|
||||
return fetch(
|
||||
`https://api.cloudflare.com/client/v4/zones/${zoneId}/logs/requests/${rayId}`,
|
||||
{
|
||||
method: "GET",
|
||||
headers: {
|
||||
"X-Auth-Email": CloudflareEmail,
|
||||
"X-Auth-Key": CloudflareKey
|
||||
}
|
||||
}
|
||||
}).then(res => (res.status === 404 ? "NOT FOUND" : res.json()))
|
||||
).then(res => (res.status === 404 ? "NOT FOUND" : res.json()));
|
||||
}
|
||||
|
||||
getZones("unpkg.com").then(zones => {
|
||||
getLog(zones[0].id, RayID).then(entry => {
|
||||
console.log(entry)
|
||||
})
|
||||
})
|
||||
console.log(entry);
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,48 +1,58 @@
|
||||
const subDays = require("date-fns/sub_days")
|
||||
const prettyBytes = require("pretty-bytes")
|
||||
const table = require("text-table")
|
||||
const subDays = require("date-fns/sub_days");
|
||||
const prettyBytes = require("pretty-bytes");
|
||||
const table = require("text-table");
|
||||
|
||||
const StatsAPI = require("../server/StatsAPI")
|
||||
const now = new Date()
|
||||
const StatsAPI = require("../server/StatsAPI");
|
||||
const now = new Date();
|
||||
|
||||
function createRange(start, end) {
|
||||
const range = []
|
||||
while (start < end) range.push(start++)
|
||||
return range
|
||||
const range = [];
|
||||
while (start < end) range.push(start++);
|
||||
return range;
|
||||
}
|
||||
|
||||
function createPastDays(n) {
|
||||
return createRange(1, n + 1)
|
||||
.map(days => subDays(now, days))
|
||||
.reverse()
|
||||
.reverse();
|
||||
}
|
||||
|
||||
const pastSevenDays = createPastDays(7)
|
||||
const pastThirtyDays = createPastDays(30)
|
||||
const pastSevenDays = createPastDays(7);
|
||||
const pastThirtyDays = createPastDays(30);
|
||||
|
||||
Promise.all([
|
||||
StatsAPI.sumKeys(pastSevenDays.map(date => `stats-requests-${StatsAPI.createDayKey(date)}`)),
|
||||
StatsAPI.sumKeys(pastSevenDays.map(date => `stats-bandwidth-${StatsAPI.createDayKey(date)}`)),
|
||||
StatsAPI.sumKeys(pastThirtyDays.map(date => `stats-requests-${StatsAPI.createDayKey(date)}`)),
|
||||
StatsAPI.sumKeys(pastThirtyDays.map(date => `stats-bandwidth-${StatsAPI.createDayKey(date)}`))
|
||||
StatsAPI.sumKeys(
|
||||
pastSevenDays.map(date => `stats-requests-${StatsAPI.createDayKey(date)}`)
|
||||
),
|
||||
StatsAPI.sumKeys(
|
||||
pastSevenDays.map(date => `stats-bandwidth-${StatsAPI.createDayKey(date)}`)
|
||||
),
|
||||
StatsAPI.sumKeys(
|
||||
pastThirtyDays.map(date => `stats-requests-${StatsAPI.createDayKey(date)}`)
|
||||
),
|
||||
StatsAPI.sumKeys(
|
||||
pastThirtyDays.map(date => `stats-bandwidth-${StatsAPI.createDayKey(date)}`)
|
||||
)
|
||||
]).then(results => {
|
||||
console.log("\n## Summary")
|
||||
console.log("Requests this week: %s", results[0].toLocaleString())
|
||||
console.log("Bandwidth this week: %s", prettyBytes(results[1]))
|
||||
console.log("Requests this month: %s", results[2].toLocaleString())
|
||||
console.log("Bandwidth this month: %s", prettyBytes(results[3]))
|
||||
console.log("\n## Summary");
|
||||
console.log("Requests this week: %s", results[0].toLocaleString());
|
||||
console.log("Bandwidth this week: %s", prettyBytes(results[1]));
|
||||
console.log("Requests this month: %s", results[2].toLocaleString());
|
||||
console.log("Bandwidth this month: %s", prettyBytes(results[3]));
|
||||
|
||||
StatsAPI.sumTopScores(
|
||||
pastSevenDays.map(date => `stats-packageRequests-${StatsAPI.createDayKey(date)}`)
|
||||
pastSevenDays.map(
|
||||
date => `stats-packageRequests-${StatsAPI.createDayKey(date)}`
|
||||
)
|
||||
).then(topPackages => {
|
||||
console.log("\n## Top Packages This Week")
|
||||
console.log("\n## Top Packages This Week");
|
||||
|
||||
topPackages.forEach(result => {
|
||||
result[1] = result[1].toLocaleString()
|
||||
})
|
||||
result[1] = result[1].toLocaleString();
|
||||
});
|
||||
|
||||
console.log(table(topPackages))
|
||||
console.log(table(topPackages));
|
||||
|
||||
process.exit()
|
||||
})
|
||||
})
|
||||
process.exit();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user