From ff613a27989bdc28d0fa00e5395e3b605e3a6a21 Mon Sep 17 00:00:00 2001 From: BOTAlex Date: Tue, 7 Oct 2025 18:16:08 +0200 Subject: [PATCH] progress --- src/ts/Redaction/Redactor.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/ts/Redaction/Redactor.ts b/src/ts/Redaction/Redactor.ts index f647531..7aebebd 100644 --- a/src/ts/Redaction/Redactor.ts +++ b/src/ts/Redaction/Redactor.ts @@ -1,7 +1,11 @@ import { parseProfile, type Profile } from "./Profile"; class Redactor { + public unredactedProfile: Profile | undefined = undefined; + async TryGetUnredacter(): Promise { + if (!!this.unredactedProfile) return this.unredactedProfile; + const storedKey = localStorage.getItem("key"); if (!storedKey) throw new Error("Missing key"); @@ -30,6 +34,21 @@ class Redactor { const data = await res.json(); return parseProfile(data); } + + // TS/JS + async t(unredactPath: string, fallback: string): Promise { + try { + if (!this.unredactedProfile) await this.TryGetUnredacter(); + const src = this.unredactedProfile ?? {}; + + // safe dot-path lookup + const value = unredactPath.split(".").reduce((o, k) => o?.[k], src); + + return (value ?? "") !== "" ? String(value) : fallback; + } catch { + return fallback; + } + } } export let re = new Redactor();