fixes index filterable attributes & auto trail upload
This commit is contained in:
@@ -157,7 +157,7 @@ func main() {
|
||||
for _, trail := range trails {
|
||||
log.Println(trail)
|
||||
|
||||
if err := util.IndexTrail(trail, client); err != nil {
|
||||
if err := util.UpdateTrail(trail, client); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,10 +19,18 @@ func init() {
|
||||
})
|
||||
|
||||
m.Register(func(db dbx.Builder) error {
|
||||
_, err := client.Index("trails").UpdateFilterableAttributes(&[]string{
|
||||
"_geo", "author", "category", "completed", "date", "difficulty", "distance", "elevation_gain", "public", "shares",
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
dao := daos.New(db)
|
||||
|
||||
var usernames []string
|
||||
err := db.NewQuery("SELECT username FROM users").Column(&usernames)
|
||||
err = db.NewQuery("SELECT username FROM users").Column(&usernames)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -54,8 +54,8 @@ services:
|
||||
PUBLIC_POCKETBASE_URL: http://db:8090
|
||||
PUBLIC_DISABLE_SIGNUP: false
|
||||
UPLOAD_FOLDER: /app/uploads
|
||||
UPLOAD_USER: Flomp
|
||||
UPLOAD_PASSWORD: 12345678
|
||||
UPLOAD_USER:
|
||||
UPLOAD_PASSWORD:
|
||||
PUBLIC_VALHALLA_URL: https://valhalla1.openstreetmap.de
|
||||
volumes:
|
||||
- ./data/uploads:/app/uploads
|
||||
|
||||
Binary file not shown.
14
web/cron.sh
14
web/cron.sh
@@ -18,9 +18,9 @@ login() {
|
||||
|
||||
# Check if login was successful (look for "200 OK" in response headers)
|
||||
if [ $? -eq 0 ] && [ "$(echo "$response" | grep -c "token")" -eq 1 ]; then
|
||||
echo "$(date +"%T"): Login successful. Cookie obtained." > /proc/1/fd/1
|
||||
echo "[INFO] [$(date +"%T")]: Login successful. Cookie obtained." > /proc/1/fd/1
|
||||
else
|
||||
echo "$(date +"%T"): Login failed. Unable to obtain cookie." > /proc/1/fd/1
|
||||
echo "[ERROR] [$(date +"%T")]: Login failed. Unable to obtain cookie." > /proc/1/fd/1
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
@@ -36,16 +36,16 @@ upload_and_delete() {
|
||||
|
||||
# Check if API call was successful (status code 200)
|
||||
if [ $? -eq 0 ] && [ "$(echo "$response" | grep -c "author")" -eq 1 ]; then
|
||||
echo "$(date +"%T"): File $file uploaded successfully." > /proc/1/fd/1
|
||||
echo "[INFO] [$(date +"%T")]: File $file uploaded successfully." > /proc/1/fd/1
|
||||
# Delete the file
|
||||
rm "$file"
|
||||
echo "File $file deleted."
|
||||
echo "[INFO] [$(date +"%T")]: File $file deleted."
|
||||
else
|
||||
echo $response
|
||||
echo "$(date +"%T"): Failed to upload file $file." > /proc/1/fd/1
|
||||
echo "[ERROR] [$(date +"%T")]: Failed to upload file $file." > /proc/1/fd/1
|
||||
fi
|
||||
}
|
||||
echo "$(date +"%T"): Starting auto-upload" > /proc/1/fd/1
|
||||
echo "[INFO] [$(date +"%T")]: Starting auto-upload" > /proc/1/fd/1
|
||||
# Login to obtain cookie
|
||||
login "$USERNAME" "$PASSWORD"
|
||||
|
||||
@@ -57,4 +57,4 @@ for file in "$UPLOAD_FOLDER"/*; do
|
||||
fi
|
||||
done
|
||||
|
||||
echo "$(date +"%T"): Auto-upload completed" > /proc/1/fd/1
|
||||
echo "[INFO] [$(date +"%T")]: Auto-upload completed" > /proc/1/fd/1
|
||||
|
||||
@@ -8,8 +8,10 @@
|
||||
import type { Trail } from "$lib/models/trail";
|
||||
|
||||
import {
|
||||
comments,
|
||||
comments_create,
|
||||
comments_delete,
|
||||
comments_index,
|
||||
comments_update,
|
||||
} from "$lib/stores/comment_store";
|
||||
import { currentUser } from "$lib/stores/user_store";
|
||||
@@ -59,6 +61,10 @@
|
||||
let commentCreateLoading: boolean = false;
|
||||
let commentDeleteLoading: boolean = false;
|
||||
|
||||
$: if (activeTab == 4) {
|
||||
fetchComments();
|
||||
}
|
||||
|
||||
onMount(async () => {
|
||||
if (mode == "overview") {
|
||||
const L = (await import("leaflet")).default;
|
||||
@@ -115,6 +121,10 @@
|
||||
goto(`/map/trail/${trail.id!}`);
|
||||
}
|
||||
|
||||
async function fetchComments() {
|
||||
await comments_index(trail);
|
||||
}
|
||||
|
||||
async function createComment() {
|
||||
if (!$currentUser || !trail.id) {
|
||||
return;
|
||||
@@ -129,10 +139,8 @@
|
||||
author: $currentUser!,
|
||||
};
|
||||
|
||||
trail.expand.comments_via_trail = [
|
||||
c,
|
||||
...(trail.expand.comments_via_trail ?? []),
|
||||
];
|
||||
const newCommentList = [c, ...$comments];
|
||||
comments.set(newCommentList);
|
||||
});
|
||||
|
||||
commentCreateLoading = false;
|
||||
@@ -146,8 +154,8 @@
|
||||
async function deleteComment(comment: Comment) {
|
||||
commentDeleteLoading = true;
|
||||
await comments_delete(comment);
|
||||
trail.expand.comments_via_trail =
|
||||
trail.expand.comments_via_trail.filter((c) => c.id !== comment.id);
|
||||
const newCommentList = $comments.filter((c) => c.id !== comment.id);
|
||||
comments.set(newCommentList);
|
||||
commentDeleteLoading = false;
|
||||
}
|
||||
</script>
|
||||
@@ -155,9 +163,9 @@
|
||||
<div
|
||||
class="trail-info-panel max-w-5xl mx-auto border border-input-border rounded-3xl h-full"
|
||||
>
|
||||
<div class="trail-info-panel-header sticky -top-44 z-10">
|
||||
<div class="trail-info-panel-header">
|
||||
<section class="relative h-80">
|
||||
<img class="w-full h-80 rounded-3xl" src={thumbnail} alt="" />
|
||||
<img class="w-full h-80 rounded-t-3xl" src={thumbnail} alt="" />
|
||||
<div
|
||||
class="absolute bottom-0 w-full h-1/2 bg-gradient-to-b from-transparent to-black opacity-50"
|
||||
></div>
|
||||
@@ -257,11 +265,13 @@
|
||||
</section>
|
||||
<hr class="border-separator" />
|
||||
{/if}
|
||||
<section class="trail-info-panel-tabs px-4 py-2 bg-background">
|
||||
</div>
|
||||
<section
|
||||
class="trail-info-panel-tabs px-4 py-2 bg-background sticky top-0"
|
||||
>
|
||||
<Tabs {tabs} bind:activeTab></Tabs>
|
||||
</section>
|
||||
</div>
|
||||
<section class="trail-info-panel-content px-8">
|
||||
<section class="trail-info-panel-content px-8 overflow-y-scroll" style="height: calc(100% - 394px)">
|
||||
<div
|
||||
class="grid grid-cols-1 my-4 gap-8"
|
||||
class:md:grid-cols-[1fr_18rem]={mode == "overview"}
|
||||
@@ -342,7 +352,7 @@
|
||||
</div>
|
||||
{/if}
|
||||
<ul class="space-y-4">
|
||||
{#each trail.expand.comments_via_trail ?? [] as comment}
|
||||
{#each $comments ?? [] as comment}
|
||||
<li>
|
||||
<CommentCard
|
||||
{comment}
|
||||
|
||||
@@ -52,7 +52,7 @@
|
||||
></i>
|
||||
{#if showInfo}
|
||||
<ul
|
||||
class="menu absolute top-7 bg-menu-background border border-input-border rounded-xl shadow-md overflow-hidden p-3 space-y-3 text-content"
|
||||
class="menu absolute z-10 top-7 bg-menu-background border border-input-border rounded-xl shadow-md overflow-hidden p-3 space-y-3 text-content"
|
||||
in:fly={{y: -10, duration: 150}} out:fly={{y: -10, duration: 150}}
|
||||
>
|
||||
{#if loading}
|
||||
|
||||
@@ -1,10 +1,28 @@
|
||||
import { Comment } from "$lib/models/comment";
|
||||
import type { Trail } from "$lib/models/trail";
|
||||
import { pb } from "$lib/pocketbase";
|
||||
import { ClientResponseError } from "pocketbase";
|
||||
import { writable, type Writable } from "svelte/store";
|
||||
|
||||
export const comments: Writable<Comment[]> = writable([])
|
||||
|
||||
export async function comments_index(trail: Trail) {
|
||||
let r = await fetch('/api/v1/comment?' + new URLSearchParams({
|
||||
filter: `trail = ${trail.id}`,
|
||||
}), {
|
||||
method: 'GET',
|
||||
})
|
||||
|
||||
if (!r.ok) {
|
||||
throw new ClientResponseError(await r.json())
|
||||
}
|
||||
|
||||
const fetchedComments: Comment[] = await r.json();
|
||||
|
||||
comments.set(fetchedComments);
|
||||
|
||||
return fetchedComments;
|
||||
}
|
||||
|
||||
export async function comments_create(comment: Comment) {
|
||||
if (!pb.authStore.model) {
|
||||
|
||||
@@ -131,7 +131,7 @@ export async function trails_search_bounding_box(northEast: LatLng, southWest: L
|
||||
|
||||
export async function trails_show(id: string, loadGPX?: boolean, f: (url: RequestInfo | URL, config?: RequestInit) => Promise<Response> = fetch) {
|
||||
const r = await f(`/api/v1/trail/${id}?` + new URLSearchParams({
|
||||
expand: "category,waypoints,summit_logs,comments_via_trail.author,trail_share_via_trail",
|
||||
expand: "category,waypoints,summit_logs,trail_share_via_trail",
|
||||
}), {
|
||||
method: 'GET',
|
||||
})
|
||||
|
||||
@@ -16,7 +16,7 @@ export async function gpx2trail(gpxString: string) {
|
||||
|
||||
const trail = new Trail("");
|
||||
|
||||
trail.name = gpx.metadata?.name ?? `trail-${new Date().toISOString()}`;
|
||||
trail.name = gpx.metadata?.name || `trail-${new Date().toISOString()}`;
|
||||
|
||||
trail.description = gpx.metadata?.desc;
|
||||
|
||||
|
||||
@@ -3,11 +3,21 @@ import { pb } from '$lib/pocketbase';
|
||||
import { error, json, type RequestEvent } from '@sveltejs/kit';
|
||||
|
||||
export async function GET(event: RequestEvent) {
|
||||
const filter = event.url.searchParams.get('filter') ?? ""
|
||||
|
||||
try {
|
||||
const r: Comment[] = await pb.collection('comments').getFullList<Comment>({
|
||||
expand: "author",
|
||||
sort: "-created",
|
||||
})
|
||||
|
||||
for (const comment of r) {
|
||||
if(!comment.expand?.author) {
|
||||
comment.expand = {
|
||||
author: await pb.collection('users_anonymous').getOne(comment.author)
|
||||
}
|
||||
}
|
||||
}
|
||||
return json(r)
|
||||
} catch (e: any) {
|
||||
throw error(e.status, e);
|
||||
|
||||
Reference in New Issue
Block a user