From 92f5cb8fe3b08409dc87b7c197f22a07ecc63494 Mon Sep 17 00:00:00 2001 From: Administrator Date: Fri, 5 Jun 2026 01:51:48 +0800 Subject: [PATCH] enhance admin leaderboard and previews --- .../src/components/html-preview-frame.tsx | 45 ++ .../artifacts/artifact-file-detail.tsx | 172 ++++---- .../workspace/messages/markdown-content.tsx | 128 +++--- frontend-web/src/core/admin/api.ts | 82 ++++ frontend-web/src/core/admin/hooks.ts | 4 +- frontend-web/src/core/utils/markdown.ts | 73 +++- .../src/pages/AdminUserLeaderboardPage.tsx | 395 +++++++++++++----- .../src/pages/PublicScheduledTaskPage.tsx | 7 +- .../src/pages/ScheduledTaskRunDetailPage.tsx | 17 +- .../components/ArtifactPreviewModal.tsx | 20 +- .../app/gateway/routers/admin_users.py | 276 ++++++++++-- 11 files changed, 937 insertions(+), 282 deletions(-) create mode 100644 frontend-web/src/components/html-preview-frame.tsx diff --git a/frontend-web/src/components/html-preview-frame.tsx b/frontend-web/src/components/html-preview-frame.tsx new file mode 100644 index 00000000..2030e398 --- /dev/null +++ b/frontend-web/src/components/html-preview-frame.tsx @@ -0,0 +1,45 @@ +import { useEffect, useState } from "react"; + +import { injectInPageAnchorHandler } from "@/core/utils/markdown"; + +/** + * Sandboxed preview of a generated HTML document. + * + * Renders via a `blob:` URL rather than `srcDoc`. A srcDoc document's base URL + * is `about:srcdoc`, so clicking an in-page anchor (``) + * navigates the frame to `about:blank#section` and BLANKS it. A `blob:` URL is + * a real document URL, so fragment links scroll within the frame as expected — + * all without enabling scripts (the sandbox stays script-free for security; the + * server already sanitizes script vectors and this is defense-in-depth). + * + * The `charset=utf-8` on the blob type is required: a blob: URL whose + * Content-Type omits the charset is decoded with the OS default (GBK/Latin-1 on + * Chinese Windows), garbling CJK text when the HTML lacks a ``. + */ +export function HtmlPreviewFrame({ + html, + className = "h-[70vh] w-full rounded-md border bg-white", +}: { + html: string; + className?: string; +}) { + const [url, setUrl] = useState(); + + useEffect(() => { + const blob = new Blob([injectInPageAnchorHandler(html ?? "")], { + type: "text/html;charset=utf-8", + }); + const objectUrl = URL.createObjectURL(blob); + setUrl(objectUrl); + return () => URL.revokeObjectURL(objectUrl); + }, [html]); + + return ( +