diff --git a/services/backend/src/routes/errors.rs b/services/backend/src/routes/errors.rs index 620008a..994bf7b 100644 --- a/services/backend/src/routes/errors.rs +++ b/services/backend/src/routes/errors.rs @@ -1,8 +1,10 @@ //! Admin: the error log of the analyses, answers and prompt test runs (every -//! failed attempt, written by the worker), newest first. +//! failed attempt, written by the worker), newest first. Entries can be +//! deleted one by one or all that match a filter. use axum::Json; -use axum::extract::{Query, State}; +use axum::extract::{Path, Query, State}; +use axum::http::StatusCode; use axum_extra::extract::WithRejection; use serde::Deserialize; use serde_json::{Value, json}; @@ -71,3 +73,41 @@ pub async fn list( .collect(); Ok(Json(json!({ "errors": errors, "total": total, "last_day": last_day, "limit": limit, "offset": offset }))) } + +#[derive(Deserialize)] +#[serde(deny_unknown_fields)] +pub struct DeleteQuery { + source: Option, + outcome: Option, +} + +/// Deletes every entry matching the filter (none given: all of them). +pub async fn delete_matching( + State(state): St, + AdminUser(admin): AdminUser, + WithRejection(Query(query), _): WithRejection, ApiError>, +) -> ApiResult> { + let deleted = sqlx::query( + "DELETE FROM generation_errors WHERE ($1::text IS NULL OR source = $1) AND ($2::text IS NULL OR outcome = $2)", + ) + .bind(&query.source) + .bind(&query.outcome) + .execute(&state.db) + .await? + .rows_affected(); + tracing::info!(admin = %admin.id(), deleted, "error log entries deleted"); + Ok(Json(json!({ "deleted": deleted }))) +} + +/// Deletes one entry. +pub async fn delete_one( + State(state): St, + _admin: AdminUser, + WithRejection(Path(id), _): WithRejection, ApiError>, +) -> ApiResult { + let result = sqlx::query("DELETE FROM generation_errors WHERE id = $1").bind(id).execute(&state.db).await?; + if result.rows_affected() == 0 { + return Err(ApiError::NotFound("error")); + } + Ok(StatusCode::NO_CONTENT) +} diff --git a/services/backend/src/routes/mod.rs b/services/backend/src/routes/mod.rs index 8ee82fb..73380e1 100644 --- a/services/backend/src/routes/mod.rs +++ b/services/backend/src/routes/mod.rs @@ -147,7 +147,8 @@ pub fn router(state: Arc) -> Router { .route("/v1/admin/prompts/{kind}/{language}", axum::routing::put(prompts::save)) .route("/v1/admin/prompts/{kind}/{language}/preview", post(prompts::start_preview)) .route("/v1/admin/previews/{id}", get(prompts::get_preview)) - .route("/v1/admin/errors", get(errors::list)) + .route("/v1/admin/errors", get(errors::list).delete(errors::delete_matching)) + .route("/v1/admin/errors/{id}", axum::routing::delete(errors::delete_one)) .route("/v1/admin/jobs", get(jobs::list)) .route("/v1/admin/jobs/restart", post(jobs::restart)) .route("/v1/admin/models", get(models::list)) diff --git a/services/backend/src/tests.rs b/services/backend/src/tests.rs index 375ba4a..ff99f03 100644 --- a/services/backend/src/tests.rs +++ b/services/backend/src/tests.rs @@ -2214,6 +2214,19 @@ async fn admins_read_the_error_log(pool: PgPool) { let r = app.get("/v1/admin/errors?outcome=retry", Some(&admin)).await; assert_eq!(r.body["errors"].as_array().unwrap().len(), 1); assert_eq!(app.get("/v1/admin/errors?source=question", Some(&admin)).await.body["total"], 0); + // deleted one by one, or all that match the filter + let retry_id = r.body["errors"][0]["id"].as_i64().unwrap(); + let r = app.call("DELETE", &format!("/v1/admin/errors/{retry_id}"), Some(&anna), None).await; + assert_eq!(r.status, StatusCode::FORBIDDEN); + let r = app.call("DELETE", &format!("/v1/admin/errors/{retry_id}"), Some(&admin), None).await; + assert_eq!(r.status, StatusCode::NO_CONTENT); + let r = app.call("DELETE", &format!("/v1/admin/errors/{retry_id}"), Some(&admin), None).await; + assert_eq!(r.status, StatusCode::NOT_FOUND); + let r = app.call("DELETE", "/v1/admin/errors?outcome=retry", Some(&admin), None).await; + assert_eq!(r.body["deleted"], 0); + let r = app.call("DELETE", "/v1/admin/errors?source=analysis", Some(&admin), None).await; + assert_eq!((r.status, &r.body["deleted"]), (StatusCode::OK, &json!(1)), "{}", r.body); + assert_eq!(app.get("/v1/admin/errors", Some(&admin)).await.body["total"], 0); // users see the attempts of their analysis (the page says it is tried again) let r = app.get(&format!("/v1/analyses/{analysis}"), Some(&anna)).await; assert_eq!(r.body["attempts"], 0); diff --git a/services/frontend/src/app/Landing.tsx b/services/frontend/src/app/Landing.tsx index c99e06a..26a6bbe 100644 --- a/services/frontend/src/app/Landing.tsx +++ b/services/frontend/src/app/Landing.tsx @@ -4,7 +4,6 @@ import { ChartWheel } from "@/components/ChartWheel"; import { Rich } from "@/components/Rich"; import { TarotCard, TarotCardBack } from "@/components/tarot/TarotCard"; import { Logo, PublicHeader } from "@/components/SiteHeader"; -import { Waitlist } from "@/components/Waitlist"; import example from "@/content/pelda.json"; import { tarotCard } from "@/lib/tarot"; import type { AnalysisContent, ChartResult } from "@/lib/types"; @@ -84,8 +83,7 @@ export function Landing({ inviteOnly }: { inviteOnly: boolean }) {

