This commit is contained in:
parent
c532ff5a26
commit
d28c8f9023
|
|
@ -151,7 +151,16 @@ export async function getWsBase() {
|
||||||
return finalUrl;
|
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 }) {
|
export function DetailPageHeader({ data }: { data: any }) {
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [statusText, setStatusText] = useState(data?.statusText || "加载中...");
|
const [statusText, setStatusText] = useState(data?.statusText || "加载中...");
|
||||||
|
|
@ -444,7 +453,7 @@ export function DetailPageHeader({ data }: { data: any }) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//软件更新
|
||||||
const handleDownloadNewVersion = async () => {
|
const handleDownloadNewVersion = async () => {
|
||||||
const download_url = data?.extra_data?.download_url;
|
const download_url = data?.extra_data?.download_url;
|
||||||
const callback_url = data?.extra_data?.callback_url;
|
const callback_url = data?.extra_data?.callback_url;
|
||||||
|
|
@ -463,7 +472,9 @@ export function DetailPageHeader({ data }: { data: any }) {
|
||||||
setShowDownloadBar(true); // 复用原进度条
|
setShowDownloadBar(true); // 复用原进度条
|
||||||
|
|
||||||
try {
|
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",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
|
|
@ -632,9 +643,11 @@ export function DetailPageHeader({ data }: { data: any }) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
console.log("📥 调用下载接口...", { url: download_url, size, id });
|
console.log("📥 调用下载接口...", { url: download_url, size, id });
|
||||||
|
const apiHost = getApiBaseUrl(); // ✅ 会自动校验是否在客户端
|
||||||
const res = await fetch("https://ai.szaiai.com/api/v1/cloud/download", {
|
//const res = await fetch("https://ai.szaiai.com/api/v1/cloud/download", {
|
||||||
|
const res = await fetch(`${apiHost}/api/v1/cloud/download`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue