Add screens for media, the audit log and statistics
This commit is contained in:
1 parent
0caa196908
commit
1c9ccadf4e
10 files changed
+478
-6
No files matched your search
@@ -53,6 +53,23 @@ export async function request<T = any>(method: string, path: string, body?: unkn
|
||||
return data as T;
|
||||
}
|
||||
|
||||
/** A file upload: multipart, the browser sets the content type. */
|
||||
export async function upload<T = any>(path: string, form: FormData): Promise<T> {
|
||||
const response = await fetch(path, {
|
||||
method: 'POST',
|
||||
credentials: 'same-origin',
|
||||
headers: { Accept: 'application/json', 'X-Requested-With': 'XMLHttpRequest', 'X-XSRF-TOKEN': xsrf() },
|
||||
body: form,
|
||||
});
|
||||
const data = await response.json().catch(() => null);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new ApiError(response.status, data);
|
||||
}
|
||||
|
||||
return data as T;
|
||||
}
|
||||
|
||||
export const api = {
|
||||
get: <T = any>(path: string) => request<T>('GET', path),
|
||||
post: <T = any>(path: string, body: unknown = {}) => request<T>('POST', path, body),
|
||||
|
||||
Reference in new issue
Block a user