This commit is contained in:
parent
56ea3878a2
commit
bce1281d1d
|
|
@ -16,8 +16,6 @@ import { Header, NavBack, TimeP } from "@/components/header";
|
||||||
import { baseTitle, baseURL, keywordsRoot } from "@/lib/metadata";
|
import { baseTitle, baseURL, keywordsRoot } from "@/lib/metadata";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
import { useState, useEffect } from 'react';
|
|
||||||
|
|
||||||
import { DetailPageHeader } from '@/components/header'
|
import { DetailPageHeader } from '@/components/header'
|
||||||
|
|
||||||
export const runtime = "nodejs";
|
export const runtime = "nodejs";
|
||||||
|
|
@ -92,39 +90,26 @@ const BlogArticleWrapper = async ({ params }: { params: { slug: string, locale:
|
||||||
const defaultImage = "https://gimg3.baidu.com/search/src=http%3A%2F%2Fpics3.baidu.com%2Ffeed%2F4ec2d5628535e5dd7c7cdc23847e08e2cc1b62c4.jpeg%40f_auto%3Ftoken%3D38327d5cbefb2cd45af58f8d47c0a0b5&refer=http%3A%2F%2Fwww.baidu.com&app=2021&size=f360,240&n=0&g=0n&q=75&fmt=auto?sec=1710435600&t=eafc0a27ff3295bb5b0b9065fc33a523"
|
const defaultImage = "https://gimg3.baidu.com/search/src=http%3A%2F%2Fpics3.baidu.com%2Ffeed%2F4ec2d5628535e5dd7c7cdc23847e08e2cc1b62c4.jpeg%40f_auto%3Ftoken%3D38327d5cbefb2cd45af58f8d47c0a0b5&refer=http%3A%2F%2Fwww.baidu.com&app=2021&size=f360,240&n=0&g=0n&q=75&fmt=auto?sec=1710435600&t=eafc0a27ff3295bb5b0b9065fc33a523"
|
||||||
|
|
||||||
|
|
||||||
// 新增状态来存储部署状态和状态文本
|
// 发起部署请求
|
||||||
const [statusText, setStatusText] = useState<string>('未知');
|
const res = await fetch("/api/v1/deploy/status", {
|
||||||
const [progress, setProgress] = useState<string>('0%');
|
method: "POST",
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
body: JSON.stringify({
|
||||||
|
id: frontmatter.id, // 假设 frontmatter.id 是你需要的标识符
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
// 在组件加载时发起部署请求
|
const json = await res.json();
|
||||||
useEffect(() => {
|
|
||||||
async function fetchDeployStatus() {
|
|
||||||
try {
|
|
||||||
const res = await fetch("/api/v1/deploy/status", {
|
|
||||||
method: "POST",
|
|
||||||
headers: { "Content-Type": "application/json" },
|
|
||||||
body: JSON.stringify({
|
|
||||||
id: frontmatter.id, // 假设 frontmatter.id 是你需要的标识符
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
|
|
||||||
const json = await res.json();
|
// 根据 API 返回值更新状态文本
|
||||||
|
let statusText = '';
|
||||||
|
let progress = '0%';
|
||||||
|
|
||||||
if (json?.header?.code === 0) {
|
if (json?.header?.code === 0) {
|
||||||
setStatusText(`${json.header.message || "操作成功"}`);
|
statusText = `${json.header.message || "操作成功"}`;
|
||||||
} else {
|
} else {
|
||||||
setStatusText(`${json.header.message || "操作失败(后端返回错误)"}`);
|
statusText = `${json.header.message || "操作失败(后端返回错误)"}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (error) {
|
|
||||||
console.error('部署状态请求失败', error);
|
|
||||||
setStatusText('请求失败');
|
|
||||||
setProgress('0%');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fetchDeployStatus();
|
|
||||||
}, [frontmatter.id]); // 依赖于 frontmatter.id,每次 id 改变时重新请求
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue