feat(submission): auto-publish approved submissions and expose review tab

- approving a submission now creates the McpService/McpToolApi records
- and records the published service id back on the submission
- review console folded into the admin console as a Submissions tab
- submit page rewritten around the shared submission API
This commit is contained in:
jinghui committed 2026-11-13 15:17:05 +08:00
1 parent d18adf035b
commit 1fbb6711f2
6 files changed
+517 -77

No files matched your search

+21 -4
View File
@@ -12,7 +12,7 @@ import UserManagement from "@/components/user-management/UserManagement";
import RevenueManagement from "@/components/revenue-management/RevenueManagement";
import ConsoleSidebar from "./Sidebar";
import { withComponentInjection } from "@/shared/hooks/useComponentInjection";
import { Boxes, DollarSign, Home, ServerIcon, Users } from "lucide-react";
import { Boxes, DollarSign, Home, Inbox, ServerIcon, Users } from "lucide-react";
import OnboardingWelcome, { REQUIRED_TASK_KEYS } from "./OnboardingWelcome";
import ConsoleStats from "./ConsoleStats";
import SystemSettingsModal from "./SystemSettingsModal";
@@ -24,6 +24,7 @@ import {
updateAdminOnboardingTasks,
} from "@/api/onboard.api";
import ResourceGroupManagement from "../resource-group/resourceGroup";
import { SubmissionsManagement } from "./SubmissionsManagement";
const ConsoleContent: React.FC = () => {
const { t } = useTranslation();
@@ -37,9 +38,13 @@ const ConsoleContent: React.FC = () => {
const tabFromUrl = searchParams.get("tab") as TabKey;
if (
tabFromUrl &&
["mcp-services", "user-management", "revenue-management", "resource-group"].includes(
tabFromUrl
)
[
"mcp-services",
"user-management",
"revenue-management",
"resource-group",
"submissions",
].includes(tabFromUrl)
) {
return tabFromUrl;
}
@@ -69,6 +74,12 @@ const ConsoleContent: React.FC = () => {
label: t("MCP"),
description: t("Manage MCP servers and API tools"),
},
{
key: TabKey.SUBMISSIONS,
icon: <Inbox size={18} />,
label: t("Submissions"),
description: t("Review user submissions and publish to marketplace"),
},
{
key: TabKey.USER_MANAGEMENT,
icon: <Users size={18} />,
@@ -213,6 +224,12 @@ const ConsoleContent: React.FC = () => {
switch (activeTab) {
case TabKey.MCP_SERVICES:
return <MCPServicesManagement />;
case TabKey.SUBMISSIONS:
return (
<div className="h-full overflow-auto">
<SubmissionsManagement />
</div>
);
case TabKey.USER_MANAGEMENT:
return (
<div className="h-full overflow-auto">
@@ -0,0 +1,173 @@
"use client";
import React, { useEffect, useState } from "react";
import { fetchAdminAPI } from "@/rpc/admin-api";
interface Metadata {
base_url?: string;
service_type?: string;
tags?: string;
charge_type?: string;
price?: number;
free_daily_limit?: number | null;
published_service_id?: string;
}
interface Submission {
id: string;
user_id: string;
type: string;
name: string;
description?: string;
file_path?: string;
metadata_json?: Metadata | null;
status: string;
created_at?: string;
review_note?: string;
}
const statusColor: Record<string, string> = {
pending: "bg-yellow-100 text-yellow-800",
approved: "bg-green-100 text-green-800",
rejected: "bg-red-100 text-red-800",
};
export function SubmissionsManagement() {
const [subs, setSubs] = useState<Submission[]>([]);
const [filter, setFilter] = useState<string>("");
const [loading, setLoading] = useState(false);
const [error, setError] = useState("");
const [rejectNote, setRejectNote] = useState<Record<string, string>>({});
const load = async () => {
setLoading(true);
setError("");
try {
const qs = filter ? `?status=${filter}` : "";
// fetchAdminAPI<T> already returns the { success, error_message, data } envelope
const response = await fetchAdminAPI<Submission[]>(
`/api/submission/admin/submissions${qs}`
);
if (response?.success === false) {
setError(response.error_message || "加载失败");
setSubs([]);
} else if (response?.data) {
setSubs(response.data);
} else {
setSubs([]);
}
} catch (err) {
setError("加载失败:" + (err as Error).message);
setSubs([]);
} finally {
setLoading(false);
}
};
useEffect(() => { load(); }, [filter]);
const act = async (id: string, action: "approve" | "reject") => {
const body: RequestInit =
action === "approve"
? { method: "PUT" }
: {
method: "PUT",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ note: rejectNote[id] || "" }),
};
await fetchAdminAPI(`/api/submission/admin/submission/${id}/${action}`, body);
load();
};
return (
<div className="max-w-6xl mx-auto p-6">
<div className="flex items-center justify-between mb-4">
<h1 className="text-2xl font-bold">投稿审核</h1>
<select value={filter} onChange={(e) => setFilter(e.target.value)} className="border p-2">
<option value="">全部</option>
<option value="pending">待审核</option>
<option value="approved">已通过</option>
<option value="rejected">已拒绝</option>
</select>
</div>
{error && <div className="mb-4 p-3 bg-red-50 text-red-700 rounded">{error}</div>}
{loading && <div className="mb-4 text-gray-500">加载中...</div>}
{!loading && !error && subs.length === 0 && (
<div className="mb-4 text-gray-500">暂无提交记录</div>
)}
<div className="space-y-4">
{subs.map((s) => {
const meta = s.metadata_json || {};
return (
<div key={s.id} className="border rounded p-4 space-y-2">
<div className="flex items-center justify-between">
<div className="flex items-center gap-2">
<span className="font-semibold">{s.name}</span>
<span className="px-2 py-0.5 rounded text-xs">{s.type}</span>
<span className={`px-2 py-0.5 rounded text-xs ${statusColor[s.status] || "bg-gray-100"}`}>{s.status}</span>
</div>
<span className="text-sm text-gray-500">{s.created_at?.slice(0, 19).replace("T", " ")}</span>
</div>
{s.description && <p className="text-sm text-gray-700">{s.description}</p>}
{s.type === "mcp" && (meta.base_url || meta.tags || meta.charge_type) && (
<div className="text-sm text-gray-600 bg-gray-50 rounded p-2 space-y-1">
{meta.base_url && <div>服务地址:<code className="text-xs">{meta.base_url}</code></div>}
{meta.tags && <div>标签:{meta.tags}</div>}
<div>
计费:
{meta.charge_type === "paid"
? `按次付费 ¥${meta.price ?? 0}/次`
: `免费${meta.free_daily_limit ? `(每日 ${meta.free_daily_limit} 次)` : "(不限次)"}`}
</div>
{meta.published_service_id && (
<div className="text-green-700">
已上架市场,服务 ID:<code className="text-xs">{meta.published_service_id}</code>
</div>
)}
</div>
)}
{s.file_path && (
<div className="text-sm text-gray-500">
附件:<code className="text-xs">{s.file_path}</code>
</div>
)}
{s.review_note && (
<div className="text-sm text-gray-600">审核备注:{s.review_note}</div>
)}
{s.status === "pending" ? (
<div className="space-y-2">
<input
value={rejectNote[s.id] || ""}
onChange={(e) => setRejectNote({ ...rejectNote, [s.id]: e.target.value })}
placeholder="拒绝原因(可选)"
className="border p-2 w-full text-sm"
/>
<div className="flex gap-2">
<button
onClick={() => act(s.id, "approve")}
className="bg-green-600 text-white px-3 py-1 rounded text-sm"
>
通过(自动上架)
</button>
<button
onClick={() => act(s.id, "reject")}
className="bg-red-600 text-white px-3 py-1 rounded text-sm"
>
拒绝
</button>
</div>
</div>
) : null}
</div>
);
})}
</div>
</div>
);
}