This commit is contained in:
hailin 2025-07-05 17:00:11 +08:00
parent c532ff5a26
commit d28c8f9023
1 changed files with 17 additions and 4 deletions

View File

@ -151,7 +151,16 @@ export async function getWsBase() {
return finalUrl;
}
function getApiBaseUrl(): string {
if (typeof window === "undefined" || !window.location) {
if (process.env.NODE_ENV === "development") {
console.error("❌ getApiBaseUrl 被错误地调用于非浏览器环境");
}
throw new Error("❌ getApiBaseUrl 必须在浏览器端调用");
}
return `${window.location.protocol}//${window.location.host}`;
}
export function DetailPageHeader({ data }: { data: any }) {
const [loading, setLoading] = useState(false);
const [statusText, setStatusText] = useState(data?.statusText || "加载中...");
@ -444,7 +453,7 @@ export function DetailPageHeader({ data }: { data: any }) {
}
};
//软件更新
const handleDownloadNewVersion = async () => {
const download_url = data?.extra_data?.download_url;
const callback_url = data?.extra_data?.callback_url;
@ -463,7 +472,9 @@ export function DetailPageHeader({ data }: { data: any }) {
setShowDownloadBar(true); // 复用原进度条
try {
const res = await fetch("https://ai.szaiai.com/api/v1/cloud/newversion", {
const apiHost = getApiBaseUrl(); // ✅ 会自动校验是否在客户端
// const res = await fetch("https://ai.szaiai.com/api/v1/cloud/newversion", {
const res = await fetch(`${apiHost}/api/v1/cloud/download`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
@ -632,9 +643,11 @@ export function DetailPageHeader({ data }: { data: any }) {
return;
}
console.log("📥 调用下载接口...", { url: download_url, size, id });
const res = await fetch("https://ai.szaiai.com/api/v1/cloud/download", {
const apiHost = getApiBaseUrl(); // ✅ 会自动校验是否在客户端
//const res = await fetch("https://ai.szaiai.com/api/v1/cloud/download", {
const res = await fetch(`${apiHost}/api/v1/cloud/download`, {
method: "POST",
headers: {
"Content-Type": "application/json",