progress
All checks were successful
Rebuild signaller for deprived.dev to rebuild site / test_service (push) Successful in 15s

This commit is contained in:
BOTAlex 2025-10-07 18:16:08 +02:00
parent 5e1cf0a83b
commit ff613a2798

View file

@ -1,7 +1,11 @@
import { parseProfile, type Profile } from "./Profile"; import { parseProfile, type Profile } from "./Profile";
class Redactor { class Redactor {
public unredactedProfile: Profile | undefined = undefined;
async TryGetUnredacter(): Promise<Profile> { async TryGetUnredacter(): Promise<Profile> {
if (!!this.unredactedProfile) return this.unredactedProfile;
const storedKey = localStorage.getItem("key"); const storedKey = localStorage.getItem("key");
if (!storedKey) throw new Error("Missing key"); if (!storedKey) throw new Error("Missing key");
@ -30,6 +34,21 @@ class Redactor {
const data = await res.json(); const data = await res.json();
return parseProfile(data); return parseProfile(data);
} }
// TS/JS
async t(unredactPath: string, fallback: string): Promise<string> {
try {
if (!this.unredactedProfile) await this.TryGetUnredacter();
const src = this.unredactedProfile ?? {};
// safe dot-path lookup
const value = unredactPath.split(".").reduce<any>((o, k) => o?.[k], src);
return (value ?? "") !== "" ? String(value) : fallback;
} catch {
return fallback;
}
}
} }
export let re = new Redactor(); export let re = new Redactor();