Skip to content

Commit e437a4d

Browse files
chore: code formatting
1 parent 587ceec commit e437a4d

File tree

6 files changed

+41
-36
lines changed

6 files changed

+41
-36
lines changed

source/app/metrics/metadata.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ metadata.plugin = async function({__plugins, __templates, name, logger}) {
371371
return null
372372
}
373373
})(),
374-
]).filter(([key, value]) => (value)&&(!((name === "base")&&(key === "repositories")))),
374+
]).filter(([key, value]) => (value) && (!((name === "base") && (key === "repositories")))),
375375
)
376376
}
377377

source/app/web/instance.mjs

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
//Imports
22
import octokit from "@octokit/graphql"
33
import OctokitRest from "@octokit/rest"
4+
import axios from "axios"
45
import compression from "compression"
6+
import crypto from "crypto"
57
import express from "express"
68
import ratelimit from "express-rate-limit"
79
import cache from "memory-cache"
8-
import util from "util"
910
import url from "url"
10-
import axios from "axios"
11+
import util from "util"
1112
import mocks from "../../../tests/mocks/index.mjs"
1213
import metrics from "../metrics/index.mjs"
1314
import presets from "../metrics/presets.mjs"
1415
import setup from "../metrics/setup.mjs"
15-
import crypto from "crypto"
1616

1717
/**App */
1818
export default async function({sandbox = false} = {}) {
@@ -68,8 +68,9 @@ export default async function({sandbox = false} = {}) {
6868
console.debug(`metrics/app/session/${login} > authenticated with session ${session.substring(0, 6)}, using custom octokit`)
6969
return {login, graphql: octokit.graphql.defaults({headers: {authorization: `token ${token}`}}), rest: new OctokitRest.Octokit({auth: token})}
7070
}
71-
else if (session)
71+
else if (session) {
7272
console.debug(`metrics/app/session > unknown session ${session.substring(0, 6)}, using default octokit`)
73+
}
7374
return null
7475
}
7576

