import { Ini } from "./deps.ts"; const config = Ini.decode( await Deno.readFile("./config.ini") .then((e) => new TextDecoder().decode(e)) .catch((err) => { if (!(err instanceof Deno.errors.NotFound)) { throw err; } return ""; }) ) || {}; if (!config.user) config.user = {}; if (!config.web) config.web = {}; if (!config.general) config.general = {}; const env = Deno.env.toObject(); for (const key in env) { if (key.startsWith("DENREG_")) { const stripped = key.slice(7); if (stripped.startsWith("USER_")) { const username = stripped.slice(5); const password = env[key]; config.user = config.user || {}; config.user[username] = { password }; } else { switch (stripped) { case "S3_ENDPOINT": config.s3 = { ...(config.s3 || {}), endpoint: env[key] }; break; case "S3_BUCKET": config.s3 = { ...(config.s3 || {}), bucket: env[key] }; break; case "S3_ACCESS": config.s3 = { ...(config.s3 || {}), accessKey: env[key] }; break; case "S3_SECRET": config.s3 = { ...(config.s3 || {}), secretKey: env[key] }; break; case "S3_REGION": config.s3 = { ...(config.s3 || {}), region: env[key] }; break; case "WEB_URL": config.web.url = env[key]; break; case "WEB_TRACKING": config.web.tracking = env[key]; break; case "GENERAL_DEV": config.general.dev = env[key] === "true"; } } } } if (config.general.dev) { console.warn("Dev mode active!!!"); } if (!config.web.url) { console.error("The web.url configuration has to be set!"); } console.log("Known users:", Object.keys(config.user)); export default config;