feat(dashboard): add redirects page

This commit is contained in:
sam 2024-10-19 20:47:55 +02:00
parent 32ddb9fae2
commit cb425fe3cd
Signed by: sam
GPG key ID: 5F3C3C1B3166639D
7 changed files with 400 additions and 62 deletions

View file

@ -1,11 +1,40 @@
export const TOKEN_KEY = "catalogger-token";
export default async function apiFetch<T>(
method: "GET" | "POST" | "PATCH" | "DELETE",
export type HttpMethod = "GET" | "POST" | "PATCH" | "DELETE";
export async function fastFetch(
method: HttpMethod,
path: string,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
body: any = null,
) {
): Promise<void> {
const token = localStorage.getItem(TOKEN_KEY);
const headers = {
...(body != null
? { "Content-Type": "application/json; charset=utf-8" }
: {}),
...(token ? { Authorization: token } : {}),
};
const reqBody = body ? JSON.stringify(body) : undefined;
console.debug("Sending", method, "request to", path, "with body", reqBody);
const resp = await fetch(path, {
method,
body: body ? JSON.stringify(body) : undefined,
headers,
});
if (resp.status < 200 || resp.status > 299)
throw (await resp.json()) as ApiError;
}
export default async function apiFetch<T>(
method: HttpMethod,
path: string,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
body: any = null,
): Promise<T> {
const token = localStorage.getItem(TOKEN_KEY);
const headers = {
...(body != null