File uploading

This commit is contained in:
2026-10-29 17:59:34 -03:00
parent ec9bdb8e8e
commit b65d8efad8
18 changed files with 686 additions and 51 deletions
+10 -6
View File
@@ -3,14 +3,10 @@ export type PostJsonResult<T> =
// status is 0 when the request never reached the server
| { ok: false; status: number; error: string };
export async function post_json<T>(url: string, body: unknown, method = "POST"): Promise<PostJsonResult<T>> {
export async function fetch_json<T>(url: string, init: RequestInit): Promise<PostJsonResult<T>> {
let response: Response;
try {
response = await fetch(url, {
method,
headers: { "Content-Type": "application/json" },
body: JSON.stringify(body),
});
response = await fetch(url, init);
} catch (err) {
return { ok: false, status: 0, error: err instanceof Error ? err.message : String(err) };
}
@@ -25,3 +21,11 @@ export async function post_json<T>(url: string, body: unknown, method = "POST"):
}
return { ok: true, data: data as T };
}
export function post_json<T>(url: string, body: unknown, method = "POST"): Promise<PostJsonResult<T>> {
return fetch_json<T>(url, {
method,
headers: { "Content-Type": "application/json" },
body: JSON.stringify(body),
});
}