@@ -146,7 +147,7 @@ export default async function({sandbox = false} = {}) {
146147
//Modes and extras
147148
app.get("/.modes", limiter, (req, res) => res.status(200).json(conf.settings.modes))
148149
app.get("/.extras", limiter, async (req, res) => {
149-
if ((authenticated.has(req.headers["x-metrics-session"]))&&(conf.settings.extras?.logged)) {
150+
if ((authenticated.has(req.headers["x-metrics-session"])) && (conf.settings.extras?.logged)) {
150151
if (conf.settings.extras?.features !== true)
151152
return res.status(200).json([...conf.settings.extras.features, ...conf.settings.extras.logged])
152153
}
@@ -177,9 +178,9 @@ export default async function({sandbox = false} = {}) {
177178
try {
178179
const custom = uapi(req.headers["x-metrics-session"])
179180
if (custom) {
180-
const {data:{resources}} = await custom.rest.rateLimit.get()
181+
const {data: {resources}} = await custom.rest.rateLimit.get()
181182
if (resources)
182-
return res.status(200).json({rest:resources.core, graphql:resources.graphql, search:resources.search, login:custom.login})
183+
return res.status(200).json({rest: resources.core, graphql: resources.graphql, search: resources.search, login: custom.login})
183184
}
184185
}
185186
catch {} //eslint-disable-line no-empty
@@ -220,39 +221,42 @@ export default async function({sandbox = false} = {}) {
220221
console.debug(`metrics/app/oauth > request ${state}`)
221222
//OAuth through GitHub
222223
return res.redirect(`https://github.com/login/oauth/authorize?${new url.URLSearchParams({
223-
client_id:conf.settings.oauth.id,
224+
client_id: conf.settings.oauth.id,
224225
state,
225-
redirect_uri:`${conf.settings.oauth.url}/.oauth/authorize`,
226-
allow_signup:false,
227-
scope:scopes,
226+
redirect_uri: `${conf.settings.oauth.url}/.oauth/authorize`,
227+
allow_signup: false,
228+
scope: scopes,
228229
})}`)
229230
})
230231
app.get("/.oauth/authorize", async (req, res) => {
231232
//Check state
232233
const {code, state} = req.query
233-
if ((!state)||(!states.has(state))) {
234+
if ((!state) || (!states.has(state))) {
234235
console.debug("metrics/app/oauth > 400 (invalid state)")
235236
return res.status(400).send("Bad request: invalid state")
236237
}
237238
//OAuth
238239
try {
239240
//Authorize user
240241
console.debug("metrics/app/oauth > authorization")
241-
const {data} = await axios.post("https://github.com/login/oauth/access_token", `${new url.URLSearchParams({
242-
client_id:conf.settings.oauth.id,
243-
client_secret:conf.settings.oauth.secret,
244-
code,
245-
})}`)
242+
const {data} = await axios.post(
243+
"https://github.com/login/oauth/access_token",
244+
`${new url.URLSearchParams({
245+
client_id: conf.settings.oauth.id,
246+
client_secret: conf.settings.oauth.secret,
247+
code,
248+
})}`,
249+
)
246250
const token = new url.URLSearchParams(data).get("access_token")
247251
//Validate user
248-
const {data:{login}} = await axios.get("https://api.github.com/user", {headers:{Authorization:`token ${token}`}})
252+
const {data: {login}} = await axios.get("https://api.github.com/user", {headers: {Authorization: `token ${token}`}})
249253
console.debug(`metrics/app/oauth > authorization success for ${login}`)
250254
const session = crypto.randomBytes(128).toString("hex")
251255
authenticated.set(session, {login, token})
252256
console.debug(`metrics/app/oauth > created session ${session.substring(0, 6)}`)
253257
//Redirect user back
254258
const {from} = states.get(state)
255-
return res.redirect(`/.oauth/redirect?${new url.URLSearchParams({to:from, session})}`)
259+
return res.redirect(`/.oauth/redirect?${new url.URLSearchParams({to: from, session})}`)
256260
}
257261
catch {
258262
console.debug("metrics/app/oauth > authorization failed")
@@ -267,7 +271,7 @@ export default async function({sandbox = false} = {}) {
267271
if (authenticated.has(session)) {
268272
const {token} = authenticated.get(session)
269273
try {
270-
console.log(await axios.delete(`https://api.github.com/applications/${conf.settings.oauth.id}/grant`, {auth:{username:conf.settings.oauth.id, password:conf.settings.oauth.secret}, headers:{Accept:"application/vnd.github+json"}, data:{access_token:token}}))
274+
console.log(await axios.delete(`https://api.github.com/applications/${conf.settings.oauth.id}/grant`, {auth: {username: conf.settings.oauth.id, password: conf.settings.oauth.secret}, headers: {Accept: "application/vnd.github+json"}, data: {access_token: token}}))
271275
authenticated.delete(session)
272276
console.debug(`metrics/app/oauth > deleted session ${session.substring(0, 6)}`)
273277
return res.redirect("/.oauth")
@@ -279,8 +283,9 @@ export default async function({sandbox = false} = {}) {
279283
app.get("/.oauth/redirect", limiter, (req, res) => res.sendFile(`${conf.paths.statics}/oauth/redirect.html`))
280284
app.get("/.oauth/enabled", limiter, (req, res) => res.json(true))
281285
}
282-
else
286+
else {
283287
app.get("/.oauth/enabled", limiter, (req, res) => res.json(false))
288+
}
284289

285290
//Pending requests
286291
const pending = new Map()
@@ -405,7 +410,7 @@ export default async function({sandbox = false} = {}) {
405410
const repository = req.params.repository?.replace(/[\n\r]/g, "")
406411
let solve = null
407412
//Check username
408-
if ((login.startsWith("."))||(login.includes("/")))
413+
if ((login.startsWith(".")) || (login.includes("/")))
409414
return next()
410415
if (!/^[-\w]+$/i.test(login)) {
411416
console.debug(`metrics/app/${login} > 400 (invalid username)`)
@@ -452,9 +457,9 @@ export default async function({sandbox = false} = {}) {
452457
console.debug(`metrics/app/${login} > ${util.inspect(q, {depth: Infinity, maxStringLength: 256})}`)
453458
const octokit = {...api, ...uapi(req.headers["x-metrics-session"])}
454459
let uconf = conf
455-
if ((octokit.login)&&(conf.settings.extras?.logged)&&(uconf.settings.extras?.features !== true)) {
460+
if ((octokit.login) && (conf.settings.extras?.logged) && (uconf.settings.extras?.features !== true)) {
456461
console.debug(`metrics/app/${login} > session is authenticated, adding additional permissions ${conf.settings.extras.logged}`)
457-
uconf = {...conf, settings:{...conf.settings, extras:{...conf.settings.extras}}}
462+
uconf = {...conf, settings: {...conf.settings, extras: {...conf.settings.extras}}}
458463
uconf.settings.extras.features = uconf.settings.extras.features ?? []
459464
uconf.settings.extras.features.push(...conf.settings.extras.logged)
460465
}
@@ -468,7 +473,7 @@ export default async function({sandbox = false} = {}) {
468473
const {rendered, mime} = await metrics({login, q}, {
469474
...octokit,
470475
plugins,
471-
conf:uconf,
476+
conf: uconf,
472477
die: q["plugins.errors.fatal"] ?? false,
473478
verify: q.verify ?? false,
474479
convert: convert !== "auto" ? convert : null,

source/app/web/statics/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
computed: {
6666
//URL parameters
6767
params() {
68-
return new URLSearchParams({from:location.href})
68+
return new URLSearchParams({from: location.href})
6969
},
7070
//Is in preview mode
7171
preview() {

source/app/web/statics/embed/app.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,17 +170,17 @@
170170
computed: {
171171
//URL parameters
172172
params() {
173-
return new URLSearchParams({from:location.href})
173+
return new URLSearchParams({from: location.href})
174174
},
175175
//Unusable plugins
176176
unusable() {
177-
const plugins = Object.entries(this.plugins.enabled).filter(([key, value]) => (value == true)&&(!this.supports(this.plugins.options.descriptions[key]))).map(([key]) => key)
177+
const plugins = Object.entries(this.plugins.enabled).filter(([key, value]) => (value == true) && (!this.supports(this.plugins.options.descriptions[key]))).map(([key]) => key)
178178
const options = this.edited.filter(option => !this.supports(this.plugins.options.descriptions[option]))
179179
return [...plugins, ...options].sort()
180180
},
181181
//Edited plugins options
182182
edited() {
183-
return Object.keys(this.plugins.enabled).flatMap(plugin => Object.keys(this.options({name:plugin})).filter(key => this.plugins.options[key] !== metadata[plugin]?.web[key]?.defaulted))
183+
return Object.keys(this.plugins.enabled).flatMap(plugin => Object.keys(this.options({name: plugin})).filter(key => this.plugins.options[key] !== metadata[plugin]?.web[key]?.defaulted))
184184
},
185185
//User's avatar
186186
avatar() {
@@ -340,19 +340,19 @@
340340
},
341341
//Get available options from plugin
342342
options({name}) {
343-
return Object.fromEntries(Object.entries(this.plugins.options.descriptions).filter(([key]) => ((key.startsWith(`${name}.`))||(key === name)) && (!(key in metadata.base.web))))
343+
return Object.fromEntries(Object.entries(this.plugins.options.descriptions).filter(([key]) => ((key.startsWith(`${name}.`)) || (key === name)) && (!(key in metadata.base.web))))
344344
},
345345
//Check if option is supported
346346
supports(option) {
347347
if (!option)
348348
return false
349-
const {extras:required = null} = option
349+
const {extras: required = null} = option
350350
if (!Array.isArray(required))
351351
return true
352352
if (!Array.isArray(this.extras))
353353
return this.extras
354354
return required.filter(permission => !this.extras.includes(permission)).length === 0
355-
}
355+
},
356356
},
357357
})
358358
})()

source/app/web/statics/insights/script.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@
163163
//Computed properties
164164
computed: {
165165
params() {
166-
return new URLSearchParams({from:location.href})
166+
return new URLSearchParams({from: location.href})
167167
},
168168
stats() {
169169
return this.metrics?.rendered.user ?? null

source/app/web/statics/oauth/script.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
//Computed properties
5656
computed: {
5757
params() {
58-
return new URLSearchParams({from:new URLSearchParams(location.search).get("from"), scopes:this.scopes.join(" ")})
58+
return new URLSearchParams({from: new URLSearchParams(location.search).get("from"), scopes: this.scopes.join(" ")})
5959
},
6060
preview() {
6161
return /-preview$/.test(this.version)
@@ -71,7 +71,7 @@
7171
requests: {rest: {limit: 0, used: 0, remaining: 0, reset: NaN}, graphql: {limit: 0, used: 0, remaining: 0, reset: NaN}, search: {limit: 0, used: 0, remaining: 0, reset: NaN}},
7272
palette: "light",
7373
oauth: false,
74-
scopes:[],
74+
scopes: [],
7575
extras: [],
7676
session: null,
7777
},

0 commit comments

Comments
 (0)