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}`

View File

@@ -137,6 +137,7 @@
const fullTrail = await trails_show(
trail.iri ? trail.iri.substring(trail.iri.length - 15) : trail.id!,
handleFromRecordWithIRI(trail),
undefined,
true,
);
selectedTrail = fullTrail;
@@ -251,7 +252,8 @@
disabled={!selectedList}
onclick={back}><i class="fa fa-arrow-left"></i></button
>
<Search bind:value={filter.q} onupdate={() => updateFilter()}></Search>
<Search bind:value={filter.q} onupdate={() => updateFilter()}
></Search>
<button
aria-label="Toggle filter"
class="btn-icon"

View File

@@ -187,7 +187,7 @@
}
async function handleSearchClick(item: SearchItem) {
const trail = await trails_show(item.value, undefined, true);
const trail = await trails_show(item.value, undefined, undefined, true);
$formData.trails?.push(trail.id!);
$formData.expand = {
trails: [...($formData.expand?.trails ?? []), trail],

View File

@@ -1,11 +1,10 @@
import { trails_show } from "$lib/stores/trail_store";
import { splitUsername } from "$lib/util/activitypub_util";
import { APIError } from "$lib/util/api_util";
import { error, type NumericRange, type ServerLoad } from "@sveltejs/kit";
export const load: ServerLoad = async ({ params, locals, fetch }) => {
export const load: ServerLoad = async ({ params, url, fetch }) => {
try {
const trail = await trails_show(params.id!, params.handle, true, fetch)
const trail = await trails_show(params.id!, params.handle, url.searchParams.get("share") ?? undefined, true, fetch)
return { trail };
} catch (e) {
if (e instanceof APIError) {

View File

@@ -2,9 +2,9 @@ import { trails_show } from "$lib/stores/trail_store";
import { APIError } from "$lib/util/api_util";
import { error, type Load, type NumericRange } from "@sveltejs/kit";
export const load: Load = async ({ params, fetch }) => {
export const load: Load = async ({ params, fetch, url }) => {
try {
const trail = await trails_show(params.id!, params.handle, true, fetch)
const trail = await trails_show(params.id!, params.handle, url.searchParams.get("share") ?? undefined, true, fetch)
return { trail };
} catch (e) {
if (e instanceof APIError) {

View File

@@ -6,7 +6,7 @@ import { currentUser } from "$lib/stores/user_store";
import { error, type Load } from "@sveltejs/kit";
import { get } from "svelte/store";
export const load: Load = async ({ params, fetch }) => {
export const load: Load = async ({ params, fetch, url }) => {
const user = get(currentUser)
if (!params.id) {
@@ -19,7 +19,7 @@ export const load: Load = async ({ params, fetch }) => {
if (params.id === "new") {
trail = new Trail("", { category: categories[0] });
} else {
trail = await trails_show(params.id, undefined, true, fetch);
trail = await trails_show(params.id, undefined, url.searchParams.get("share") ?? undefined, true, fetch);
}
return { trail: trail, lists: lists }

View File

@@ -2,9 +2,9 @@ import { trails_show } from "$lib/stores/trail_store";
import { APIError } from "$lib/util/api_util";
import { error, type Load, type NumericRange } from "@sveltejs/kit";
export const load: Load = async ({ params, fetch }) => {
export const load: Load = async ({ params, fetch, url }) => {
try {
const trail = await trails_show(params.id!, params.handle, true, fetch)
const trail = await trails_show(params.id!, params.handle, url.searchParams.get("share") ?? undefined, true, fetch)
return { trail }
} catch (e) {