diff --git a/source/app/metrics/index.mjs b/source/app/metrics/index.mjs index 824cc5d1..2fe4f365 100644 --- a/source/app/metrics/index.mjs +++ b/source/app/metrics/index.mjs @@ -85,11 +85,33 @@ console.debug(error) } //Embed method - const embed = async(name, q) => { - q = Object.fromEntries([...Object.entries(q).map(([key, value]) => [key.replace(/^plugin_/, "").replace(/_/g, "."), value]), ["base", false], ["config.animations", false]]) - const plugins = Object.fromEntries(Object.entries(arguments[1].plugins).map(([key, value]) => [key, {...value, enabled:true}])) - const {rendered} = await metrics({login, q}, {...arguments[1], plugins, convert:null}, arguments[2]) - return `` + const embed = async(name, q = {}) => { + //Check arguments + if ((!name)||(typeof q !== "object")||(q === null)) { + if (die) + throw new Error("An error occured during embed rendering, dying") + return "

⚠️ Failed to execute embed function: invalid arguments

" + } + //Translate action syntax to web syntax + let parts = [] + if (q.base === true) + ({parts} = conf.settings.plugins.base) + if (typeof q.base === "string") + parts = q.base.split(",").map(x => x.trim()) + if (Array.isArray(q.base)) + parts = q.base + for (const part of conf.settings.plugins.base.parts) + q[`base.${part}`] = q[`base.${part}`] ?? parts.includes(part) + if (convert === "markdown-pdf") { + q["config.animations"] = false + q.config_animations = false + } + q = Object.fromEntries([...Object.entries(q).map(([key, value]) => [key.replace(/^plugin_/, "").replace(/_/g, "."), value]), ["base", false]]) + //Enable required plugins + const plugins = Object.fromEntries(Object.entries(arguments[1].plugins).map(([key, value]) => [key, {...value, enabled:true}])) + //Compute rendering + const {rendered} = await metrics({login, q}, {...arguments[1], plugins, convert:null}, arguments[2]) + return `` } //Rendering template source let rendered = source.replace(/\{\{ (?[\s\S]*?) \}\}/g, "{%= $ %}") @@ -107,7 +129,7 @@ rest, }) } - return {rendered, mime:"text/plain"} + return {rendered, mime:"text/html"} } //Rendering