full settings overhaul

This commit is contained in:
Christian Beutel
2024-07-05 18:14:31 +02:00
parent 6522b06e96
commit d0a408983b
47 changed files with 4355 additions and 551 deletions

View File

@@ -15,11 +15,11 @@ export const trail: Writable<Trail> = writable(new Trail(""));
export const editTrail: Writable<Trail> = writable(new Trail(""));
export async function trails_index(data: { perPage: number, random?: boolean, f: (url: RequestInfo | URL, config?: RequestInit) => Promise<Response> } = { perPage: 30, random: false, f: fetch }) {
const r = await data.f('/api/v1/trail?' + new URLSearchParams({
"per-page": data.perPage.toString(),
export async function trails_index(perPage: number = 21, random: boolean = false, f: (url: RequestInfo | URL, config?: RequestInit) => Promise<Response> = fetch) {
const r = await f('/api/v1/trail?' + new URLSearchParams({
"per-page": perPage.toString(),
expand: "category,waypoints,summit_logs",
sort: data.random ? "@random" : ""
sort: random ? "@random" : ""
}), {
method: 'GET',
})
@@ -343,6 +343,22 @@ export async function trails_get_bounding_box(f: (url: RequestInfo | URL, config
}
}
export async function trails_upload(file: File, f: (url: RequestInfo | URL, config?: RequestInit) => Promise<Response> = fetch): Promise<TrailFilterValues> {
const r = await f('/api/v1/trail/upload', {
headers: {
"Content-Type": "multipart/form-data"
},
method: 'PUT',
body: file
})
if (r.ok) {
return await r.json();
} else {
throw new ClientResponseError(await r.json())
}
}
export async function fetchGPX(trail: Trail, f: (url: RequestInfo | URL, config?: RequestInit) => Promise<Response> = fetch) {
if (!trail.gpx) {
return "";

View File

@@ -107,20 +107,20 @@ export async function users_update(user: User | { [K in keyof User]?: User[K] },
throw new ClientResponseError(await r.json())
}
const formData = new FormData();
if (avatar) {
const formData = new FormData();
formData.append("avatar", avatar);
}
r = await fetch(`/api/v1/user/${user.id!}/file`, {
method: 'POST',
body: formData,
})
if (!r.ok) {
throw new ClientResponseError(await r.json())
r = await fetch(`/api/v1/user/${user.id!}/file`, {
method: 'POST',
body: formData,
})
if (!r.ok) {
throw new ClientResponseError(await r.json())
}
}
const model: User = await r.json();