fix: 补上清单里还没对上的登录拒绝、会话回退和代理清理

This commit is contained in:
2026-11-16 16:46:37 +08:00
parent a1e2b6e65c
commit 3cff9dc37a
19 changed files with 223 additions and 65 deletions
+28
View File
@@ -0,0 +1,28 @@
type Denied = () => void;
let onDenied: Denied | null = null;
export function setSessionDenied(handler: Denied) {
onDenied = handler;
}
function requestUrl(input: RequestInfo | URL) {
if (typeof input === "string") return input;
if (input instanceof URL) return input.href;
return input.url;
}
export async function apiFetch(input: RequestInfo | URL, init?: RequestInit) {
const response = await fetch(input, init);
if (requestUrl(input).includes("/api/session")) return response;
if (response.status === 401) {
onDenied?.();
return response;
}
if (response.status === 403) {
const body = await response.clone().json().catch(() => null);
const detail = body && typeof body === "object" ? (body as { detail?: unknown }).detail : "";
if (detail === "管理员不能访问该接口") onDenied?.();
}
return response;
}