2020-07-28 12:39:54 +00:00
|
|
|
import { Ini } from "./deps.ts";
|
|
|
|
|
|
|
|
const config =
|
|
|
|
Ini.decode(
|
2020-07-28 13:56:02 +00:00
|
|
|
await Deno.readFile("./config.ini")
|
2020-07-28 13:35:50 +00:00
|
|
|
.then((e) => new TextDecoder().decode(e))
|
|
|
|
.catch((err) => {
|
|
|
|
if (!(err instanceof Deno.errors.NotFound)) {
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
|
|
|
|
return "";
|
|
|
|
})
|
2020-07-28 12:39:54 +00:00
|
|
|
) || {};
|
|
|
|
|
2020-07-28 14:02:53 +00:00
|
|
|
if (!config.user) config.user = {};
|
2020-12-27 02:16:57 +00:00
|
|
|
if (!config.web) config.web = {};
|
2021-01-11 14:06:02 +00:00
|
|
|
if (!config.general) config.general = {};
|
2020-07-28 14:02:53 +00:00
|
|
|
|
2020-07-28 13:35:50 +00:00
|
|
|
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;
|
2020-10-14 15:44:36 +00:00
|
|
|
case "S3_REGION":
|
|
|
|
config.s3 = { ...(config.s3 || {}), region: env[key] };
|
|
|
|
break;
|
2021-01-15 01:32:51 +00:00
|
|
|
case "WEB_URL":
|
|
|
|
config.web.url = env[key];
|
|
|
|
break;
|
2020-12-27 02:16:57 +00:00
|
|
|
case "WEB_TRACKING":
|
|
|
|
config.web.tracking = env[key];
|
|
|
|
break;
|
2021-01-11 14:06:02 +00:00
|
|
|
case "GENERAL_DEV":
|
|
|
|
config.general.dev = env[key] === "true";
|
2020-07-28 13:35:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-11 14:06:02 +00:00
|
|
|
if (config.general.dev) {
|
|
|
|
console.warn("Dev mode active!!!");
|
|
|
|
}
|
|
|
|
|
2021-01-15 01:32:51 +00:00
|
|
|
if (!config.web.url) {
|
|
|
|
console.error("The web.url configuration has to be set!");
|
|
|
|
}
|
|
|
|
|
2020-07-28 13:35:50 +00:00
|
|
|
console.log("Known users:", Object.keys(config.user));
|
|
|
|
|
2020-07-28 12:39:54 +00:00
|
|
|
export default config;
|