{inviteOnly ? ( <> - Az oldal egyelőre meghívásos: meghívóval, Google-fiókkal lépsz be. Ha még nincs meghívód,{" "} - iratkozz fel a várólistára. + Az oldal egyelőre meghívásos: meghívóval, Google-fiókkal lépsz be. ) : ( "A képlet és a rövid összefoglaló ingyenes. Google-fiókkal lépsz be." @@ -458,7 +456,7 @@ export function Landing({ inviteOnly }: { inviteOnly: boolean }) { -

+

Kíváncsi vagy, mit mutat a te képleted?

{inviteOnly - ? "Egyelőre meghívással lehet csatlakozni. Ha kaptál meghívót, lépj be a Google-fiókoddal. Ha még nem, írd fel magad, és szólunk." + ? "Egyelőre meghívással lehet csatlakozni. Ha kaptál meghívót, lépj be a Google-fiókoddal." : "Két perc, és ott a képleted a rövid összefoglalóval együtt."}

{signIn} - {inviteOnly && ( -
- -
- )}

Az elemzéseket mesterséges intelligencia írja a pontosan kiszámolt képlet alapján. Tájékoztató jellegűek, nem helyettesítenek szakmai tanácsot. diff --git a/services/frontend/src/app/admin/hibak/ErrorLog.tsx b/services/frontend/src/app/admin/hibak/ErrorLog.tsx index 9cef345..a4a2630 100644 --- a/services/frontend/src/app/admin/hibak/ErrorLog.tsx +++ b/services/frontend/src/app/admin/hibak/ErrorLog.tsx @@ -6,7 +6,7 @@ import { api, errorText } from "@/lib/api"; import { formatDate } from "@/lib/astro"; import type { GenerationError } from "@/lib/types"; -const PAGE = 100; +const PAGE = 50; const SOURCES: Record = { analysis: "Elemzés", question: "Kérdés-válasz", preview: "Prompt-próba" }; const KINDS: Record = { @@ -33,43 +33,82 @@ interface Page { export function ErrorLog() { const [source, setSource] = useState(""); const [outcome, setOutcome] = useState(""); + const [page, setPage] = useState(0); const [errors, setErrors] = useState(null); const [total, setTotal] = useState(0); const [lastDay, setLastDay] = useState(0); const [busy, setBusy] = useState(false); const [error, setError] = useState(null); - const load = useCallback( - async (offset: number) => { - setBusy(true); - setError(null); - const params = new URLSearchParams({ limit: String(PAGE), offset: String(offset) }); - if (source) params.set("source", source); - if (outcome) params.set("outcome", outcome); - try { - const page = await api(`/admin/errors?${params}`); - setErrors((all) => (offset === 0 ? page.errors : [...(all ?? []), ...page.errors])); - setTotal(page.total); - setLastDay(page.last_day); - } catch (e) { - setError(errorText(e)); - } finally { - setBusy(false); - } - }, - [source, outcome], - ); + const filter = useCallback(() => { + const params = new URLSearchParams(); + if (source) params.set("source", source); + if (outcome) params.set("outcome", outcome); + return params; + }, [source, outcome]); + + const load = useCallback(async () => { + setBusy(true); + setError(null); + const params = filter(); + params.set("limit", String(PAGE)); + params.set("offset", String(page * PAGE)); + try { + const res = await api(`/admin/errors?${params}`); + // The last page emptied by deleting: one page back. + if (res.errors.length === 0 && page > 0) return setPage(Math.max(0, Math.ceil(res.total / PAGE) - 1)); + setErrors(res.errors); + setTotal(res.total); + setLastDay(res.last_day); + } catch (e) { + setError(errorText(e)); + } finally { + setBusy(false); + } + }, [filter, page]); useEffect(() => { - load(0); + load(); }, [load]); + async function removeOne(id: number) { + setError(null); + try { + await api(`/admin/errors/${id}`, { method: "DELETE" }); + await load(); + } catch (e) { + setError(errorText(e)); + } + } + + async function removeMatching() { + const what = source || outcome ? `a szűrésnek megfelelő ${total} bejegyzést` : `mind a ${total} bejegyzést`; + if (!window.confirm(`Biztosan törlöd ${what}? Nem vonható vissza.`)) return; + setBusy(true); + setError(null); + try { + await api(`/admin/errors?${filter()}`, { method: "DELETE" }); + setPage(0); + await load(); + } catch (e) { + setError(errorText(e)); + } finally { + setBusy(false); + } + } + + const pages = Math.max(1, Math.ceil(total / PAGE)); + return (

- { + setSource(e.target.value); + setPage(0); + }} + > {Object.entries(SOURCES).map(([v, l]) => (
- { + setOutcome(e.target.value); + setPage(0); + }} + > {Object.entries(OUTCOMES).map(([v, o]) => (
{error && (

@@ -116,6 +164,9 @@ export function ErrorLog() { Kísérlet Következmény Hiba + + Törlés + @@ -140,16 +191,40 @@ export function ErrorLog() { {OUTCOMES[e.outcome].label} {e.error} + + + ))}

)} - {errors && errors.length < total && ( - + {total > PAGE && ( + )}
); diff --git a/services/frontend/src/app/admin/meghivok/AdminInvitations.tsx b/services/frontend/src/app/admin/meghivok/AdminInvitations.tsx index 0602de8..8eb9f7d 100644 --- a/services/frontend/src/app/admin/meghivok/AdminInvitations.tsx +++ b/services/frontend/src/app/admin/meghivok/AdminInvitations.tsx @@ -5,7 +5,7 @@ import { useCallback, useEffect, useState } from "react"; import { usePackages } from "@/components/PackageCards"; import { api, errorText } from "@/lib/api"; import { formatDate } from "@/lib/astro"; -import type { AdminInvitation, InvitationResult, WaitlistEntry } from "@/lib/types"; +import type { AdminInvitation, InvitationResult } from "@/lib/types"; const MAX_MESSAGE = 300; @@ -33,7 +33,6 @@ const RESULT: Record = { interface ListData { invitations: AdminInvitation[]; - waitlist: WaitlistEntry[]; signup_mode: "invite" | "open"; } @@ -96,7 +95,6 @@ export function AdminInvitations() {

)} {data && } - {data && }
); } @@ -399,117 +397,3 @@ function InvitationRow({ invitation: i, onChange }: { invitation: AdminInvitatio ); } - -function WaitlistTable({ waitlist, onChange }: { waitlist: WaitlistEntry[]; onChange: () => Promise }) { - const [busy, setBusy] = useState(null); - const [note, setNote] = useState(null); - const [pkg, setPkg] = useState(""); - const packages = usePackages(); - - async function invite(w: WaitlistEntry) { - setBusy(w.email); - setNote(null); - try { - const res = await api<{ results: InvitationResult[] }>("/admin/invitations", { - body: { emails: [w.email], locale: w.locale, package: pkg || null }, - }); - const r = res.results[0]; - if (r && r.status !== "invited") setNote(`${r.email}: ${RESULT[r.status]}`); - await onChange(); - } catch (e) { - setNote(errorText(e)); - } finally { - setBusy(null); - } - } - - async function remove(w: WaitlistEntry) { - setBusy(w.email); - setNote(null); - try { - await api(`/admin/waitlist/${encodeURIComponent(w.email)}`, { method: "DELETE" }); - await onChange(); - } catch (e) { - setNote(errorText(e)); - } finally { - setBusy(null); - } - } - - return ( -
-

- Várólista -

-

Akik meghívó nélkül próbáltak belépni, és kérték, hogy szóljunk nekik.

- {waitlist.some((w) => w.invitation === null) && ( -
- - - A „Meghívás” gomb ezzel a csomaggal küldi a meghívót; a regisztrációkor magától jóváíródik. -
- )} - {note && ( -

- {note} -

- )} - {waitlist.length === 0 ? ( -

Üres.

- ) : ( -
- - - - - - - - - - - {waitlist.map((w) => ( - - - - - - - ))} - -
CímFeliratkozottMeghívó - Műveletek -
{w.email}{formatDate(w.created_at)}{w.invitation === "pending" ? "elküldve" : w.invitation === "accepted" ? "elfogadva" : "–"} -
- {w.invitation === null && ( - - )} - -
-
-
- )} -
- ); -} diff --git a/services/frontend/src/app/belepes/AppleLogin.tsx b/services/frontend/src/app/belepes/AppleLogin.tsx index 8eef023..dd91edc 100644 --- a/services/frontend/src/app/belepes/AppleLogin.tsx +++ b/services/frontend/src/app/belepes/AppleLogin.tsx @@ -4,7 +4,6 @@ import Script from "next/script"; import { useRouter } from "next/navigation"; import { useState } from "react"; -import { Waitlist } from "@/components/Waitlist"; import { ApiError, api, errorText } from "@/lib/api"; /** The part of Sign in with Apple JS (appleid.auth.js) we use. */ @@ -136,7 +135,6 @@ export function AppleLogin({ ? "Ez a meghívó már nem érvényes, és ehhez az Apple-fiókhoz sem tartozik másik." : "A Sorsfonalak jelenleg meghívásos, és ehhez az Apple-fiókhoz nem tartozik meghívó. Ha kaptál meghívót, nyisd meg a levélben kapott linket, vagy lépj be azzal a fiókkal, amelynek a címére a meghívó szólt."}

- )} diff --git a/services/frontend/src/app/belepes/GoogleLogin.tsx b/services/frontend/src/app/belepes/GoogleLogin.tsx index 4b3117d..982d1c6 100644 --- a/services/frontend/src/app/belepes/GoogleLogin.tsx +++ b/services/frontend/src/app/belepes/GoogleLogin.tsx @@ -4,7 +4,6 @@ import Script from "next/script"; import { useRouter } from "next/navigation"; import { useCallback, useEffect, useRef, useState } from "react"; -import { Waitlist } from "@/components/Waitlist"; import { ApiError, api, errorText } from "@/lib/api"; /** Google's "G" mark (branding guidelines: unmodified, on the left of the label). */ @@ -130,7 +129,6 @@ export function GoogleLogin({ ? "Ez a meghívó már nem érvényes, és ehhez a Google-fiókhoz sem tartozik másik." : `A Sorsfonalak jelenleg meghívásos, és ${uninvited ? `a(z) ${uninvited} címhez` : "ehhez a fiókhoz"} nem tartozik meghívó. Ha kaptál meghívót egy másik címre, lépj be azzal a Google-fiókkal, vagy nyisd meg a levélben kapott linket.`}

- )} diff --git a/services/frontend/src/app/belepes/PasswordLogin.tsx b/services/frontend/src/app/belepes/PasswordLogin.tsx index 14e6cbf..ad53be0 100644 --- a/services/frontend/src/app/belepes/PasswordLogin.tsx +++ b/services/frontend/src/app/belepes/PasswordLogin.tsx @@ -3,7 +3,6 @@ import { useRouter } from "next/navigation"; import { useState } from "react"; -import { Waitlist } from "@/components/Waitlist"; import { ApiError, api, errorText } from "@/lib/api"; type Mode = "login" | "register" | "forgot"; @@ -178,7 +177,6 @@ export function PasswordLogin({ ? "Ez a meghívó már nem érvényes, és ehhez a címhez sem tartozik másik." : "A Sorsfonalak jelenleg meghívásos, és ehhez az e-mail-címhez nem tartozik meghívó. Ha kaptál meghívót, nyisd meg a levélben kapott linket."}

- )}

diff --git a/services/frontend/src/app/globals.css b/services/frontend/src/app/globals.css index 1d9fe15..2e70fcc 100644 --- a/services/frontend/src/app/globals.css +++ b/services/frontend/src/app/globals.css @@ -982,7 +982,6 @@ a.pair-row:hover strong { color: var(--gold); } .lp-final-inner { max-width: 820px; display: flex; flex-direction: column; align-items: center; gap: 22px; text-align: center; } .lp-emblem { width: 88px; height: 88px; } .lp-emblem-outer { fill: none; stroke: var(--gold); stroke-opacity: 0.5; stroke-width: 1; } -.lp-waitlist { width: 100%; max-width: 520px; text-align: left; } .lp-disclaimer { max-width: 560px; } .lp-footer { border-top: 1px solid var(--line); padding: 28px 0; } .lp-footer-inner { display: flex; gap: 16px; flex-wrap: wrap; align-items: center; justify-content: space-between; } diff --git a/services/frontend/src/components/Waitlist.tsx b/services/frontend/src/components/Waitlist.tsx deleted file mode 100644 index 034dd83..0000000 --- a/services/frontend/src/components/Waitlist.tsx +++ /dev/null @@ -1,67 +0,0 @@ -"use client"; - -import { useState } from "react"; - -import { api, errorText } from "@/lib/api"; - -/** "Tell me when it opens": for visitors without an invitation. */ -export function Waitlist({ email: initial = "" }: { email?: string }) { - const [email, setEmail] = useState(initial); - const [busy, setBusy] = useState(false); - const [done, setDone] = useState(false); - const [error, setError] = useState(null); - - async function submit(e: React.FormEvent) { - e.preventDefault(); - setBusy(true); - setError(null); - try { - await api("/public/waitlist", { body: { email, locale: "hu" } }); - setDone(true); - } catch (err) { - setError(errorText(err)); - } finally { - setBusy(false); - } - } - - if (done) { - return ( -

- Felírtunk. Ha megnyílik az oldal, vagy meghívót küldünk, ide írunk: {email} -

- ); - } - return ( -
-

- Szólunk, ha megnyílik.{" "} - Add meg az e-mail-címed, és felírunk a várólistára. -

-
- - setEmail(e.target.value)} - placeholder="nev@pelda.hu" - style={{ flex: "1 1 220px" }} - /> - -
- {error && ( -

- {error} -

- )} -
- ); -} diff --git a/services/frontend/src/lib/types.ts b/services/frontend/src/lib/types.ts index afcdd68..e4b326a 100644 --- a/services/frontend/src/lib/types.ts +++ b/services/frontend/src/lib/types.ts @@ -511,14 +511,6 @@ export interface AdminInvitation { package: { id: string; name: string | null; code: string | null; redeemed_at: string | null } | null; } -export interface WaitlistEntry { - email: string; - locale: string; - created_at: string; - /** The address's latest invitation, if any. */ - invitation: "pending" | "accepted" | null; -} - export interface InvitationResult { email: string; status: "invited" | "invalid" | "already_user" | "already_invited" | "opted_out";