fixes serverside pb usage
This commit is contained in:
@@ -117,7 +117,7 @@
|
||||
summitLog: boolean;
|
||||
}) {
|
||||
try {
|
||||
let fileData: string = await trail2gpx(trail);
|
||||
let fileData: string = await trail2gpx(trail, $currentUser);
|
||||
if (exportSettings.fileFormat == "json") {
|
||||
fileData = JSON.stringify(
|
||||
gpx(
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { SummitLog, type SummitLogFilter } from "$lib/models/summit_log";
|
||||
import { APIError } from "$lib/util/api_util";
|
||||
import { type ListResult } from "pocketbase";
|
||||
import { type AuthRecord, type ListResult } from "pocketbase";
|
||||
import { get, writable, type Writable } from "svelte/store";
|
||||
import { currentUser } from "./user_store";
|
||||
|
||||
@@ -45,8 +45,8 @@ export async function summit_logs_index(author: string, filter?: SummitLogFilter
|
||||
return fetchedSummitLogs;
|
||||
}
|
||||
|
||||
export async function summit_logs_create(summitLog: SummitLog, f: (url: RequestInfo | URL, config?: RequestInit) => Promise<Response> = fetch) {
|
||||
const user = get(currentUser)
|
||||
export async function summit_logs_create(summitLog: SummitLog, f: (url: RequestInfo | URL, config?: RequestInit) => Promise<Response> = fetch, user?: AuthRecord) {
|
||||
user ??= get(currentUser)
|
||||
if (!user) {
|
||||
throw Error("Unauthenticated")
|
||||
}
|
||||
|
||||
@@ -175,8 +175,8 @@ export async function trails_show(id: string, loadGPX?: boolean, f: (url: Reques
|
||||
return response as Trail;
|
||||
}
|
||||
|
||||
export async function trails_create(trail: Trail, photos: File[], gpx: File | Blob | null, f: (url: RequestInfo | URL, config?: RequestInit) => Promise<Response> = fetch) {
|
||||
const user = get(currentUser)
|
||||
export async function trails_create(trail: Trail, photos: File[], gpx: File | Blob | null, f: (url: RequestInfo | URL, config?: RequestInit) => Promise<Response> = fetch, user?: AuthRecord) {
|
||||
user ??= get(currentUser)
|
||||
if (!user) {
|
||||
throw Error("Unauthenticated")
|
||||
}
|
||||
|
||||
@@ -2,11 +2,12 @@ import { Waypoint } from "$lib/models/waypoint";
|
||||
import { APIError } from "$lib/util/api_util";
|
||||
import { get, writable, type Writable } from "svelte/store";
|
||||
import { currentUser } from "./user_store";
|
||||
import type { AuthRecord } from "pocketbase";
|
||||
|
||||
export const waypoint: Writable<Waypoint> = writable(new Waypoint(0, 0));
|
||||
|
||||
export async function waypoints_create(waypoint: Waypoint, f: (url: RequestInfo | URL, config?: RequestInit) => Promise<Response> = fetch) {
|
||||
const user = get(currentUser)
|
||||
export async function waypoints_create(waypoint: Waypoint, f: (url: RequestInfo | URL, config?: RequestInit) => Promise<Response> = fetch, user?: AuthRecord) {
|
||||
user ??= get(currentUser)
|
||||
if (!user) {
|
||||
throw Error("Unauthenticated")
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import type { Feature, FeatureCollection, GeoJSON, GeoJsonProperties, Position }
|
||||
import * as xmldom from 'xmldom';
|
||||
import { bbox, splitMultiLineStringToLineStrings } from "./geojson_util";
|
||||
import JSZip from "jszip";
|
||||
import type { AuthRecord } from "pocketbase";
|
||||
|
||||
|
||||
export async function gpx2trail(gpxString: string, fallbackName?: string) {
|
||||
@@ -66,7 +67,7 @@ export async function gpx2trail(gpxString: string, fallbackName?: string) {
|
||||
return { gpx: gpx, trail: trail }
|
||||
}
|
||||
|
||||
export async function trail2gpx(trail: Trail) {
|
||||
export async function trail2gpx(trail: Trail, user?: AuthRecord) {
|
||||
if (!trail.expand?.gpx_data) {
|
||||
throw Error("Trail has no GPX data")
|
||||
}
|
||||
@@ -81,7 +82,7 @@ export async function trail2gpx(trail: Trail) {
|
||||
desc: trail.description ?? "",
|
||||
time: trail.date ? new Date(trail.date) : new Date(),
|
||||
keywords: `${trail.category ?? ""}, ${trail.location ?? ""}`,
|
||||
author: { name: trail.author ?? "", email: get(currentUser)?.email ?? "" }
|
||||
author: { name: trail.author ?? "", email: user?.email ?? "" }
|
||||
}
|
||||
|
||||
if (!gpx.wpt) {
|
||||
|
||||
@@ -53,7 +53,7 @@ export async function PUT(event: RequestEvent) {
|
||||
|
||||
|
||||
try {
|
||||
trail = await trails_create(trail, [], gpxFile, event.fetch);
|
||||
trail = await trails_create(trail, [], gpxFile, event.fetch, event.locals.user);
|
||||
} catch (e: any) {
|
||||
console.error(e)
|
||||
throw handleError(e)
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
import { show_toast } from "$lib/stores/toast_store.svelte";
|
||||
import { fetchGPX, trails_index, trails_upload } from "$lib/stores/trail_store";
|
||||
import { processUploadQueue, uploadStore, type Upload } from "$lib/stores/upload_store.svelte";
|
||||
import { currentUser } from "$lib/stores/user_store";
|
||||
import { getFileURL, saveAs } from "$lib/util/file_util";
|
||||
import { trail2gpx } from "$lib/util/gpx_util";
|
||||
import { gpx } from "$lib/vendor/toGeoJSON/toGeoJSON";
|
||||
@@ -78,7 +79,7 @@
|
||||
}
|
||||
trail.expand!.gpx_data = gpxData;
|
||||
const trailFolder = zip.folder(`${trail.name}`);
|
||||
let fileData: string = await trail2gpx(trail);
|
||||
let fileData: string = await trail2gpx(trail, $currentUser);
|
||||
if (exportSettings.fileFormat == "json") {
|
||||
fileData = JSON.stringify(
|
||||
gpx(
|
||||
|
||||
Reference in New Issue
Block a user