Landing page redacted!
All checks were successful
Rebuild signaller for deprived.dev to rebuild site / test_service (push) Successful in 17s

This commit is contained in:
BOTAlex 2025-10-09 02:02:46 +02:00
parent 07f0d798a2
commit 4205712d32
5 changed files with 53 additions and 44 deletions

View file

@ -19,6 +19,7 @@ const EducationLoose = z.object({
const ProfileSchema = z.object({
name: z.string().min(1),
nick: z.string().min(1),
shortProfileHiddenContent: z.array(z.string()),
email: z.string().email(),
phone: z.string().min(1),

View file

@ -1,56 +1,62 @@
// redactor.ts
import { parseProfile, type Profile } from "./Profile";
import env from "@ts/EnvHandler";
import { initEnv } from "@ts/EnvHandler";
import env, { initEnv } from "@ts/EnvHandler";
import type { Readable, Subscriber, Unsubscriber } from "svelte/store";
class Redactor {
class Redactor implements Readable<Profile | undefined> {
public unredactedProfile: Profile | undefined = undefined;
private subs = new Set<Subscriber<Profile | undefined>>();
subscribe(run: Subscriber<Profile | undefined>): Unsubscriber {
this.subs.add(run);
run(this.unredactedProfile);
return () => this.subs.delete(run);
}
private notify() {
this.subs.forEach((s) => s(this.unredactedProfile));
}
async TryGetUnredacter(): Promise<Profile> {
if (!!this.unredactedProfile) return this.unredactedProfile;
if (this.unredactedProfile) return this.unredactedProfile;
const storedKey = localStorage.getItem("key");
if (!storedKey) throw new Error("Missing key");
let jsonKey = JSON.stringify({ key: storedKey });
console.log("Requesting unredactor.json with: " + jsonKey);
const hashResJson = await (
await fetch("https://api.deprived.dev/unredact", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: jsonKey,
body: JSON.stringify({ key: storedKey }),
})
).json();
const unredactHash = hashResJson.response;
console.log('Trying unredact hash: "' + unredactHash + '"');
initEnv();
const url = `${env.POCKETBASE_URL}/api/files/redacted_content/${unredactHash}/redacted_cv_info_ha08bbn520.json`;
const url = `${env.POCKETBASE_URL}/api/files/redacted_content/${unredactHash}/redacted_cv_info_amhz90nhr7.json`;
const res = await fetch(url, {
method: "GET",
headers: { Accept: "application/json" },
});
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const data = await res.json();
return parseProfile(data);
this.unredactedProfile = parseProfile(data);
this.notify(); // <-- tell Svelte to update
return this.unredactedProfile;
}
async t(unredactPath: string, fallback: string): Promise<string> {
t(path: string, fallback: string): 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;
const src = this.unredactedProfile as Record<string, unknown> | undefined;
if (!src) return fallback;
const v = path.split(".").reduce<any>((o, k) => (o as any)?.[k], src);
return (v ?? "") !== "" ? String(v) : fallback;
} catch {
return fallback;
}
}
}
export let re = new Redactor();
export const re = new Redactor();
export default re;