订单需管理员审核后才开通节点,并更新登录页文案。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -37,6 +37,30 @@ export async function api(path, options = {}) {
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function download(path, filename) {
|
||||
const headers = {};
|
||||
const token = localStorage.getItem("token");
|
||||
if (token) headers.Authorization = `Bearer ${token}`;
|
||||
const response = await fetch(`/api/v1${path}`, { headers });
|
||||
if (response.status === 401) {
|
||||
clearSession();
|
||||
if (location.pathname !== "/login") location.assign("/login");
|
||||
throw new Error("登录已失效");
|
||||
}
|
||||
if (!response.ok) {
|
||||
const text = await response.text();
|
||||
const data = text ? JSON.parse(text) : null;
|
||||
throw new Error(messageOf(data) || "下载失败");
|
||||
}
|
||||
const blob = await response.blob();
|
||||
const url = URL.createObjectURL(blob);
|
||||
const link = document.createElement("a");
|
||||
link.href = url;
|
||||
link.download = filename;
|
||||
link.click();
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
|
||||
function messageOf(data) {
|
||||
if (!data) return "";
|
||||
if (typeof data.detail === "string") return data.detail;
|
||||
|
||||
Reference in New Issue
Block a user