local no errors
Some checks failed
Rebuild signaller for deprived.dev to rebuild site / test_service (push) Failing after 9s

This commit is contained in:
BOTAlex 2025-10-03 15:06:40 +02:00
parent a7a53e6fb6
commit 7a21f70144
7 changed files with 104 additions and 5 deletions

View file

@ -0,0 +1,50 @@
// npm i zod
import { z } from "zod";
const Link = z.object({
text: z.string().min(1),
link: z.string().url(),
});
const Experience = z.object({
imageId: z.string().min(1),
name: z.string().min(1),
date: z.string().min(1),
});
const EducationLoose = z.object({
imageId: z.string().min(1).optional(),
name: z.string().min(1).optional(),
});
const ProfileSchema = z.object({
name: z.string().min(1),
shortProfileHiddenContent: z.array(z.string()),
email: z.string().email(),
phone: z.string().min(1),
linkedIn: Link,
itch: Link,
experience: z.array(Experience),
education: z
.array(EducationLoose)
.transform((arr) =>
arr.filter(
(e): e is { imageId: string; name: string } => !!e.imageId && !!e.name,
),
),
});
export type LinkT = z.infer<typeof Link>;
export type ExperienceT = z.infer<typeof Experience>;
export type EducationT = { imageId: string; name: string };
export type Profile = Omit<z.infer<typeof ProfileSchema>, "education"> & {
education: EducationT[];
};
export function parseProfile(json: unknown): Profile {
return ProfileSchema.parse(json);
}
// --- usage ---
// const raw = JSON.parse(yourJsonString);
// const profile = parseProfile(raw);

View file

@ -0,0 +1,25 @@
import PocketBase from "pocketbase";
import { parseProfile, type Profile } from "./Profile";
import { PUBLIC_POCKET_URL } from "$env/static/public";
let pb = new PocketBase(PUBLIC_POCKET_URL);
class Redactor {
async TryGetUnredacter(): Promise<Profile> {
const url =
'https://pocket.deprived.dev/api/collections/redacted_content/records?page=1&perPage=1&filter=plain_id="redacted_json"&skipTotal=1';
const res = await fetch(url, {
body: localStorage.getItem("key"),
method: "GET",
});
if (!res.ok) throw new Error(`HTTP ${res.status}`);
console.log(res);
const data = await res.json();
console.log(data);
const item = data?.items?.[0];
const raw = JSON.parse(item.file);
return parseProfile(raw);
}
}
export let re = new Redactor();

View file

@ -3,8 +3,7 @@
import PocketBase from "pocketbase";
import ShopItem from "./classes/ShopItem";
import { env } from "$env/dynamic/public";
export const PUBLIC_URL_BASE = env.PUBLIC_URL_BASE ?? "";
import { PUBLIC_POCKET_URL } from "$env/static/public";
export let pb = new PocketBase(PUBLIC_POCKET_URL);