diff --git a/src/env.d.ts b/src/env.d.ts deleted file mode 100644 index 6104d1e..0000000 --- a/src/env.d.ts +++ /dev/null @@ -1,10 +0,0 @@ -/// - -interface ImportMetaEnv { - readonly PUBLIC_URL_BASE: string; - readonly PUBLIC_POCKET_URL: string; -} - -interface ImportMeta { - readonly env: ImportMetaEnv; -} diff --git a/src/ts/EnvHandler.ts b/src/ts/EnvHandler.ts new file mode 100644 index 0000000..55de446 --- /dev/null +++ b/src/ts/EnvHandler.ts @@ -0,0 +1,42 @@ +// used to deal with .env things, but with this instead because nix + +export let env = { + POCKETBASE_URL: "https://pocket.deprived.dev/", + DEV_POCKETBASE_URL: "https://dev.pocket.deprived.dev/", +}; +export default env; + +// Check if ?debug=1 or debug in localstorage is 1 or true +export function checkIfDev(): boolean { + if (typeof window === "undefined") return false; + + try { + const params = new URL(window.location.href).searchParams; + const urlDebug = params.get("debug"); + + const ls = window.localStorage?.getItem("debug") ?? ""; + const lsDebug = ls.toLowerCase(); + + const isUrlDebug = urlDebug === "1"; + const isLocalDebug = lsDebug === "1" || lsDebug === "true"; + + return isUrlDebug || isLocalDebug; + } catch { + return false; + } +} + +// Load overrides from localstorage +function loadOverrides() { + for (const [name, val] of Object.entries(env)) { + const envOverride = localStorage.getItem(name); + if (envOverride) { + env[name] = envOverride; + console.log("Env var +: " + name + "=" + val); + } else { + console.log("Env var loaded: " + name + "=" + val); + } + } +} + +loadOverrides(); diff --git a/src/ts/Redaction/Redactor.ts b/src/ts/Redaction/Redactor.ts index 055c6d8..9642fbb 100644 --- a/src/ts/Redaction/Redactor.ts +++ b/src/ts/Redaction/Redactor.ts @@ -1,4 +1,5 @@ import { parseProfile, type Profile } from "./Profile"; +import env from "@ts/EnvHandler"; class Redactor { public unredactedProfile: Profile | undefined = undefined; @@ -23,7 +24,7 @@ class Redactor { const unredactHash = hashResJson.response; console.log('Trying unredact hash: "' + unredactHash + '"'); - const url = `https://pocket.deprived.dev/api/files/redacted_content/${unredactHash}/redacted_cv_info_ha08bbn520.json`; + const url = `https://${env.POCKETBASE_URL}/api/files/redacted_content/${unredactHash}/redacted_cv_info_ha08bbn520.json`; const res = await fetch(url, { method: "GET", @@ -35,7 +36,6 @@ class Redactor { return parseProfile(data); } - // TS/JS async t(unredactPath: string, fallback: string): Promise { try { if (!this.unredactedProfile) await this.TryGetUnredacter();