diff --git a/.gitignore b/.gitignore
index f7a7b680..1b45bf8a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,5 +7,10 @@ search/meilisearch
search/data.ms
search/dumps
+web/uploads/*
+web/cookie.txt
+
run.sh
-build*.sh
\ No newline at end of file
+build*.sh
+
+data/
\ No newline at end of file
diff --git a/docker-compose.yml b/docker-compose.yml
index f70bd862..1f8df57d 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -53,6 +53,10 @@ services:
BODY_SIZE_LIMIT: Infinity
PUBLIC_POCKETBASE_URL: http://db:8090
PUBLIC_DISABLE_SIGNUP: false
+ UPLOAD_USER: Flomp
+ UPLOAD_PASSWORD: 12345678
+ volumes:
+ - ./data/uploads:/app/uploads
ports:
- "3000:3000"
networks:
diff --git a/web/Dockerfile b/web/Dockerfile
index 154feac9..9592a1d5 100644
--- a/web/Dockerfile
+++ b/web/Dockerfile
@@ -6,8 +6,15 @@ RUN npm ci --omit=dev
EXPOSE 3000
ENV NODE_ENV=production
+COPY ./cron.sh /etc/periodic/15min/cron
+RUN chmod +x /etc/periodic/15min/cron
+RUN mkdir /app/uploads
+RUN apk add curl
+
ENV PUBLIC_POCKETBASE_URL=http://127.0.0.1:8090
ENV MEILI_URL=http://127.0.0.1:7700
ENV PUBLIC_DISABLE_SIGNUP=false
+ENV UPLOAD_USER=
+ENV UPLOAD_PASSWORD=
-CMD [ "node", "build" ]
\ No newline at end of file
+CMD crond && node build
\ No newline at end of file
diff --git a/web/cron.sh b/web/cron.sh
new file mode 100644
index 00000000..608661e8
--- /dev/null
+++ b/web/cron.sh
@@ -0,0 +1,58 @@
+#!/bin/ash
+
+# API endpoint URL
+API_URL="http://localhost:3000/api/v1"
+
+# Folder containing files to upload
+UPLOAD_FOLDER="/app/uploads"
+
+# Credentials for login
+USERNAME=$UPLOAD_USER
+PASSWORD=$UPLOAD_PASSWORD
+
+login() {
+ local username="$1"
+ local password="$2"
+
+ response=$(curl -c cookie.txt --location --request POST "$API_URL/auth/login" --header 'Content-Type: application/json' --data-raw "{\"username\": \"$username\", \"password\": \"$password\"}")
+
+ # Check if login was successful (look for "200 OK" in response headers)
+ if [ $? -eq 0 ] && [ "$(echo "$response" | grep -c "token")" -eq 1 ]; then
+ echo "Login successful. Cookie obtained."
+ else
+ echo "Login failed. Unable to obtain cookie."
+ exit 1
+ fi
+}
+
+# Function to upload file and delete if successful
+upload_and_delete() {
+ local file="$1"
+
+ ls $file
+
+ # API call to upload file
+ response=$(curl -b cookie.txt --location --request PUT "$API_URL/trail/upload" --header 'Content-Type: application/gpx+xml' --data-binary "@$file")
+
+ # Check if API call was successful (status code 200)
+ if [ $? -eq 0 ] && [ "$(echo "$response" | grep -c "author")" -eq 1 ]; then
+ echo "File $file uploaded successfully."
+ # Delete the file
+ rm "$file"
+ echo "File $file deleted."
+ else
+ echo $response
+ echo "Failed to upload file $file."
+ fi
+}
+
+# Login to obtain cookie
+login "$USERNAME" "$PASSWORD"
+
+# Iterate over each file in the folder
+for file in "$UPLOAD_FOLDER"/*; do
+ # Check if file exists and is a regular file
+ if [ -f "$file" ]; then
+ upload_and_delete "$file"
+ fi
+done
diff --git a/web/package-lock.json b/web/package-lock.json
index a27dec65..aa69b0a6 100644
--- a/web/package-lock.json
+++ b/web/package-lock.json
@@ -15,7 +15,6 @@
"@types/leaflet.awesome-markers": "^2.0.28",
"@types/three": "^0.161.2",
"crypto-random-string": "^5.0.0",
- "date-fns": "^3.3.1",
"jsdom": "^24.0.0",
"leaflet": "^1.9.4",
"leaflet-gpx": "^1.7.0",
@@ -1757,15 +1756,6 @@
"node": ">=18"
}
},
- "node_modules/date-fns": {
- "version": "3.3.1",
- "resolved": "https://registry.npmjs.org/date-fns/-/date-fns-3.3.1.tgz",
- "integrity": "sha512-y8e109LYGgoQDveiEBD3DYXKba1jWf5BA8YU1FL5Tvm0BTdEfy54WLCwnuYWZNnzzvALy/QQ4Hov+Q9RVRv+Zw==",
- "funding": {
- "type": "github",
- "url": "https://github.com/sponsors/kossnocorp"
- }
- },
"node_modules/debug": {
"version": "4.3.4",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
diff --git a/web/package.json b/web/package.json
index c4a07597..3a66d36b 100644
--- a/web/package.json
+++ b/web/package.json
@@ -40,7 +40,6 @@
"@types/leaflet.awesome-markers": "^2.0.28",
"@types/three": "^0.161.2",
"crypto-random-string": "^5.0.0",
- "date-fns": "^3.3.1",
"jsdom": "^24.0.0",
"leaflet": "^1.9.4",
"leaflet-gpx": "^1.7.0",
diff --git a/web/src/lib/components/summit_log/summit_log_card.svelte b/web/src/lib/components/summit_log/summit_log_card.svelte
index 098357ce..be2c0258 100644
--- a/web/src/lib/components/summit_log/summit_log_card.svelte
+++ b/web/src/lib/components/summit_log/summit_log_card.svelte
@@ -1,6 +1,6 @@
= writable(new SummitLog(new Date().toISOString()));
+export const summitLog: Writable = writable(new SummitLog(new Date().toISOString().substring(0, 10)));
export async function summit_logs_create(summitLog: SummitLog) {
const r = await fetch('/api/v1/summit-log', {
diff --git a/web/src/lib/stores/trail_store.ts b/web/src/lib/stores/trail_store.ts
index f5a37a32..9de5df7e 100644
--- a/web/src/lib/stores/trail_store.ts
+++ b/web/src/lib/stores/trail_store.ts
@@ -167,7 +167,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 = fetch) {
const r = await f(`/api/v1/trail/${id}?` + new URLSearchParams({
- expand: "category,waypoints,summit_logs,lists_via_trails",
+ expand: "category,waypoints,summit_logs",
}), {
method: 'GET',
})
diff --git a/web/src/routes/trail/edit/[id]/+page.svelte b/web/src/routes/trail/edit/[id]/+page.svelte
index 2eb1b082..b64f9765 100644
--- a/web/src/routes/trail/edit/[id]/+page.svelte
+++ b/web/src/routes/trail/edit/[id]/+page.svelte
@@ -40,7 +40,6 @@
import "$lib/vendor/leaflet-elevation/src/index.css";
import { createForm } from "$lib/vendor/svelte-form-lib";
import cryptoRandomString from "crypto-random-string";
- import { format } from "date-fns";
import type { GPX, Icon, LeafletEvent, Map } from "leaflet";
import "leaflet.awesome-markers/dist/leaflet.awesome-markers.css";
import "leaflet/dist/leaflet.css";
@@ -384,14 +383,8 @@
savedWaypoint.marker = marker;
}
- function beforeSummitLogModalOpen() {
- summitLog.set(new SummitLog(format(new Date(), "yyyy-MM-dd")));
- openSummitLogModal();
- }
-
function saveSummitLog(e: CustomEvent) {
const savedSummitLog = e.detail;
- savedSummitLog.date = format(savedSummitLog.date, "yyyy-MM-dd");
let editedSummitLogIndex = $form.expand.summit_logs.findIndex(
(s) => s.id == savedSummitLog.id,
);
@@ -413,7 +406,6 @@
e: CustomEvent<{ text: string; value: string }>,
) {
if (e.detail.value === "edit") {
- currentSummitLog.date = format(currentSummitLog.date, "yyyy-MM-dd");
summitLog.set(currentSummitLog);
openSummitLogModal();
} else if (e.detail.value === "delete") {
@@ -618,7 +610,7 @@
{#if $lists.length}