Famous people: admin page, own prompt, one photo, public pages
CI / test (push) Successful in 2m21s
CI / build (push) Skipped
CI / deploy (push) Skipped

- Admin "Híres emberek": birth data, one photo (S3: DigitalOcean Spaces in
  production, RustFS in development), a face point that every crop keeps
  in view, publishing, and a detailed portrait written with its own
  `celebrity` prompt (third person, by name, from the chart alone).
- The photo is stored once (upright JPEG, at most 2000 px, no metadata);
  next/image makes the sizes from it, so Cloudflare can cache those.
- Public list and pages (/hires-emberek), in the sitemap, with a share
  image showing the face and the chart.
- Share images: the wheel's glyphs and numbers are drawn with the card's
  fonts (inside the SVG image they came out as boxes, on every card).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
feco
2026-11-22 16:08:35 +00:00
co-authored by Claude Opus 5.5
parent 13e22a9c7d
commit 37cb0abf4b
47 changed files with 3008 additions and 77 deletions
@@ -14,6 +14,7 @@ const KINDS: Record<string, string> = {
natal: "képletelemzés",
synastry: "kapcsolati",
forecast: "előrejelzés",
celebrity: "híres ember",
question: "válasz",
};
const OUTCOMES: Record<GenerationError["outcome"], { label: string; tone: string }> = {
@@ -0,0 +1,139 @@
"use client";
import Link from "next/link";
import { useRouter } from "next/navigation";
import { useEffect, useState } from "react";
import { BirthForm } from "@/app/profil/BirthForm";
import { api, errorText } from "@/lib/api";
import { signName } from "@/lib/astro";
import type { AdminCelebrity, AdminCelebrityRow } from "@/lib/types";
export const ANALYSIS_STATUS: Record<string, string> = {
pending: "sorban áll",
running: "készül",
done: "kész",
failed: "sikertelen",
};
/** The famous people (drafts too) and the form for a new one. */
export function AdminCelebrities() {
const router = useRouter();
const [rows, setRows] = useState<AdminCelebrityRow[] | null>(null);
const [error, setError] = useState<string | null>(null);
const [adding, setAdding] = useState(false);
const [subtitle, setSubtitle] = useState("");
useEffect(() => {
api<{ celebrities: AdminCelebrityRow[] }>("/admin/celebrities")
.then((r) => setRows(r.celebrities))
.catch((e) => setError(errorText(e)));
}, []);
return (
<section className="field" style={{ gap: 18 }}>
{adding ? (
<div className="card field" style={{ gap: 16 }}>
<h2>Új híres ember</h2>
<BirthForm
initial={null}
person={{}}
save={(name, birth) =>
api<AdminCelebrity>("/admin/celebrities", { body: { name, subtitle: subtitle.trim() || null, birth } })
}
onCancel={() => setAdding(false)}
onSaved={(id) => router.push(`/admin/hires-emberek/${id}`)}
>
<SubtitleField value={subtitle} onChange={setSubtitle} />
</BirthForm>
<p className="hint">
Mentés után kiszámolja a képletet, és elindítja a részletes portré írását. Utána tölthetsz fel fotót.
</p>
</div>
) : (
<div className="form-actions">
<button type="button" className="btn btn-primary" onClick={() => setAdding(true)}>
Új híres ember
</button>
<Link href="/hires-emberek" className="btn btn-ghost">
Nyilvános lista
</Link>
</div>
)}
{error && (
<p className="msg msg-error" role="alert">
{error}
</p>
)}
{rows === null ? (
!error && <p className="muted">Betöltés…</p>
) : rows.length === 0 ? (
<p className="muted">Még nincs híres ember.</p>
) : (
<div className="table-wrap">
<table className="promo-table">
<thead>
<tr>
<th>Név</th>
<th>Született</th>
<th>Nap · Hold · Asc</th>
<th>Portré</th>
<th>Fotó</th>
<th>Állapot</th>
</tr>
</thead>
<tbody>
{rows.map((c) => (
<tr key={c.id}>
<td>
<Link href={`/admin/hires-emberek/${c.id}`}>{c.name}</Link>
{c.subtitle && <span className="hint">{c.subtitle}</span>}
</td>
<td className="num">
{c.birth.date}
{c.birth.time ? ` ${c.birth.time}` : ""}
{c.birth.place && <span className="hint">{c.birth.place}</span>}
</td>
<td>
{[c.highlights.sun, c.highlights.moon, c.highlights.time_known ? c.highlights.ascendant : null]
.map((s) => (s ? signName(s) : "–"))
.join(" · ")}
</td>
<td>{c.analysis_status ? ANALYSIS_STATUS[c.analysis_status] : <span className="muted">–</span>}</td>
<td>{c.has_photo ? "van" : <span className="muted">nincs</span>}</td>
<td>
{c.published ? (
<Link href={`/hires-emberek/${c.slug}`} className="promo-open">
közzétéve
</Link>
) : (
<span className="muted">vázlat</span>
)}
</td>
</tr>
))}
</tbody>
</table>
</div>
)}
</section>
);
}
/** The line under the name, e.g. "színésznő, énekesnő". */
export function SubtitleField({ value, onChange }: { value: string; onChange: (v: string) => void }) {
return (
<div className="field" style={{ maxWidth: 420 }}>
<label htmlFor="celeb-subtitle">Egy sor a név alatt (nem kötelező)</label>
<input
id="celeb-subtitle"
className="inp"
value={value}
maxLength={160}
placeholder="pl. színésznő, énekesnő"
onChange={(e) => onChange(e.target.value)}
/>
</div>
);
}
@@ -0,0 +1,399 @@
"use client";
import Link from "next/link";
import { useRouter } from "next/navigation";
import { useCallback, useEffect, useRef, useState } from "react";
import { BirthForm } from "@/app/profil/BirthForm";
import { AnalysisView } from "@/components/AnalysisView";
import { RegenerateButton } from "@/components/RegenerateButton";
import { ApiError, api, errorText } from "@/lib/api";
import { signName } from "@/lib/astro";
import { objectPosition, photoSrc } from "@/lib/celebrityPhoto";
import type { AdminCelebrity, Analysis } from "@/lib/types";
import { ANALYSIS_STATUS, SubtitleField } from "../AdminCelebrities";
const POLL_MS = 10_000;
/** Everything about one famous person: photo and face point, texts, publishing, portrait, birth data. */
export function CelebrityEditor({ id }: { id: string }) {
const router = useRouter();
const [c, setC] = useState<AdminCelebrity | null>(null);
const [error, setError] = useState<string | null>(null);
const url = `/admin/celebrities/${id}`;
const load = useCallback(async () => {
try {
setC(await api<AdminCelebrity>(url));
} catch (e) {
setError(errorText(e));
}
}, [url]);
useEffect(() => {
load();
}, [load]);
// A portrait being written: look again now and then.
const writing = c?.analysis?.status === "pending" || c?.analysis?.status === "running";
useEffect(() => {
if (!writing) return;
const t = setInterval(load, POLL_MS);
return () => clearInterval(t);
}, [writing, load]);
if (!c) {
return error ? (
<p className="msg msg-error" role="alert">
{error}
</p>
) : (
<p className="muted">Betöltés…</p>
);
}
async function patch(body: object) {
setError(null);
try {
setC(await api<AdminCelebrity>(url, { method: "PATCH", body }));
return true;
} catch (e) {
setError(errorText(e));
return false;
}
}
async function remove() {
if (!c || !window.confirm(`Biztosan törlöd: ${c.name}? A képlet, a portré és a fotó is törlődik.`)) return;
try {
await api(url, { method: "DELETE" });
router.push("/admin/hires-emberek");
} catch (e) {
setError(errorText(e));
}
}
return (
<div className="field" style={{ gap: 20 }}>
<div className="page-head">
<span className="eyebrow">
<Link href="/admin/hires-emberek">Híres emberek</Link>
</span>
<h1>{c.name}</h1>
<p className="muted">
{c.birth.date}
{c.birth.time ? ` ${c.birth.time}` : " (idő nélkül)"}
{c.birth.place ? `, ${c.birth.place}` : ""} ·{" "}
{[c.highlights.sun, c.highlights.moon, c.highlights.time_known ? c.highlights.ascendant : null]
.filter(Boolean)
.map((s) => signName(s as string))
.join(" · ")}
</p>
<div className="form-actions">
<button type="button" className="btn btn-primary" onClick={() => patch({ published: !c.published })}>
{c.published ? "Visszavonás vázlatba" : "Közzététel"}
</button>
<Link href={`/hires-emberek/${c.slug}`} className="btn btn-ghost" target="_blank">
{c.published ? "Nyilvános oldal" : "Előnézet"}
</Link>
<span className={c.published ? "promo-open" : "muted"}>{c.published ? "közzétéve" : "vázlat"}</span>
</div>
</div>
{error && (
<p className="msg msg-error" role="alert">
{error}
</p>
)}
<PhotoSection c={c} url={url} onChange={setC} onFocus={(x, y) => patch({ focus_x: x, focus_y: y })} />
<TextsSection key={c.updated_at} c={c} onSave={patch} />
<AnalysisSection c={c} url={url} onChange={setC} onAnalysis={(a) => setC({ ...c, analysis: a })} />
<section className="card field" style={{ gap: 14 }}>
<h2>Születési adatok</h2>
<p className="hint">
Ha a javítás után más lesz a képlet, a portré törlődik, és újra elkészül az új képletből.
</p>
<BirthForm
key={JSON.stringify(c.birth_data)}
initial={{ ...c.birth_data, placeName: c.birth.place, region: c.birth.region }}
person={{ chartId: c.id, name: c.name }}
save={async (name, birth) => {
const next = await api<AdminCelebrity>(url, { method: "PATCH", body: birth ? { name, birth } : { name } });
setC(next);
return next;
}}
onSaved={() => undefined}
/>
</section>
<section className="card field" style={{ gap: 10 }}>
<h2>Törlés</h2>
<p className="hint">A képlet, a portré és a fotó is törlődik; a nyilvános oldal megszűnik.</p>
<div className="form-actions">
<button type="button" className="btn btn-ghost" onClick={remove}>
{c.name} törlése
</button>
</div>
</section>
</div>
);
}
/** Upload, the face point (a click on the photo) and how the crops will look. */
function PhotoSection({
c,
url,
onChange,
onFocus,
}: {
c: AdminCelebrity;
url: string;
onChange: (c: AdminCelebrity) => void;
onFocus: (x: number, y: number) => void;
}) {
const [busy, setBusy] = useState(false);
const [error, setError] = useState<string | null>(null);
const input = useRef<HTMLInputElement>(null);
const photo = c.photo;
async function upload(file: File) {
setBusy(true);
setError(null);
try {
// The image itself is the body (the backend makes the stored JPEG).
const res = await fetch(`/api/v1${url}/photo`, {
method: "PUT",
headers: { "content-type": file.type || "application/octet-stream" },
body: file,
credentials: "same-origin",
});
const data = await res.json().catch(() => null);
if (!res.ok) {
const err = data?.error ?? {};
throw new ApiError(res.status, err.code ?? "error", err.message ?? `HTTP ${res.status}`);
}
onChange(data as AdminCelebrity);
} catch (e) {
setError(errorText(e));
} finally {
setBusy(false);
if (input.current) input.current.value = "";
}
}
async function removePhoto() {
if (!window.confirm("Törlöd a fotót?")) return;
try {
onChange(await api<AdminCelebrity>(`${url}/photo`, { method: "DELETE" }));
} catch (e) {
setError(errorText(e));
}
}
function pick(e: React.MouseEvent<HTMLButtonElement>) {
const r = e.currentTarget.getBoundingClientRect();
const x = Math.min(1, Math.max(0, (e.clientX - r.left) / r.width));
const y = Math.min(1, Math.max(0, (e.clientY - r.top) / r.height));
onFocus(Math.round(x * 1000) / 1000, Math.round(y * 1000) / 1000);
}
return (
<section className="card field" style={{ gap: 14 }}>
<h2>Fotó</h2>
<p className="hint">
Egy fotó kell (JPEG, PNG vagy WebP, legfeljebb 15 MB). Feltöltés után kattints az arcra: minden kivágás
(megosztási kép, oldal, lista) e pont köré igazodik.
</p>
{photo && (
<div className="celeb-editor-photo">
<button type="button" className="celeb-focus" onClick={pick} aria-label="Az arc helye: kattints az arcra">
{/* The stored original, for clicking: no optimizer needed here. */}
{/* eslint-disable-next-line @next/next/no-img-element */}
<img src={photoSrc(photo)} alt={c.name} width={photo.width} height={photo.height} />
<span
className="celeb-focus-mark"
style={{ left: `${photo.focus_x * 100}%`, top: `${photo.focus_y * 100}%` }}
aria-hidden="true"
/>
</button>
<div className="celeb-crops" aria-label="Kivágások">
<figure>
<span className="celeb-crop" style={{ aspectRatio: "440 / 630" }}>
{/* eslint-disable-next-line @next/next/no-img-element */}
<img src={photoSrc(photo)} alt="" style={{ objectPosition: objectPosition(photo) }} />
</span>
<figcaption className="hint">Megosztási kép</figcaption>
</figure>
<figure>
<span className="celeb-crop" style={{ aspectRatio: "4 / 5" }}>
{/* eslint-disable-next-line @next/next/no-img-element */}
<img src={photoSrc(photo)} alt="" style={{ objectPosition: objectPosition(photo) }} />
</span>
<figcaption className="hint">Oldal</figcaption>
</figure>
<figure>
<span className="celeb-crop" style={{ aspectRatio: "1 / 1" }}>
{/* eslint-disable-next-line @next/next/no-img-element */}
<img src={photoSrc(photo)} alt="" style={{ objectPosition: objectPosition(photo) }} />
</span>
<figcaption className="hint">Lista</figcaption>
</figure>
</div>
</div>
)}
<div className="form-actions">
<input
ref={input}
type="file"
accept="image/jpeg,image/png,image/webp"
className="sr-only"
id="celeb-photo-input"
onChange={(e) => {
const file = e.target.files?.[0];
if (file) upload(file);
}}
/>
<label htmlFor="celeb-photo-input" className="btn" aria-disabled={busy}>
{busy ? "Feltöltés…" : photo ? "Másik fotó" : "Fotó feltöltése"}
</label>
{photo && (
<button type="button" className="btn btn-ghost" onClick={removePhoto} disabled={busy}>
Fotó törlése
</button>
)}
<Link href={`/hires-emberek/${c.slug}/kep/elonezet.png`} target="_blank" className="btn btn-ghost">
Megosztási kép megnyitása
</Link>
</div>
{error && (
<p className="msg msg-error" role="alert">
{error}
</p>
)}
</section>
);
}
/** Name, the line under it and the address of the page. */
function TextsSection({ c, onSave }: { c: AdminCelebrity; onSave: (body: object) => Promise<boolean> }) {
const [name, setName] = useState(c.name);
const [subtitle, setSubtitle] = useState(c.subtitle ?? "");
const [slug, setSlug] = useState(c.slug);
const [busy, setBusy] = useState(false);
const [saved, setSaved] = useState(false);
const changed = name.trim() !== c.name || subtitle.trim() !== (c.subtitle ?? "") || slug.trim() !== c.slug;
async function save(e: React.FormEvent) {
e.preventDefault();
setBusy(true);
setSaved(await onSave({ name: name.trim(), subtitle: subtitle.trim() || null, slug: slug.trim() }));
setBusy(false);
}
return (
<form className="card field" style={{ gap: 14 }} onSubmit={save}>
<h2>Név és cím</h2>
<div className="grid-2">
<div className="field">
<label htmlFor="celeb-name">Név</label>
<input id="celeb-name" className="inp" value={name} maxLength={100} required onChange={(e) => setName(e.target.value)} />
</div>
<SubtitleField value={subtitle} onChange={setSubtitle} />
</div>
<div className="field" style={{ maxWidth: 520 }}>
<label htmlFor="celeb-slug">Az oldal címe</label>
<input
id="celeb-slug"
className="inp"
value={slug}
maxLength={80}
pattern="[a-z0-9]+(-[a-z0-9]+)*"
title="Csak kisbetű, szám és kötőjel (pl. marilyn-monroe)."
onChange={(e) => setSlug(e.target.value)}
/>
<span className="hint">sorsfonalak.hu/hires-emberek/{slug || "…"}</span>
</div>
<p className="hint">
A név a portré szövegében is szerepel: ha jelentősen javítod, a portrét érdemes újragenerálni.
</p>
<div className="form-actions">
<button type="submit" className="btn btn-primary" disabled={busy || !changed}>
{busy ? "Mentés…" : "Mentés"}
</button>
{saved && !changed && <span className="msg msg-ok">Elmentve.</span>}
</div>
</form>
);
}
/** The portrait: its state, the text, writing it again. */
function AnalysisSection({
c,
url,
onChange,
onAnalysis,
}: {
c: AdminCelebrity;
url: string;
onChange: (c: AdminCelebrity) => void;
onAnalysis: (a: Analysis) => void;
}) {
const [error, setError] = useState<string | null>(null);
const [open, setOpen] = useState(false);
const a = c.analysis;
async function start() {
setError(null);
try {
onChange(await api<AdminCelebrity>(`${url}/analysis`, { method: "POST" }));
} catch (e) {
setError(errorText(e));
}
}
return (
<section className="card field" style={{ gap: 14 }}>
<h2>Részletes portré</h2>
<p className="hint">
Saját prompttal készül (Promptok → <Link href="/admin/promptok">Híres ember</Link>), harmadik személyben, csak a
képletből; elemzést nem használ fel.
</p>
{!a ? (
<p className="muted">Még nincs portré.</p>
) : (
<p>
Állapot: <strong>{ANALYSIS_STATUS[a.status] ?? a.status}</strong>
{a.status === "failed" && a.error && <span className="hint"> ({a.error})</span>}
{(a.status === "pending" || a.status === "running") && (a.attempts ?? 0) > 1 && (
<span className="hint"> · {a.attempts}. próbálkozás</span>
)}
</p>
)}
<div className="form-actions">
{(!a || a.status === "failed") && (
<button type="button" className="btn btn-primary" onClick={start}>
Portré írása
</button>
)}
{a?.status === "done" && (
<>
<button type="button" className="btn btn-ghost" onClick={() => setOpen((o) => !o)}>
{open ? "Szöveg elrejtése" : "Szöveg megnézése"}
</button>
<RegenerateButton<Analysis> url={`/admin/analyses/${a.id}/regenerate`} onStarted={onAnalysis} />
</>
)}
</div>
{error && (
<p className="msg msg-error" role="alert">
{error}
</p>
)}
{open && a?.status === "done" && a.content && (
<AnalysisView content={a.content} kind="celebrity" language={a.language} />
)}
</section>
);
}
@@ -0,0 +1,23 @@
import type { Metadata } from "next";
import { notFound } from "next/navigation";
import { AdminNav } from "@/components/AdminNav";
import { requireMe } from "@/lib/server";
import { CelebrityEditor } from "./CelebrityEditor";
export const metadata: Metadata = { title: "Híres ember" };
type Props = { params: Promise<{ id: string }> };
export default async function AdminCelebrityPage({ params }: Props) {
const { id } = await params;
const me = await requireMe(`/admin/hires-emberek/${id}`);
if (!me.user.roles.includes("admin")) notFound();
return (
<main className="page" style={{ maxWidth: 1180 }}>
<AdminNav current="/admin/hires-emberek" />
<CelebrityEditor id={id} />
</main>
);
}
@@ -0,0 +1,28 @@
import type { Metadata } from "next";
import { notFound } from "next/navigation";
import { AdminNav } from "@/components/AdminNav";
import { requireMe } from "@/lib/server";
import { AdminCelebrities } from "./AdminCelebrities";
export const metadata: Metadata = { title: "Híres emberek" };
export default async function AdminCelebritiesPage() {
const me = await requireMe("/admin/hires-emberek");
if (!me.user.roles.includes("admin")) notFound();
return (
<main className="page" style={{ maxWidth: 1180 }}>
<AdminNav current="/admin/hires-emberek" />
<div className="page-head">
<h1>Híres emberek</h1>
<p className="muted">
Születési adat, egy fotó és egy részletes portré (saját prompt: Promptok → Híres ember). Közzététel után a
nyilvános oldalon (sorsfonalak.hu/hires-emberek) és a keresőkben is megjelenik; megosztáskor az előnézeti
képen az arc és a képlet látszik.
</p>
</div>
<AdminCelebrities />
</main>
);
}
@@ -10,6 +10,7 @@ const KINDS: Record<AdminJob["kind"], string> = {
natal: "Képletelemzés",
synastry: "Kapcsolati elemzés",
forecast: "Éves előrejelzés",
celebrity: "Híres ember",
question: "Kérdés-válasz",
};
@@ -5,7 +5,7 @@ import { useEffect, useState } from "react";
import { Tabs } from "@/components/Tabs";
import { api, errorText } from "@/lib/api";
import { formatDate } from "@/lib/astro";
import type { AdminPrompt, ChartListItem, PromptKind } from "@/lib/types";
import type { AdminCelebrityRow, AdminPrompt, ChartListItem, PromptKind } from "@/lib/types";
import { PromptTrial } from "./PromptTrial";
@@ -35,6 +35,13 @@ const KINDS: { kind: PromptKind; id: string; label: string; about: string }[] =
about:
"Fizetős elemzés egy születésnaptól a következőig: szolár, lassú tranzitok, progresszió, profekció, fogyatkozások. Öt fejezet, lehetőségek, kihívások és útravaló. Kérésre készül.",
},
{
kind: "celebrity",
id: "hires-ember",
label: "Híres ember",
about:
"A híres emberek nyilvános oldalának részletes portréja: ugyanaz a hat fejezet, mint a részletes elemzésé, de harmadik személyben, a nevén nevezve, csak a képletből (az életrajzát nem használja). A modell a nevet és a képlet adatait kapja. Az admin oldalon készül (Híres emberek).",
},
{
kind: "question",
id: "kerdesek",
@@ -49,6 +56,8 @@ const LANGUAGES: Record<string, string> = { hu: "Magyar", en: "Angol" };
export function AdminPrompts() {
const [prompts, setPrompts] = useState<AdminPrompt[] | null>(null);
const [charts, setCharts] = useState<ChartListItem[]>([]);
// The famous people's charts, for trying their prompt.
const [famous, setFamous] = useState<ChartListItem[]>([]);
const [error, setError] = useState<string | null>(null);
useEffect(() => {
@@ -58,6 +67,22 @@ export function AdminPrompts() {
api<{ charts: ChartListItem[] }>("/charts")
.then((d) => setCharts(d.charts))
.catch(() => setCharts([]));
api<{ celebrities: AdminCelebrityRow[] }>("/admin/celebrities")
.then((d) =>
setFamous(
d.celebrities.map((c) => ({
id: c.chart_id,
label: c.name,
is_primary: false,
kind: "person",
editable_until: null,
birth: { date: c.birth.date, time: c.birth.time, place: c.birth.place },
highlights: c.highlights,
created_at: "",
})),
),
)
.catch(() => setFamous([]));
}, []);
if (error) {
@@ -83,7 +108,7 @@ export function AdminPrompts() {
<KindPrompts
about={k.about}
prompts={prompts.filter((p) => p.kind === k.kind)}
charts={charts}
charts={k.kind === "celebrity" ? famous : charts}
onSaved={replace}
/>
),