redacted my info, into my database #1
3 changed files with 44 additions and 12 deletions
10
src/env.d.ts
vendored
10
src/env.d.ts
vendored
|
|
@ -1,10 +0,0 @@
|
||||||
/// <reference types="vite/client" />
|
|
||||||
|
|
||||||
interface ImportMetaEnv {
|
|
||||||
readonly PUBLIC_URL_BASE: string;
|
|
||||||
readonly PUBLIC_POCKET_URL: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface ImportMeta {
|
|
||||||
readonly env: ImportMetaEnv;
|
|
||||||
}
|
|
||||||
42
src/ts/EnvHandler.ts
Normal file
42
src/ts/EnvHandler.ts
Normal file
|
|
@ -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();
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import { parseProfile, type Profile } from "./Profile";
|
import { parseProfile, type Profile } from "./Profile";
|
||||||
|
import env from "@ts/EnvHandler";
|
||||||
|
|
||||||
class Redactor {
|
class Redactor {
|
||||||
public unredactedProfile: Profile | undefined = undefined;
|
public unredactedProfile: Profile | undefined = undefined;
|
||||||
|
|
@ -23,7 +24,7 @@ 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://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, {
|
const res = await fetch(url, {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
|
|
@ -35,7 +36,6 @@ class Redactor {
|
||||||
return parseProfile(data);
|
return parseProfile(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TS/JS
|
|
||||||
async t(unredactPath: string, fallback: string): Promise<string> {
|
async t(unredactPath: string, fallback: string): Promise<string> {
|
||||||
try {
|
try {
|
||||||
if (!this.unredactedProfile) await this.TryGetUnredacter();
|
if (!this.unredactedProfile) await this.TryGetUnredacter();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue