chore: code formatting
This commit is contained in:
@@ -212,7 +212,7 @@ export default async function metrics({login, q}, {graphql, rest, plugins, conf,
|
||||
|
||||
//Metrics insights
|
||||
metrics.insights = async function({login}, {graphql, rest, conf, callbacks}, {Plugins, Templates}) {
|
||||
return metrics({login, q:metrics.insights.q}, {graphql, rest, plugins:metrics.insights.plugins, conf, callbacks, convert: "json"}, {Plugins, Templates})
|
||||
return metrics({login, q: metrics.insights.q}, {graphql, rest, plugins: metrics.insights.plugins, conf, callbacks, convert: "json"}, {Plugins, Templates})
|
||||
}
|
||||
metrics.insights.q = {
|
||||
template: "classic",
|
||||
@@ -292,5 +292,5 @@ metrics.insights.output = async function({login, imports, conf}, {graphql, rest,
|
||||
</body>
|
||||
</html>`
|
||||
await browser.close()
|
||||
return {mime: "text/html", rendered, errors:json.errors}
|
||||
return {mime: "text/html", rendered, errors: json.errors}
|
||||
}
|
||||
|
||||
@@ -193,9 +193,8 @@ export default async function({sandbox = false} = {}) {
|
||||
console.debug(`metrics/app/${login}/insights > 400 (invalid plugin name)`)
|
||||
return res.status(400).send("Bad request: plugin name seems invalid")
|
||||
}
|
||||
if (cache.get(`about.${login}.${plugin}`)) {
|
||||
if (cache.get(`about.${login}.${plugin}`))
|
||||
return res.send(cache.get(`about.${login}.${plugin}`))
|
||||
}
|
||||
return res.status(204).send("No content: no data fetched yet")
|
||||
})
|
||||
app.get("/about/query/:login/", ...middlewares, async (req, res) => {
|
||||
@@ -209,7 +208,7 @@ export default async function({sandbox = false} = {}) {
|
||||
let solve = null
|
||||
try {
|
||||
//Prevent multiples requests
|
||||
if ((!debug) && (!mock) && (pending.has(`about.${login}`))) {
|
||||
if ((!debug) && (!mock) && (pending.has(`about.${login}`))) {
|
||||
console.debug(`metrics/app/${login}/insights > awaiting pending request`)
|
||||
await pending.get(`about.${login}`)
|
||||
}
|
||||
@@ -227,7 +226,7 @@ export default async function({sandbox = false} = {}) {
|
||||
async plugin(login, plugin, success, result) {
|
||||
console.debug(`metrics/app/${login}/insights/plugins > ${plugin} > ${success ? "success" : "failure"}`)
|
||||
cache.put(`about.${login}.${plugin}`, result)
|
||||
}
|
||||
},
|
||||
}
|
||||
;(async () => {
|
||||
try {
|
||||
@@ -244,7 +243,7 @@ export default async function({sandbox = false} = {}) {
|
||||
}
|
||||
})()
|
||||
console.debug(`metrics/app/${login}/insights > accepted request`)
|
||||
return res.status(202).json({processing:true, plugins:Object.keys(metrics.insights.plugins)})
|
||||
return res.status(202).json({processing: true, plugins: Object.keys(metrics.insights.plugins)})
|
||||
}
|
||||
//Internal error
|
||||
catch (error) {
|
||||
|
||||
@@ -101,7 +101,7 @@
|
||||
const {processing, ...data} = (await axios.get(`/about/query/${this.user}`)).data
|
||||
if (processing) {
|
||||
let completed = 0
|
||||
this.progress = 1/(data.plugins.length+1)
|
||||
this.progress = 1 / (data.plugins.length + 1)
|
||||
this.loaded = []
|
||||
const retry = async (plugin, attempts = 60, interval = 10) => {
|
||||
if (this.loaded.includes(plugin))
|
||||
@@ -112,18 +112,18 @@
|
||||
if (!data)
|
||||
throw new Error(`${plugin}: no data`)
|
||||
if (plugin === "base")
|
||||
this.metrics = {rendered:data, mime:"application/json", errors:[]}
|
||||
this.metrics = {rendered: data, mime: "application/json", errors: []}
|
||||
else
|
||||
Object.assign(this.metrics.rendered.plugins, {[plugin]:data})
|
||||
Object.assign(this.metrics.rendered.plugins, {[plugin]: data})
|
||||
break
|
||||
}
|
||||
catch {
|
||||
console.warn(`${plugin}: no data yet, retrying in ${interval} seconds`)
|
||||
await new Promise(solve => setTimeout(solve, interval*1000))
|
||||
await new Promise(solve => setTimeout(solve, interval * 1000))
|
||||
}
|
||||
} while (--attempts)
|
||||
completed++
|
||||
this.progress = completed/(data.plugins.length+1)
|
||||
this.progress = completed / (data.plugins.length + 1)
|
||||
this.loaded.push(plugin)
|
||||
}
|
||||
await retry("base", 30, 5)
|
||||
@@ -167,16 +167,19 @@
|
||||
return this.metrics?.rendered.plugins?.followup ?? null
|
||||
},
|
||||
calendar() {
|
||||
if (this.metrics?.rendered.plugins?.calendar)
|
||||
return Object.assign(this.metrics?.rendered.plugins?.calendar, {color(c) {
|
||||
return {
|
||||
"#ebedf0":"var(--color-calendar-graph-day-bg)",
|
||||
"#9be9a8":"var(--color-calendar-graph-day-L1-bg)",
|
||||
"#40c463":"var(--color-calendar-graph-day-L2-bg)",
|
||||
"#30a14e":"var(--color-calendar-graph-day-L3-bg)",
|
||||
"#216e39":"var(--color-calendar-graph-day-L4-bg)",
|
||||
}[c] ?? c
|
||||
}})
|
||||
if (this.metrics?.rendered.plugins?.calendar) {
|
||||
return Object.assign(this.metrics?.rendered.plugins?.calendar, {
|
||||
color(c) {
|
||||
return {
|
||||
"#ebedf0": "var(--color-calendar-graph-day-bg)",
|
||||
"#9be9a8": "var(--color-calendar-graph-day-L1-bg)",
|
||||
"#40c463": "var(--color-calendar-graph-day-L2-bg)",
|
||||
"#30a14e": "var(--color-calendar-graph-day-L3-bg)",
|
||||
"#216e39": "var(--color-calendar-graph-day-L4-bg)",
|
||||
}[c] ?? c
|
||||
},
|
||||
})
|
||||
}
|
||||
return null
|
||||
},
|
||||
isocalendar() {
|
||||
@@ -188,7 +191,7 @@
|
||||
.replace(/#216e39/gi, "var(--color-calendar-graph-day-L4-bg)")
|
||||
},
|
||||
languages() {
|
||||
return Object.assign(this.metrics?.rendered.plugins?.languages?.favorites ?? [], {total:this.metrics?.rendered.plugins?.languages.total})
|
||||
return Object.assign(this.metrics?.rendered.plugins?.languages?.favorites ?? [], {total: this.metrics?.rendered.plugins?.languages.total})
|
||||
},
|
||||
reactions() {
|
||||
return this.metrics?.rendered.plugins?.reactions ?? null
|
||||
@@ -197,7 +200,7 @@
|
||||
return this.metrics?.rendered.plugins?.repositories?.list ?? []
|
||||
},
|
||||
stars() {
|
||||
return {repositories:this.metrics?.rendered.plugins?.stars?.repositories.map(({node, starredAt}) => ({...node, starredAt})) ?? []}
|
||||
return {repositories: this.metrics?.rendered.plugins?.stars?.repositories.map(({node, starredAt}) => ({...node, starredAt})) ?? []}
|
||||
},
|
||||
topics() {
|
||||
return this.metrics?.rendered.plugins?.topics?.list ?? []
|
||||
@@ -240,7 +243,7 @@
|
||||
error: null,
|
||||
config: {},
|
||||
progress: 0,
|
||||
loaded: []
|
||||
loaded: [],
|
||||
},
|
||||
})
|
||||
})()
|
||||
|
||||
Reference in New Issue
Block a user