| 5 | |
| 6 | //Setup |
| 7 | export default async function metrics({login, q}, {graphql, rest, plugins, conf, die = false, verify = false, convert = null, callbacks = null, warnings = []}, {Plugins, Templates}) { |
| 8 | //Compute rendering |
| 9 | try { |
| 10 | //Debug |
| 11 | login = login.replace(/[\n\r]/g, "") |
| 12 | console.debug(`metrics/compute/${login} > start`) |
| 13 | console.debug(util.inspect(q, {depth: Infinity, maxStringLength: 256})) |
| 14 | |
| 15 | //Load template |
| 16 | const template = q.template || conf.settings.templates.default |
| 17 | if ((!(template in Templates)) || (!(template in conf.templates)) || ((conf.settings.templates.enabled.length) && (!conf.settings.templates.enabled.includes(template)))) |
| 18 | throw new Error("unsupported template") |
| 19 | const {image, style, fonts, views, partials} = conf.templates[template] |
| 20 | const computer = Templates[template].default || Templates[template] |
| 21 | convert = convert ?? conf.metadata.templates[template]?.formats?.[0] ?? null |
| 22 | console.debug(`metrics/compute/${login} > output format set to ${convert}`) |
| 23 | |
| 24 | //Initialization |
| 25 | const pending = [] |
| 26 | const {queries} = conf |
| 27 | const imports = { |
| 28 | plugins: Plugins, |
| 29 | templates: Templates, |
| 30 | metadata: conf.metadata, |
| 31 | ...utils, |
| 32 | ...utils.formatters({timeZone: q["config.timezone"]}), |
| 33 | ...(/markdown/.test(convert) |
| 34 | ? { |
| 35 | imgb64(url, options) { |
| 36 | return options?.force ? utils.imgb64(...arguments) : url |
| 37 | }, |
| 38 | } |
| 39 | : null), |
| 40 | } |
| 41 | const {"debug.flags": dflags, "experimental.features": _experimental, "config.order": _partials} = imports.metadata.plugins.core.inputs({account: "bypass", q}) |
| 42 | const extras = {css: imports.metadata.plugins.core.extras("extras_css", {...conf.settings, error: false}) ? q["extras.css"] ?? "" : "", js: imports.metadata.plugins.core.extras("extras_js", {...conf.settings, error: false}) ? q["extras.js"] ?? "" : ""} |
| 43 | const data = {q, animated: true, large: false, base: {}, config: {}, errors: [], warnings, plugins: {}, computed: {}, extras, postscripts: []} |
| 44 | const experimental = new Set(_experimental) |
| 45 | if (conf.settings["debug.headless"]) { |
| 46 | imports.puppeteer.headless = false |
| 47 | console.debug(`metrics/compute/${login} > disabled puppeteer headless mode`) |
| 48 | } |
| 49 | if ((conf.settings.debug) || (process.env.GITHUB_ACTIONS)) { |
| 50 | if (dflags.includes("--puppeteer-disable-headless")) { |
| 51 | imports.puppeteer.headless = false |
| 52 | console.debug(`metrics/compute/${login} > disabled puppeteer headless mode`) |
| 53 | } |
| 54 | if (dflags.includes("--puppeteer-debug")) { |
| 55 | process.env.DEBUG = "puppeteer:*" |
| 56 | console.debug(`metrics/compute/${login} > enabled puppeteer debugging`) |
| 57 | } |
| 58 | if (dflags.find(flag => flag.startsWith("--puppeteer-wait-"))) { |
| 59 | imports.puppeteer.events = dflags.filter(flag => flag.startsWith("--puppeteer-wait-")).map(flag => flag.replace("--puppeteer-wait-", "")) |
| 60 | console.debug(`metrics/compute/${login} > overridden puppeteer wait events [${imports.puppeteer.events}]`) |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | //Metrics insights |