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,26 @@
import { TrailLinkShareCreateSchema } from '$lib/models/api/trail_link_share_schema';
import type { TrailLinkShare } from '$lib/models/trail_link_share';
import { Collection, handleError, list } from '$lib/util/api_util';
import { json, type RequestEvent } from '@sveltejs/kit';
export async function GET(event: RequestEvent) {
try {
const r = await list<TrailLinkShare>(event, Collection.trail_link_share);
return json(r)
} catch (e: any) {
handleError(e)
}
}
export async function PUT(event: RequestEvent) {
try {
const data = await event.request.json();
const safeData = TrailLinkShareCreateSchema.parse(data);
const r = await event.locals.pb.collection(Collection.trail_link_share).create<TrailLinkShare>(safeData)
return json(r);
} catch (e) {
return handleError(e)
}
}

View File

@@ -0,0 +1,31 @@
import { TrailLinkShareUpdateSchema } from "$lib/models/api/trail_link_share_schema";
import type { TrailLinkShare } from "$lib/models/trail_link_share";
import { Collection, handleError, remove, show, update } from "$lib/util/api_util";
import { json, type RequestEvent } from "@sveltejs/kit";
export async function GET(event: RequestEvent) {
try {
const r = await show<TrailLinkShare>(event, Collection.trail_link_share)
return json(r)
} catch (e: any) {
return handleError(e)
}
}
export async function POST(event: RequestEvent) {
try {
const r = await update<TrailLinkShare>(event, TrailLinkShareUpdateSchema, Collection.trail_link_share)
return json(r);
} catch (e: any) {
return handleError(e)
}
}
export async function DELETE(event: RequestEvent) {
try {
const r = await remove(event, Collection.trail_link_share)
return json(r);
} catch (e: any) {
return handleError(e)
}
}

View File

@@ -18,7 +18,9 @@ export async function GET(event: RequestEvent) {
event.url.searchParams.delete("handle")
const safeSearchParams = RecordOptionsSchema.parse(Object.fromEntries(event.url.searchParams));
if (event.url.searchParams.has("share")) {
safeSearchParams.query = { share: event.url.searchParams.get("share")! }
}
let origin = new URL(actor.iri).origin
let iri = `${origin}/api/v1/trail/${event.params.id}`