mirror of
https://github.com/projectsend/projectsend.git
synced 2026-09-16 08:35:07 +00:00
6e47d76ba6
Client file sharing, rebuilt from the ground up: a private area per client, resumable uploads, folders, groups and categories, sharing with expiry dates and download limits, comments, file versions, an activity log, a REST API, and sixteen languages. This repository begins here. ProjectSend 2 was developed privately, and that development history is not published — the previous generation remains available, with its own history, at projectsend/legacy. Free software under the GNU General Public License v2, or (at your option) any later version.
26 lines
867 B
TypeScript
26 lines
867 B
TypeScript
import { xsrfToken } from '@/lib/xsrf';
|
|
|
|
// Re-exported because this module was where the helper used to live, and
|
|
// several callers still reach for it here.
|
|
export { xsrfToken };
|
|
|
|
export async function apiFetch<T>(url: string, method: string, body?: unknown): Promise<T> {
|
|
const response = await fetch(url, {
|
|
method,
|
|
credentials: 'same-origin',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
Accept: 'application/json',
|
|
'X-XSRF-TOKEN': xsrfToken(),
|
|
},
|
|
body: body === undefined ? undefined : JSON.stringify(body),
|
|
});
|
|
|
|
if (!response.ok) {
|
|
const payload = (await response.json().catch(() => null)) as { message?: string } | null;
|
|
throw new Error(payload?.message ?? `Upload request failed (${response.status})`);
|
|
}
|
|
|
|
return (await response.json()) as T;
|
|
}
|