fix waypoint creation from photo (#1006)

This commit is contained in:
slothful-vassal
2026-05-26 09:24:45 +02:00
committed by GitHub
parent f7c7c6d805
commit 04844a64dd
2 changed files with 81 additions and 32 deletions

View File

@@ -0,0 +1,33 @@
import { handleError } from "$lib/util/api_util";
import { json, type RequestEvent } from "@sveltejs/kit";
import { z } from "zod";
const WaypointClusterPointSchema = z.object({
id: z.string().min(1),
lat: z.number().min(-90).max(90),
lon: z.number().min(-180).max(180),
});
const WaypointClusterSchema = z.object({
category: z.string().length(15).or(z.literal("")).optional(),
photos: z.array(WaypointClusterPointSchema),
waypoints: z.array(WaypointClusterPointSchema),
});
export async function POST(event: RequestEvent) {
try {
const data = WaypointClusterSchema.parse(await event.request.json());
const response = await event.locals.pb.send("/waypoint/cluster", {
method: "POST",
headers: {
"content-type": "application/json",
},
body: JSON.stringify(data),
fetch: event.fetch,
});
return json(response);
} catch (e) {
return handleError(e);
}
}

View File

@@ -77,7 +77,6 @@
import RouteEditor from "$lib/components/trail/route_editor.svelte"; import RouteEditor from "$lib/components/trail/route_editor.svelte";
import { TagCreateSchema } from "$lib/models/api/tag_schema.js"; import { TagCreateSchema } from "$lib/models/api/tag_schema.js";
import { convertDMSToDD } from "$lib/models/gpx/utils.js"; import { convertDMSToDD } from "$lib/models/gpx/utils.js";
import { getPb } from "$lib/pocketbase";
import { Tag } from "$lib/models/tag.js"; import { Tag } from "$lib/models/tag.js";
import { import {
searchLocationReverse, searchLocationReverse,
@@ -541,13 +540,7 @@
} }
try { try {
const clusterResponse: WaypointPhotoClusterResponse = const clusterResponse = await clusterWaypointPhotos({
await getPb().send("/waypoint/cluster", {
method: "POST",
headers: {
"content-type": "application/json",
},
body: JSON.stringify({
category: $formData.category, category: $formData.category,
photos: [ photos: [
{ {
@@ -557,7 +550,6 @@
}, },
], ],
waypoints: existingWaypoints, waypoints: existingWaypoints,
}),
}); });
const matchingCluster = clusterResponse.clusters.find( const matchingCluster = clusterResponse.clusters.find(
@@ -1323,6 +1315,36 @@
clusters: WaypointPhotoCluster[]; clusters: WaypointPhotoCluster[];
} }
interface WaypointClusterPoint {
id: string;
lat: number;
lon: number;
}
interface WaypointPhotoClusterRequest {
category?: string;
photos: WaypointClusterPoint[];
waypoints: WaypointClusterPoint[];
}
async function clusterWaypointPhotos(
data: WaypointPhotoClusterRequest,
): Promise<WaypointPhotoClusterResponse> {
const response = await fetch("/api/v1/waypoint/cluster", {
method: "POST",
headers: {
"content-type": "application/json",
},
body: JSON.stringify(data),
});
if (!response.ok) {
throw await response.json();
}
return (await response.json()) as WaypointPhotoClusterResponse;
}
const waypointMergeCheckPhotoId = "__waypoint_merge_check__"; const waypointMergeCheckPhotoId = "__waypoint_merge_check__";
async function handleWaypointPhotoSelection() { async function handleWaypointPhotoSelection() {
@@ -1374,12 +1396,7 @@
let clusterResponse: WaypointPhotoClusterResponse; let clusterResponse: WaypointPhotoClusterResponse;
try { try {
clusterResponse = await getPb().send("/waypoint/cluster", { clusterResponse = await clusterWaypointPhotos({
method: "POST",
headers: {
"content-type": "application/json",
},
body: JSON.stringify({
category: $formData.category, category: $formData.category,
photos: photoCoords.map((coords) => ({ photos: photoCoords.map((coords) => ({
id: coords.id, id: coords.id,
@@ -1387,7 +1404,6 @@
lon: coords.longitude, lon: coords.longitude,
})), })),
waypoints: getExistingWaypointClusterInputs(), waypoints: getExistingWaypointClusterInputs(),
}),
}); });
} catch (e) { } catch (e) {
show_toast( show_toast(