adds trail link sharing
This commit is contained in:
26
web/src/routes/api/v1/trail-link-share/+server.ts
Normal file
26
web/src/routes/api/v1/trail-link-share/+server.ts
Normal 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)
|
||||
}
|
||||
}
|
||||
31
web/src/routes/api/v1/trail-link-share/[id]/+server.ts
Normal file
31
web/src/routes/api/v1/trail-link-share/[id]/+server.ts
Normal 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)
|
||||
}
|
||||
}
|
||||
@@ -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}`
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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],
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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 }
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user