filebrowser/frontend/src/api/users.ts
Jon_K 0a3d1642f7 Add user quota management system
Introduces comprehensive quota management with real-time usage tracking, frontend components, backend API endpoints, and TUS upload integration for storage limit enforcement.
2026-01-03 01:07:26 -05:00

48 lines
1.0 KiB
TypeScript

import { fetchURL, fetchJSON, StatusError } from "./utils";
export async function getAll() {
return fetchJSON<IUser[]>(`/api/users`, {});
}
export async function get(id: number) {
return fetchJSON<IUser>(`/api/users/${id}`, {});
}
export async function create(user: IUser) {
const res = await fetchURL(`/api/users`, {
method: "POST",
body: JSON.stringify({
what: "user",
which: [],
data: user,
}),
});
if (res.status === 201) {
return res.headers.get("Location");
}
throw new StatusError(await res.text(), res.status);
}
export async function update(user: Partial<IUser>, which = ["all"]) {
await fetchURL(`/api/users/${user.id}`, {
method: "PUT",
body: JSON.stringify({
what: "user",
which: which,
data: user,
}),
});
}
export async function remove(id: number) {
await fetchURL(`/api/users/${id}`, {
method: "DELETE",
});
}
export async function getQuota(id: number) {
return fetchJSON<IQuotaInfo>(`/api/users/${id}/quota`, {});
}