redacted my info, into my database #1
2 changed files with 46 additions and 32 deletions
|
|
@ -1,42 +1,54 @@
|
||||||
// used to deal with .env things, but with this instead because nix
|
// used to deal with .env things, but with this instead because nix
|
||||||
|
// Drafted manually, then fed through chatgpt
|
||||||
|
// Idk what is going on anymore, but it isn't really an important aspect of the code, since this is just for changing from productiong to dev environment
|
||||||
|
|
||||||
|
type Env = { [K in keyof typeof env]: (typeof env)[K] } & Record<
|
||||||
|
string,
|
||||||
|
unknown
|
||||||
|
>;
|
||||||
|
|
||||||
export let env = {
|
export let env = {
|
||||||
POCKETBASE_URL: "https://pocket.deprived.dev/",
|
POCKETBASE_URL: "https://pocket.deprived.dev",
|
||||||
DEV_POCKETBASE_URL: "https://dev.pocket.deprived.dev/",
|
} as const;
|
||||||
};
|
|
||||||
export default env;
|
export default env;
|
||||||
|
|
||||||
// Check if ?debug=1 or debug in localstorage is 1 or true
|
let initialized = false;
|
||||||
export function checkIfDev(): boolean {
|
|
||||||
if (typeof window === "undefined") return false;
|
|
||||||
|
|
||||||
try {
|
// Load overrides from localstorage or url params
|
||||||
const params = new URL(window.location.href).searchParams;
|
const isOverride = (k: string) => k.startsWith("-E");
|
||||||
const urlDebug = params.get("debug");
|
const norm = (k: string) => k.slice(2); // strip "-E"
|
||||||
|
|
||||||
const ls = window.localStorage?.getItem("debug") ?? "";
|
function apply(from: Record<string, string>, tag: string) {
|
||||||
const lsDebug = ls.toLowerCase();
|
for (const [rawK, rawV] of Object.entries(from)) {
|
||||||
|
env[rawK] = rawV;
|
||||||
const isUrlDebug = urlDebug === "1";
|
|
||||||
const isLocalDebug = lsDebug === "1" || lsDebug === "true";
|
|
||||||
|
|
||||||
return isUrlDebug || isLocalDebug;
|
|
||||||
} catch {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load overrides from localstorage
|
export function initEnv(): void {
|
||||||
function loadOverrides() {
|
if (initialized) return;
|
||||||
for (const [name, val] of Object.entries(env)) {
|
initialized = true;
|
||||||
const envOverride = localStorage.getItem(name);
|
window.env = env!;
|
||||||
if (envOverride) {
|
|
||||||
env[name] = envOverride;
|
// localStorage overrides: only keys starting with "-E"
|
||||||
console.log("Env var +: " + name + "=" + val);
|
const ls: Record<string, string> = {};
|
||||||
} else {
|
for (const [k, v] of Object.entries(env)) {
|
||||||
console.log("Env var loaded: " + name + "=" + val);
|
const val = localStorage.getItem(k);
|
||||||
}
|
if (val != null) ls[k] = val;
|
||||||
}
|
}
|
||||||
|
apply(ls, "localStorage");
|
||||||
|
|
||||||
|
// URL param overrides: ?-EKEY=value
|
||||||
|
const params = new URLSearchParams(location.search);
|
||||||
|
const url: Record<string, string> = {};
|
||||||
|
for (const [k, v] of params.entries()) url[k] = v;
|
||||||
|
apply(url, "url");
|
||||||
|
|
||||||
|
// (optional) persist URL overrides in localStorage with the "-E" prefix
|
||||||
|
for (const [k, v] of Object.entries(url)) {
|
||||||
|
if (isOverride(k)) localStorage.setItem(norm(k), String(v));
|
||||||
}
|
}
|
||||||
|
|
||||||
loadOverrides();
|
// Object.assign(env as any, current);
|
||||||
|
// for (const [k, v] of Object.entries(env))
|
||||||
|
// console.log(`[env final] ${k}=${String(v)}`);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import { parseProfile, type Profile } from "./Profile";
|
import { parseProfile, type Profile } from "./Profile";
|
||||||
import env from "@ts/EnvHandler";
|
import env from "@ts/EnvHandler";
|
||||||
|
import { initEnv } from "@ts/EnvHandler";
|
||||||
|
|
||||||
class Redactor {
|
class Redactor {
|
||||||
public unredactedProfile: Profile | undefined = undefined;
|
public unredactedProfile: Profile | undefined = undefined;
|
||||||
|
|
@ -24,7 +25,8 @@ class Redactor {
|
||||||
const unredactHash = hashResJson.response;
|
const unredactHash = hashResJson.response;
|
||||||
console.log('Trying unredact hash: "' + unredactHash + '"');
|
console.log('Trying unredact hash: "' + unredactHash + '"');
|
||||||
|
|
||||||
const url = `https://${env.POCKETBASE_URL}/api/files/redacted_content/${unredactHash}/redacted_cv_info_ha08bbn520.json`;
|
initEnv();
|
||||||
|
const url = `${env.POCKETBASE_URL}/api/files/redacted_content/${unredactHash}/redacted_cv_info_ha08bbn520.json`;
|
||||||
|
|
||||||
const res = await fetch(url, {
|
const res = await fetch(url, {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue