diff --git a/frontend/src/app/admin/submissions/page.tsx b/frontend/src/app/admin/submissions/page.tsx index c96057f..e0207b3 100644 --- a/frontend/src/app/admin/submissions/page.tsx +++ b/frontend/src/app/admin/submissions/page.tsx @@ -1,55 +1,7 @@ "use client"; -import React, { useEffect, useState } from "react"; +import React from "react"; +import { SubmissionsManagement } from "@/components/console/SubmissionsManagement"; export default function AdminSubmissionsPage() { - const [list, setList] = useState([]); - const [status, setStatus] = useState("pending"); - - const load = async () => { - const res = await fetch(`/api/submission/admin/submissions?status=${status}`, { credentials: "include" }); - const data = await res.json(); - setList(data?.data || []); - }; - - useEffect(() => { load(); }, [status]); - - const approve = async (id: string) => { - await fetch(`/api/submission/admin/submission/${id}/approve`, { method: "PUT", credentials: "include" }); - load(); - }; - const reject = async (id: string) => { - await fetch(`/api/submission/admin/submission/${id}/reject`, { method: "PUT", credentials: "include", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ note: "rejected" }) }); - load(); - }; - - return ( -
-

提交审核

- - - - - {list.map((s: any) => ( - - - - - - - ))} - -
名称类型状态操作
{s.name}{s.type}{s.status} - {s.status === "pending" && ( - <> - - - - )} -
-
- ); + return ; } diff --git a/frontend/src/app/submit/page.tsx b/frontend/src/app/submit/page.tsx index 5720ed6..6ac52a6 100644 --- a/frontend/src/app/submit/page.tsx +++ b/frontend/src/app/submit/page.tsx @@ -1,40 +1,173 @@ "use client"; import React, { useState } from "react"; +import { fetchAPI } from "@/shared/rpc/common-function"; + +type SubType = "mcp" | "skill" | "plugin"; export default function SubmitPage() { - const [type, setType] = useState("mcp"); + const [type, setType] = useState("mcp"); const [name, setName] = useState(""); const [desc, setDesc] = useState(""); const [file, setFile] = useState(null); - const [msg, setMsg] = useState(""); + const [baseUrl, setBaseUrl] = useState(""); + const [serviceType, setServiceType] = useState("openapi"); + const [tags, setTags] = useState(""); + const [chargeType, setChargeType] = useState<"free" | "paid">("free"); + const [price, setPrice] = useState(""); + const [freeDailyLimit, setFreeDailyLimit] = useState(""); + const [msg, setMsg] = useState<{ ok: boolean; text: string } | null>(null); + const [submitting, setSubmitting] = useState(false); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); - const fd = new FormData(); - fd.append("type", type); - fd.append("name", name); - if (desc) fd.append("description", desc); - if (file) fd.append("file", file); - const res = await fetch("/api/submission/submission", { method: "POST", body: fd, credentials: "include" }); - const data = await res.json(); - setMsg(JSON.stringify(data)); + setMsg(null); + + if (typeof window !== "undefined" && !localStorage.getItem("user_token")) { + setMsg({ ok: false, text: "请先登录后再提交(右上角登录)" }); + return; + } + if (type === "mcp" && !baseUrl.trim()) { + setMsg({ ok: false, text: "MCP 服务必须填写服务地址 base_url" }); + return; + } + + setSubmitting(true); + try { + const fd = new FormData(); + fd.append("type", type); + fd.append("name", name); + if (desc) fd.append("description", desc); + if (file) fd.append("file", file); + if (type === "mcp") { + fd.append("base_url", baseUrl.trim()); + fd.append("service_type", serviceType); + if (tags.trim()) fd.append("tags", tags.trim()); + fd.append("charge_type", chargeType); + if (chargeType === "paid" && price) fd.append("price", price); + if (chargeType === "free" && freeDailyLimit) fd.append("free_daily_limit", freeDailyLimit); + } + + const data = await fetchAPI<{ success: boolean; error_message?: string; data?: { id: string; status: string } }>( + "/api/submission/submission", + { method: "POST", body: fd } + ); + if (data?.success) { + setMsg({ ok: true, text: "提交成功,等待管理员审核。审核通过后将自动上架到市场。" }); + setName(""); setDesc(""); setFile(null); setBaseUrl(""); setTags(""); + } else { + setMsg({ ok: false, text: data?.error_message || "提交失败,请稍后重试" }); + } + } catch (err) { + setMsg({ ok: false, text: "提交失败:" + (err as Error).message }); + } finally { + setSubmitting(false); + } }; + const inputCls = "border p-2 w-full rounded"; + return (
-

上传 MCP / Skill / Plugin

+
+

上传 MCP / Skill / Plugin

+
+
- setType(e.target.value as SubType)} className={inputCls}> - setName(e.target.value)} placeholder="名称" className="border p-2 w-full" required /> -