-
+ {/* */}
{/* */}
diff --git a/apps/blogai/components/dev-only/console-silencer.tsx b/apps/blogai/components/dev-only/console-silencer.tsx
index a5d33cc..266b86a 100644
--- a/apps/blogai/components/dev-only/console-silencer.tsx
+++ b/apps/blogai/components/dev-only/console-silencer.tsx
@@ -3,6 +3,15 @@
import { useEffect } from 'react'
export function ConsoleSilencer() {
+ if (typeof window !== 'undefined' && process.env.NODE_ENV === 'development') {
+ // 全局替换 console 方法(同步执行)
+ console.log = () => {}
+ console.debug = () => {}
+ console.info = () => {}
+ console.warn = () => {}
+ console.error = () => {}
+ }
+
useEffect(() => {
if (process.env.NODE_ENV === 'development') {
console.log = () => {};
diff --git a/apps/blogai/components/header.tsx b/apps/blogai/components/header.tsx
index 0fc7d7d..b3c6ed3 100644
--- a/apps/blogai/components/header.tsx
+++ b/apps/blogai/components/header.tsx
@@ -30,7 +30,6 @@ import Image from 'next/image';
import logoImage from '@/components/images/logo.png';
import { useRouter } from 'next/navigation'
-// import { Button } from './ui/button'
import { Flex, Text } from '@radix-ui/themes';
import Link from 'next/link'
import { useTranslation } from 'react-i18next'
@@ -43,8 +42,6 @@ import { Trash2 } from "lucide-react";
import { useEffect } from "react";
-// import { getRuntimeEnv } from "@/lib/ipconfig";
-
import {
BadgeInfo,
Tags,
@@ -74,7 +71,7 @@ export function Header() {
const soonFunc = () => {
message.info(t("soon"))
}
-//w-11/12 sm:w-5/6 md:w-3/4 lg:w-2/3 xl:w-3/5 2xl:w-1/2
+
return (
@@ -117,63 +114,6 @@ export function Header() {
)
}
-// export async function getWsBase() {
-// let ip = await getRuntimeEnv("SUPABASE_URL");
-// if (!ip) throw new Error("SUPABASE_URL 获取失败,无法构建 wsBase");
-
-// // 判断协议
-// let wsProtocol = "ws";
-// if (
-// typeof window !== "undefined" &&
-// window.location &&
-// window.location.protocol === "https:"
-// ) {
-// wsProtocol = "wss";
-// // ✅ HTTPS + 浏览器环境下用 hostname 避免 TLS 报错
-// ip = window.location.hostname;
-// }
-
-// // 拼接最终 ws 地址
-// return `${wsProtocol}://${ip}/api/v1/deploy/ws`;
-// }
-
-
-// import { getRuntimeEnv } from "@/lib/ipconfig";
-// //import { headers } from "next/headers";
-
-// export async function getWsBase() {
-// let ip = await getRuntimeEnv("SUPABASE_URL");
-// if (!ip) throw new Error("SUPABASE_URL 获取失败,无法构建 wsBase");
-
-// let wsProtocol = "ws";
-
-// if (
-// typeof window !== "undefined" &&
-// window.location &&
-// window.location.protocol === "https:"
-// ) {
-// wsProtocol = "wss";
-// ip = window.location.hostname; // ✅ 浏览器下安全替换为域名
-// } else {
-// // ✅ SSR 场景
-// const hdrs = headers();
-// const forwardedProto = hdrs.get("x-forwarded-proto");
-// const hostHeader = hdrs.get("host");
-
-// if (forwardedProto === "https") {
-// wsProtocol = "wss";
-// }
-
-// if (hostHeader) {
-// ip = hostHeader.includes(":") ? hostHeader.split(":")[0] : hostHeader;
-// }
-// }
-
-// // 拼接最终 ws 地址
-// return `${wsProtocol}://${ip}/api/v1/deploy/ws`;
-// }
-
-
import { getRuntimeEnv } from "@/lib/ipconfig";
export async function getWsBase() {
@@ -222,6 +162,10 @@ export function DetailPageHeader({ data }: { data: any }) {
const [hasWSConnected, setHasWSConnected] = useState(false);
const [statusLoaded, setStatusLoaded] = useState(false);
const [canDeploy, setCanDeploy] = useState(true);
+
+ const [currentStatus, setCurrentStatus] = useState(""); // 当前部署状态:running / stopped
+ const [switchLoading, setSwitchLoading] = useState(false); // 控制按钮 loading 状态
+
const socketRef = useRef(null);
const { t } = useTranslation();
@@ -388,6 +332,7 @@ export function DetailPageHeader({ data }: { data: any }) {
const code = result?.header?.code;
const status = result?.data?.data?.status;
+ setCurrentStatus(status || ""); //...............................................
const userData = JSON.parse(localStorage.getItem("UserData") || "null");
const userName = userData?.user_name;
const id = data?.id;
@@ -436,79 +381,49 @@ export function DetailPageHeader({ data }: { data: any }) {
}
};
+
+ const handleSwitchStatus = async () => {
+ if (!data?.id) return;
+
+ setSwitchLoading(true);
+ const userData = JSON.parse(localStorage.getItem("UserData") || "null");
+ const userName = userData?.user_name;
+
+ if (!userName) {
+ setStatusText("未登录,跳转中...");
+ window.location.href = "/auth/sign-in/";
+ return;
+ }
+
+ const endpoint = currentStatus === "running" ? "/api/v1/deploy/stop" : "/api/v1/deploy/start";
+
+ try {
+ const res = await fetch(endpoint, {
+ method: "POST",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify({ user_name: userName, id: data.id }),
+ });
+
+ const json = await res.json();
+ if (json?.header?.code === 0) {
+ setStatusText(currentStatus === "running" ? "已停止" : "已启动");
+ fetchDeployStatus(); // ✅ 状态切换成功后刷新
+ } else {
+ setStatusText(json?.header?.message || "操作失败(后端)");
+ }
+ } catch (err) {
+ console.error("切换请求失败:", err);
+ setStatusText("网络异常");
+ } finally {
+ setSwitchLoading(false);
+ }
+ };
+
+
useEffect(() => {
fetchDeployStatus();
}, [data?.id]);
-
- // useEffect(() => {
- // const fetchDeployStatus = async () => {
- // try {
- // const result = await fetch("/api/v1/deploy/status", {
- // method: "POST",
- // headers: { "Content-Type": "application/json" },
- // body: JSON.stringify({ id: data?.id }),
- // }).then((res) => res.json());
-
- // console.log("====> deploy status result:", result);
- // setStatusLoaded(true);
-
- // if (!result) {
- // setStatusText("接口响应为空");
- // setShowDelete(false);
- // return;
- // }
-
- // const code = result?.header?.code;
- // const status = result?.data?.data?.status;
- // const userData = JSON.parse(localStorage.getItem("UserData") || "null");
- // const userName = userData?.user_name;
- // const id = data?.id;
-
- // console.log("🟡 状态码 code =", code, "状态 status =", status);
-
- // if (code === 1006) {
- // setStatusText("尚未部署");
- // setShowDelete(false);
- // setProgress("0%");
- // setShowProgressBar(false)
- // return;
- // }
-
- // if (status === "deploying" && userName && id && !hasWSConnected) {
- // setStatusText("检测到正在部署,连接中...");
- // initWebSocket(userName, id);
- // setShowProgressBar(true)
- // }
-
- // if (status === "running" || status === "stopped") {
- // console.log("✅ 允许删除(status =", status, ")");
- // setShowDelete(true);
- // setProgress("100%");
- // setShowProgressBar(true)
-
- // if (status === "running") {
- // setStatusText("运行中");
- // setProgressBarColor("bg-green-500");
- // } else if (status === "stopped") {
- // setStatusText("已停止");
- // setProgressBarColor("bg-gray-400");
- // }
- // } else {
- // console.log("❌ 不允许删除(status =", status, ")");
- // setShowDelete(false);
- // setProgressBarColor("bg-blue-500"); // 回到默认蓝色
- // }
- // } catch (err) {
- // console.error("获取状态失败:", err);
- // setStatusText("状态拉取失败");
- // setShowDelete(false);
- // }
- // };
-
- // fetchDeployStatus();
- // }, [data?.id]);
-
useEffect(() => {
return () => {
if (socketRef.current) {
@@ -563,6 +478,24 @@ export function DetailPageHeader({ data }: { data: any }) {
+
+ {statusLoaded && (currentStatus === "running" || currentStatus === "stopped") && (
+
+ )}
+
+
+
{statusLoaded && showDelete && (