53 lines
1.6 KiB
TypeScript
53 lines
1.6 KiB
TypeScript
import { from } from "env-var";
|
|
|
|
import type { LogLevel, Mode } from "./types";
|
|
|
|
const envVar = from(process.env, {
|
|
asLogLevel: (value): LogLevel => {
|
|
const logLevels = ["error", "info", "debug"];
|
|
if (logLevels.includes(value)) {
|
|
return value as LogLevel;
|
|
} else {
|
|
throw new Error("Invalid log level");
|
|
}
|
|
},
|
|
asTs3GotifyMode: (value): Mode[] => {
|
|
const parsedValue: string[] = envVar.accessors.asJsonArray(value);
|
|
|
|
const modes = ["connect", "disconnect", "moved", "message"];
|
|
for (const mode of parsedValue) {
|
|
if (!modes.includes(mode)) {
|
|
throw new Error("Invalid mode");
|
|
}
|
|
}
|
|
return parsedValue as Mode[];
|
|
},
|
|
});
|
|
|
|
export const LOG_LEVEL = envVar.get("LOG_LEVEL").default("info").asLogLevel();
|
|
|
|
export const TS3_HOST = envVar.get("TS3_HOST").required().asString();
|
|
export const TS3_QUERY_PORT = envVar
|
|
.get("TS3_QUERY_PORT")
|
|
.default(10011)
|
|
.asPortNumber();
|
|
export const TS3_SERVER_PORT = envVar
|
|
.get("TS3_SERVER_PORT")
|
|
.default(9987)
|
|
.asPortNumber();
|
|
export const TS3_USERNAME = envVar.get("TS3_USERNAME").required().asString();
|
|
export const TS3_PASSWORD = envVar.get("TS3_PASSWORD").required().asString();
|
|
export const TS3_NICKNAME = envVar
|
|
.get("TS3_NICKNAME")
|
|
.default("ts3gotify")
|
|
.asString();
|
|
|
|
export const GOTIFY_URL = envVar.get("GOTIFY_URL").required().asUrlString();
|
|
export const GOTIFY_TOKEN = envVar.get("GOTIFY_TOKEN").required().asString();
|
|
export const GOTIFY_TITLE = envVar
|
|
.get("GOTIFY_TITLE")
|
|
.default("ts3gotify")
|
|
.asString();
|
|
|
|
export const MODE = envVar.get("MODE").default('["connect"]').asTs3GotifyMode();
|