adds zod API validation

This commit is contained in:
Christian Beutel
2024-12-27 01:56:35 +01:00
parent 1f81779a64
commit 75c94a3ce4
80 changed files with 847 additions and 559 deletions

View File

@@ -203,7 +203,9 @@
<a class="btn-primary btn-large" href="/trail/edit/new"
><i class="fa fa-plus mr-2"></i>{$_("new-trail")}</a
>
<NotificationDropdown></NotificationDropdown>
{#if $page.data.notifications}
<NotificationDropdown></NotificationDropdown>
{/if}
<Dropdown
items={dropdownItems}
on:change={(e) => handleDropdownClick(e.detail)}

View File

@@ -32,13 +32,13 @@
onMount(async () => {});
async function openMap(log: SummitLog) {
if (!log.expand.gpx_data) {
if (!log.expand?.gpx_data) {
return;
}
trail = (await gpx2trail(log.expand.gpx_data)).trail;
trail.id = log.id;
trail.expand.gpx_data = log.expand.gpx_data;
trail.expand!.gpx_data = log.expand.gpx_data;
openMapModal();
await tick();
@@ -75,7 +75,7 @@
{#if summitLogs.some((l) => l.text?.length)}
<th>{$_("description")}</th>
{/if}
{#if showAuthor && summitLogs.some(l => l.expand.author)}
{#if showAuthor && summitLogs.some(l => l.expand?.author)}
<th>
{$_("author", { values: { n: 1 } })}
</th>

View File

@@ -14,7 +14,7 @@
export let fullWidth: boolean = false;
$: thumbnail = trail.photos.length
? getFileURL(trail, trail.photos[trail.thumbnail])
? getFileURL(trail, trail.photos[trail.thumbnail ?? 0])
: "/imgs/default_thumbnail.webp";
$: trailIsShared = (trail.expand?.trail_share_via_trail?.length ?? 0) > 0;
@@ -66,7 +66,7 @@
})}
</p>
{/if}
{#if trail.expand.author}
{#if trail.expand?.author}
<p class="text-xs text-gray-500 mb-3">
{$_("by")}
<img

View File

@@ -34,7 +34,7 @@
const allowEdit =
trail.author == $currentUser?.id ||
trail.expand.trail_share_via_trail?.some((s) => s.permission == "edit");
trail.expand?.trail_share_via_trail?.some((s) => s.permission == "edit");
const dropdownItems: DropdownItem[] = [
mode == "overview"
@@ -142,7 +142,7 @@
}
if (exportSettings.summitLog) {
let summitLogString = "";
for (const summitLog of trail.expand.summit_logs) {
for (const summitLog of trail.expand?.summit_logs ?? []) {
summitLogString += `${summitLog.date},${summitLog.text}\n`;
}
zip.file(

View File

@@ -51,7 +51,7 @@
(trail.expand?.trail_share_via_trail?.length ?? 0) > 0;
let thumbnail = trail.photos.length
? getFileURL(trail, trail.photos[trail.thumbnail])
? getFileURL(trail, trail.photos[trail.thumbnail ?? 0])
: "/imgs/default_thumbnail.webp";
let openGallery: (idx?: number) => void;
@@ -99,7 +99,7 @@
comments_create(newComment).then((c) => {
newComment.text = "";
c.expand = {
author: $currentUser!,
author: { ...$currentUser!, private: false },
};
const newCommentList = [c, ...$comments];
@@ -182,7 +182,7 @@
)}
</h5>
{/if}
{#if trail.expand.author}
{#if trail.expand?.author}
<p class="my-3">
{$_("by")}
<img
@@ -218,7 +218,7 @@
</h3>
</div>
</div>
{#if ($currentUser && $currentUser.id == trail.author) || trail.expand.trail_share_via_trail?.length || trail.public}
{#if ($currentUser && $currentUser.id == trail.author) || trail.expand?.trail_share_via_trail?.length || trail.public}
<TrailDropdown {trail} {mode}></TrailDropdown>
{/if}
</div>
@@ -251,7 +251,7 @@
>{formatElevation(trail.elevation_loss)}</span
>
</div>
{#if trail.expand.category}
{#if trail.expand?.category}
<div class="flex flex-col items-center">
<span>{$_("category")}</span>
<span class="font-semibold text-lg"
@@ -286,7 +286,7 @@
{/if}
{#if activeTab == 1}
<ul>
{#each trail.expand.waypoints ?? [] as waypoint, i}
{#each trail.expand?.waypoints ?? [] as waypoint, i}
<li
on:mouseenter={() => openMarkerPopup(i)}
on:mouseleave={() => closeMarkerPopup(i)}
@@ -322,7 +322,7 @@
{#if activeTab == 3}
<div class="overflow-x-auto">
<SummitLogTable
summitLogs={trail.expand.summit_logs}
summitLogs={trail.expand?.summit_logs}
showAuthor
showRoute
showPhotos

View File

@@ -15,7 +15,7 @@
export let showDescription: boolean = true;
$: thumbnail = trail.photos.length
? getFileURL(trail, trail.photos[trail.thumbnail])
? getFileURL(trail, trail.photos[trail.thumbnail ?? 0])
: "/imgs/default_thumbnail.webp";
</script>
@@ -49,7 +49,7 @@
})}
</p>
{/if}
{#if trail.expand.author}
{#if trail.expand?.author}
<p class="text-xs text-gray-500 mb-3">
{$_("by")}
<img