sync snapshot from LAN repo (source codex/kb-context-retrieval-20261021 @ b69568e4)
This commit is contained in:
1 parent
ea9dcff9c0
commit
4cf657f725
781 files changed
+13559
-104852
No files matched your search
@@ -1,5 +1,4 @@
|
||||
import { apiFetch } from "@/core/api/fetch-client";
|
||||
import { fetchWithBindingRetry } from "@/core/auth/login-transport";
|
||||
import { getBackendBaseURL } from "@/core/config";
|
||||
|
||||
import type { LoginByUsernameResponse } from "./index";
|
||||
@@ -30,10 +29,10 @@ async function accountRequest<T>(path: string, init: RequestInit = {}): Promise<
|
||||
const controller = new AbortController();
|
||||
const timer = setTimeout(() => controller.abort(), 20_000);
|
||||
try {
|
||||
const response = await fetchWithBindingRetry(() => apiFetch(`${getBackendBaseURL()}/api/v1/auth${path}`, {
|
||||
const response = await apiFetch(`${getBackendBaseURL()}/api/v1/auth${path}`, {
|
||||
...init,
|
||||
signal: controller.signal,
|
||||
}));
|
||||
});
|
||||
const body: unknown = await response.json().catch(() => null);
|
||||
if (!response.ok) throw new Error(accountError(body, "请求失败,请稍后重试"));
|
||||
return body as T;
|
||||
@@ -46,6 +45,15 @@ async function accountRequest<T>(path: string, init: RequestInit = {}): Promise<
|
||||
}
|
||||
}
|
||||
|
||||
export async function fetchAuthenticationOptions(): Promise<AuthenticationOptions> {
|
||||
const options = await accountRequest<AuthenticationOptions>("/options", { cache: "no-store" });
|
||||
if (!options || [options.password_login_enabled, options.registration_enabled, options.sso_enabled]
|
||||
.some((value) => typeof value !== "boolean")) {
|
||||
throw new Error("无法读取登录设置,请联系管理员或重试");
|
||||
}
|
||||
return options;
|
||||
}
|
||||
|
||||
export function loginWithPassword(username: string, password: string): Promise<LoginByUsernameResponse> {
|
||||
return accountRequest("/login/local", {
|
||||
method: "POST",
|
||||
|
||||
Reference in new issue
Block a user