fixes index filterable attributes & auto trail upload
This commit is contained in:
@@ -157,7 +157,7 @@ func main() {
|
|||||||
for _, trail := range trails {
|
for _, trail := range trails {
|
||||||
log.Println(trail)
|
log.Println(trail)
|
||||||
|
|
||||||
if err := util.IndexTrail(trail, client); err != nil {
|
if err := util.UpdateTrail(trail, client); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,10 +19,18 @@ func init() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
m.Register(func(db dbx.Builder) error {
|
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)
|
dao := daos.New(db)
|
||||||
|
|
||||||
var usernames []string
|
var usernames []string
|
||||||
err := db.NewQuery("SELECT username FROM users").Column(&usernames)
|
err = db.NewQuery("SELECT username FROM users").Column(&usernames)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -54,8 +54,8 @@ services:
|
|||||||
PUBLIC_POCKETBASE_URL: http://db:8090
|
PUBLIC_POCKETBASE_URL: http://db:8090
|
||||||
PUBLIC_DISABLE_SIGNUP: false
|
PUBLIC_DISABLE_SIGNUP: false
|
||||||
UPLOAD_FOLDER: /app/uploads
|
UPLOAD_FOLDER: /app/uploads
|
||||||
UPLOAD_USER: Flomp
|
UPLOAD_USER:
|
||||||
UPLOAD_PASSWORD: 12345678
|
UPLOAD_PASSWORD:
|
||||||
PUBLIC_VALHALLA_URL: https://valhalla1.openstreetmap.de
|
PUBLIC_VALHALLA_URL: https://valhalla1.openstreetmap.de
|
||||||
volumes:
|
volumes:
|
||||||
- ./data/uploads:/app/uploads
|
- ./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)
|
# Check if login was successful (look for "200 OK" in response headers)
|
||||||
if [ $? -eq 0 ] && [ "$(echo "$response" | grep -c "token")" -eq 1 ]; then
|
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
|
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
|
exit 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@@ -36,16 +36,16 @@ upload_and_delete() {
|
|||||||
|
|
||||||
# Check if API call was successful (status code 200)
|
# Check if API call was successful (status code 200)
|
||||||
if [ $? -eq 0 ] && [ "$(echo "$response" | grep -c "author")" -eq 1 ]; then
|
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
|
# Delete the file
|
||||||
rm "$file"
|
rm "$file"
|
||||||
echo "File $file deleted."
|
echo "[INFO] [$(date +"%T")]: File $file deleted."
|
||||||
else
|
else
|
||||||
echo $response
|
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
|
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 to obtain cookie
|
||||||
login "$USERNAME" "$PASSWORD"
|
login "$USERNAME" "$PASSWORD"
|
||||||
|
|
||||||
@@ -57,4 +57,4 @@ for file in "$UPLOAD_FOLDER"/*; do
|
|||||||
fi
|
fi
|
||||||
done
|
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 type { Trail } from "$lib/models/trail";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
comments,
|
||||||
comments_create,
|
comments_create,
|
||||||
comments_delete,
|
comments_delete,
|
||||||
|
comments_index,
|
||||||
comments_update,
|
comments_update,
|
||||||
} from "$lib/stores/comment_store";
|
} from "$lib/stores/comment_store";
|
||||||
import { currentUser } from "$lib/stores/user_store";
|
import { currentUser } from "$lib/stores/user_store";
|
||||||
@@ -59,6 +61,10 @@
|
|||||||
let commentCreateLoading: boolean = false;
|
let commentCreateLoading: boolean = false;
|
||||||
let commentDeleteLoading: boolean = false;
|
let commentDeleteLoading: boolean = false;
|
||||||
|
|
||||||
|
$: if (activeTab == 4) {
|
||||||
|
fetchComments();
|
||||||
|
}
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
if (mode == "overview") {
|
if (mode == "overview") {
|
||||||
const L = (await import("leaflet")).default;
|
const L = (await import("leaflet")).default;
|
||||||
@@ -115,6 +121,10 @@
|
|||||||
goto(`/map/trail/${trail.id!}`);
|
goto(`/map/trail/${trail.id!}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function fetchComments() {
|
||||||
|
await comments_index(trail);
|
||||||
|
}
|
||||||
|
|
||||||
async function createComment() {
|
async function createComment() {
|
||||||
if (!$currentUser || !trail.id) {
|
if (!$currentUser || !trail.id) {
|
||||||
return;
|
return;
|
||||||
@@ -129,10 +139,8 @@
|
|||||||
author: $currentUser!,
|
author: $currentUser!,
|
||||||
};
|
};
|
||||||
|
|
||||||
trail.expand.comments_via_trail = [
|
const newCommentList = [c, ...$comments];
|
||||||
c,
|
comments.set(newCommentList);
|
||||||
...(trail.expand.comments_via_trail ?? []),
|
|
||||||
];
|
|
||||||
});
|
});
|
||||||
|
|
||||||
commentCreateLoading = false;
|
commentCreateLoading = false;
|
||||||
@@ -146,8 +154,8 @@
|
|||||||
async function deleteComment(comment: Comment) {
|
async function deleteComment(comment: Comment) {
|
||||||
commentDeleteLoading = true;
|
commentDeleteLoading = true;
|
||||||
await comments_delete(comment);
|
await comments_delete(comment);
|
||||||
trail.expand.comments_via_trail =
|
const newCommentList = $comments.filter((c) => c.id !== comment.id);
|
||||||
trail.expand.comments_via_trail.filter((c) => c.id !== comment.id);
|
comments.set(newCommentList);
|
||||||
commentDeleteLoading = false;
|
commentDeleteLoading = false;
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
@@ -155,9 +163,9 @@
|
|||||||
<div
|
<div
|
||||||
class="trail-info-panel max-w-5xl mx-auto border border-input-border rounded-3xl h-full"
|
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">
|
<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
|
<div
|
||||||
class="absolute bottom-0 w-full h-1/2 bg-gradient-to-b from-transparent to-black opacity-50"
|
class="absolute bottom-0 w-full h-1/2 bg-gradient-to-b from-transparent to-black opacity-50"
|
||||||
></div>
|
></div>
|
||||||
@@ -257,11 +265,13 @@
|
|||||||
</section>
|
</section>
|
||||||
<hr class="border-separator" />
|
<hr class="border-separator" />
|
||||||
{/if}
|
{/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>
|
<Tabs {tabs} bind:activeTab></Tabs>
|
||||||
</section>
|
</section>
|
||||||
</div>
|
<section class="trail-info-panel-content px-8 overflow-y-scroll" style="height: calc(100% - 394px)">
|
||||||
<section class="trail-info-panel-content px-8">
|
|
||||||
<div
|
<div
|
||||||
class="grid grid-cols-1 my-4 gap-8"
|
class="grid grid-cols-1 my-4 gap-8"
|
||||||
class:md:grid-cols-[1fr_18rem]={mode == "overview"}
|
class:md:grid-cols-[1fr_18rem]={mode == "overview"}
|
||||||
@@ -342,7 +352,7 @@
|
|||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
<ul class="space-y-4">
|
<ul class="space-y-4">
|
||||||
{#each trail.expand.comments_via_trail ?? [] as comment}
|
{#each $comments ?? [] as comment}
|
||||||
<li>
|
<li>
|
||||||
<CommentCard
|
<CommentCard
|
||||||
{comment}
|
{comment}
|
||||||
|
|||||||
@@ -52,7 +52,7 @@
|
|||||||
></i>
|
></i>
|
||||||
{#if showInfo}
|
{#if showInfo}
|
||||||
<ul
|
<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}}
|
in:fly={{y: -10, duration: 150}} out:fly={{y: -10, duration: 150}}
|
||||||
>
|
>
|
||||||
{#if loading}
|
{#if loading}
|
||||||
|
|||||||
@@ -1,10 +1,28 @@
|
|||||||
import { Comment } from "$lib/models/comment";
|
import { Comment } from "$lib/models/comment";
|
||||||
|
import type { Trail } from "$lib/models/trail";
|
||||||
import { pb } from "$lib/pocketbase";
|
import { pb } from "$lib/pocketbase";
|
||||||
import { ClientResponseError } from "pocketbase";
|
import { ClientResponseError } from "pocketbase";
|
||||||
import { writable, type Writable } from "svelte/store";
|
import { writable, type Writable } from "svelte/store";
|
||||||
|
|
||||||
export const comments: Writable<Comment[]> = writable([])
|
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) {
|
export async function comments_create(comment: Comment) {
|
||||||
if (!pb.authStore.model) {
|
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) {
|
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({
|
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',
|
method: 'GET',
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ export async function gpx2trail(gpxString: string) {
|
|||||||
|
|
||||||
const trail = new Trail("");
|
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;
|
trail.description = gpx.metadata?.desc;
|
||||||
|
|
||||||
|
|||||||
@@ -3,11 +3,21 @@ import { pb } from '$lib/pocketbase';
|
|||||||
import { error, json, type RequestEvent } from '@sveltejs/kit';
|
import { error, json, type RequestEvent } from '@sveltejs/kit';
|
||||||
|
|
||||||
export async function GET(event: RequestEvent) {
|
export async function GET(event: RequestEvent) {
|
||||||
|
const filter = event.url.searchParams.get('filter') ?? ""
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const r: Comment[] = await pb.collection('comments').getFullList<Comment>({
|
const r: Comment[] = await pb.collection('comments').getFullList<Comment>({
|
||||||
expand: "author",
|
expand: "author",
|
||||||
sort: "-created",
|
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)
|
return json(r)
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
throw error(e.status, e);
|
throw error(e.status, e);
|
||||||
|
|||||||
Reference in New Issue
Block a user