From f77bd6cc62997f08f3875b4ff2e22ea295a6a500 Mon Sep 17 00:00:00 2001 From: hailin Date: Fri, 28 Mar 2025 11:20:30 +0800 Subject: [PATCH] . --- .../app/[locale]/details/[slug]/page.tsx | 1 + apps/blogai/components/header.tsx | 29 +++++++++++++++++-- apps/blogai/lib/mdx-helper.ts | 2 ++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/apps/blogai/app/[locale]/details/[slug]/page.tsx b/apps/blogai/app/[locale]/details/[slug]/page.tsx index 607355f..e2e393f 100644 --- a/apps/blogai/app/[locale]/details/[slug]/page.tsx +++ b/apps/blogai/app/[locale]/details/[slug]/page.tsx @@ -88,6 +88,7 @@ const BlogArticleWrapper = async ({ params }: { params: { slug: string, locale: {/* */} { setLoading(true); setStatusText(source === "icon" ? "正在处理图标操作..." : "正在处理信息操作..."); + try { - await fetch("/api/stub", { + // 从 localStorage 获取用户信息 + const userData = JSON.parse(localStorage.getItem("UserData") || "null"); + + if (!userData || !userData.user_name) { + setStatusText("未登录,正在跳转登录页面..."); + window.location.href = "/login"; + return; + } + + const userName = userData.user_name; + + // 从组件 props 里的 data 中取 id + const id = data?.id; + if (!id) { + setStatusText("数据缺失:找不到组件 ID"); + return; + } + + await fetch("/api/v1/deploy/deploy", { method: "POST", headers: { "Content-Type": "application/json" }, - body: JSON.stringify({ source }) + body: JSON.stringify({ + id, + user_name: userName, + }), }); - + await new Promise((resolve) => setTimeout(resolve, 1000)); setStatusText(`操作成功:来自${source === "icon" ? "图标" : "信息区域"}`); } catch (err) { + console.error("请求出错:", err); setStatusText("操作失败"); } finally { setLoading(false); diff --git a/apps/blogai/lib/mdx-helper.ts b/apps/blogai/lib/mdx-helper.ts index f036a1c..f8d27fa 100644 --- a/apps/blogai/lib/mdx-helper.ts +++ b/apps/blogai/lib/mdx-helper.ts @@ -107,6 +107,7 @@ type Frontmatter = { }; type AIFrontmatter = { + id:string; p_name:string; title: string; date: string; @@ -281,6 +282,7 @@ export const getPostContent = async (language: string, slug: string): Promise