fixes gpx import/export errors on Safari
This commit is contained in:
@@ -119,11 +119,13 @@ export default class GPX {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static parse(gpxString: string): Promise<GPX | Error> {
|
static parse(gpxString: string): Promise<GPX | Error> {
|
||||||
return new Promise<GPX | Error>((resolve, reject) => xml2js.parseString(gpxString, {
|
const sanitizedGPX = gpxString.replace(/\sxmlns=""/g, '');
|
||||||
|
|
||||||
|
return new Promise<GPX | Error>((resolve, reject) => xml2js.parseString(sanitizedGPX, {
|
||||||
explicitArray: false,
|
explicitArray: false,
|
||||||
attrValueProcessors: [(str: string | number) => {
|
attrValueProcessors: [(str: string) => {
|
||||||
if (!isNaN(Number(str))) {
|
if (str.length && !isNaN(Number(str))) {
|
||||||
str = Number.isInteger(Number(str)) ? parseInt(String(str), 10) : parseFloat(String(str));
|
return Number.isInteger(Number(str)) ? parseInt(String(str), 10) : parseFloat(String(str));
|
||||||
}
|
}
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
@@ -158,6 +160,9 @@ export default class GPX {
|
|||||||
xmlString = xmlString.replace('<gpx', `<gpx xmlns="${defaultAttributes["xmlns"]}"`);
|
xmlString = xmlString.replace('<gpx', `<gpx xmlns="${defaultAttributes["xmlns"]}"`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Safari for some ungodly reason adds empty xmlns attributes to every tag...
|
||||||
|
xmlString = xmlString.replace(/ xmlns=""/g, '');
|
||||||
|
|
||||||
return xmlString;
|
return xmlString;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -123,8 +123,8 @@
|
|||||||
/>
|
/>
|
||||||
{:else}
|
{:else}
|
||||||
{#each data.trails as trail}
|
{#each data.trails as trail}
|
||||||
<a href="/trail/view/{trail.id}">
|
<a class="w-full md:max-w-72" href="/trail/view/{trail.id}">
|
||||||
<TrailCard {trail}></TrailCard></a
|
<TrailCard {trail} fullWidth></TrailCard></a
|
||||||
>
|
>
|
||||||
{/each}
|
{/each}
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ import { SummitLog } from "$lib/models/summit_log";
|
|||||||
import type { Trail } from "$lib/models/trail";
|
import type { Trail } from "$lib/models/trail";
|
||||||
import { trails_create } from "$lib/stores/trail_store";
|
import { trails_create } from "$lib/stores/trail_store";
|
||||||
import { handleError } from "$lib/util/api_util";
|
import { handleError } from "$lib/util/api_util";
|
||||||
import { fromFile, fromFIT, fromKML, fromTCX, gpx2trail, isFITFile } from "$lib/util/gpx_util";
|
import { fromFile, gpx2trail } from "$lib/util/gpx_util";
|
||||||
import { error, json, type RequestEvent } from "@sveltejs/kit";
|
import { json, type RequestEvent } from "@sveltejs/kit";
|
||||||
import { ClientResponseError } from "pocketbase";
|
import { ClientResponseError } from "pocketbase";
|
||||||
|
|
||||||
export async function PUT(event: RequestEvent) {
|
export async function PUT(event: RequestEvent) {
|
||||||
@@ -30,6 +30,7 @@ export async function PUT(event: RequestEvent) {
|
|||||||
|
|
||||||
trail.expand!.summit_logs.push(log);
|
trail.expand!.summit_logs.push(log);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
|
console.error(e)
|
||||||
throw new ClientResponseError({ status: 400, response: { message: "Invalid file" } })
|
throw new ClientResponseError({ status: 400, response: { message: "Invalid file" } })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user