Spaces:
Running
Running
Download frontend/src/features/admin/api/adminApi.ts from TwanAPI/UploadFile: direct link, hf CLI and curl.
- Browser
- Download file 1.61 kB
-
https://huggingface.co/spaces/TwanAPI/UploadFile/resolve/main/frontend/src/features/admin/api/adminApi.ts
- Command line
-
hf download hf://spaces/TwanAPI/UploadFile/frontend/src/features/admin/api/adminApi.ts
-
curl -L -o adminApi.ts https://huggingface.co/spaces/TwanAPI/UploadFile/resolve/main/frontend/src/features/admin/api/adminApi.ts
1.61 kB
| import { apiRequest } from "@/shared/lib/http"; | |
| import { PermissionSet, PublicUser } from "@/shared/types/domain"; | |
| export async function listUsersAdmin(token: string | null): Promise<PublicUser[]> { | |
| const res = await apiRequest<{ ok: boolean; users: PublicUser[] }>("/api/admin/users", { | |
| token, | |
| }); | |
| return Array.isArray(res.users) ? res.users : []; | |
| } | |
| export async function saveUserAdmin( | |
| token: string | null, | |
| payload: { | |
| username: string; | |
| display_name: string; | |
| role: "admin" | "user"; | |
| password?: string; | |
| permissions: PermissionSet; | |
| active: boolean; | |
| }, | |
| ): Promise<PublicUser> { | |
| const res = await apiRequest<{ ok: boolean; user: PublicUser }>("/api/admin/users", { | |
| method: "POST", | |
| token, | |
| body: payload, | |
| }); | |
| return res.user; | |
| } | |
| export async function deleteUserAdmin(token: string | null, username: string): Promise<void> { | |
| await apiRequest(`/api/admin/users?username=${encodeURIComponent(username)}`, { | |
| method: "DELETE", | |
| token, | |
| }); | |
| } | |
| export type ActiveUiVersion = "v1" | "v2"; | |
| export async function getActiveUiAdmin(token: string | null): Promise<ActiveUiVersion> { | |
| const res = await apiRequest<{ ok: boolean; active_ui: string }>("/api/admin/ui", { token }); | |
| return res.active_ui === "v2" ? "v2" : "v1"; | |
| } | |
| export async function setActiveUiAdmin( | |
| token: string | null, | |
| activeUi: ActiveUiVersion, | |
| ): Promise<ActiveUiVersion> { | |
| const res = await apiRequest<{ ok: boolean; active_ui: string }>("/api/admin/ui", { | |
| method: "POST", | |
| token, | |
| body: { active_ui: activeUi }, | |
| }); | |
| return res.active_ui === "v2" ? "v2" : "v1"; | |
| } | |