adds trail link sharing

This commit is contained in:
Christian Beutel
2025-08-20 16:51:33 +02:00
parent b3d44f3b78
commit 1e22c78c22
36 changed files with 598 additions and 36 deletions

View File

@@ -0,0 +1,66 @@
import type { TrailLinkShare } from "$lib/models/trail_link_share";
import { APIError } from "$lib/util/api_util";
import { type ListResult } from "pocketbase";
import { writable, type Writable } from "svelte/store";
export const linkShares: Writable<TrailLinkShare[]> = writable([])
export async function trail_link_share_index(trail?: string, f: (url: RequestInfo | URL, config?: RequestInit) => Promise<Response> = fetch) {
let filter = ""
filter += `trail='${trail}'`
const r = await f('/api/v1/trail-link-share?' + new URLSearchParams({
filter: filter,
expand: "actor"
}), {
method: 'GET',
})
if (!r.ok) {
const response = await r.json();
throw new APIError(r.status, response.message, response.detail)
}
const response: ListResult<TrailLinkShare> = await r.json();
linkShares.set(response.items);
return response.items;
}
export async function trail_link_share_create(share: TrailLinkShare) {
let r = await fetch('/api/v1/trail-link-share', {
method: 'PUT',
body: JSON.stringify(share),
})
if (!r.ok) {
const response = await r.json();
throw new APIError(r.status, response.message, response.detail)
}
}
export async function trail_link_share_update(share: TrailLinkShare) {
let r = await fetch('/api/v1/trail-link-share/' + share.id, {
method: 'POST',
body: JSON.stringify(share),
})
if (!r.ok) {
const response = await r.json();
throw new APIError(r.status, response.message, response.detail)
}
}
export async function trail_link_share_delete(share: TrailLinkShare) {
const r = await fetch('/api/v1/trail-link-share/' + share.id, {
method: 'DELETE',
})
if (!r.ok) {
const response = await r.json();
throw new APIError(r.status, response.message, response.detail)
}
}

View File

@@ -133,12 +133,12 @@ export async function trails_search_bounding_box(northEast: M.LngLat, southWest:
}
export async function trails_show(id: string, handle?: string, loadGPX?: boolean, f: (url: RequestInfo | URL, config?: RequestInit) => Promise<Response> = fetch) {
export async function trails_show(id: string, handle?: string, share?: string, loadGPX?: boolean, f: (url: RequestInfo | URL, config?: RequestInit) => Promise<Response> = fetch) {
const r = await f(`/api/v1/trail/${id}?` + new URLSearchParams({
expand: "category,waypoints,summit_logs_via_trail,summit_logs_via_trail.author,trail_share_via_trail.actor,trail_like_via_trail,tags,author",
...(handle ? { handle } : {})
...(handle ? { handle } : {}),
...(share ? { share } : {})
}), {
method: 'GET',
})