From 3d54a8392be94a369bf388dad0f83f60fb5a5474 Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Tue, 2 Jan 2024 18:06:25 +0100 Subject: [PATCH] Fix: improve parsing of possible mapillary values --- src/Logic/ImageProviders/Mapillary.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/Logic/ImageProviders/Mapillary.ts b/src/Logic/ImageProviders/Mapillary.ts index 8f7e1c97a..85f1bd1ac 100644 --- a/src/Logic/ImageProviders/Mapillary.ts +++ b/src/Logic/ImageProviders/Mapillary.ts @@ -84,10 +84,20 @@ export class Mapillary extends ImageProvider { private static ExtractKeyFromURL(value: string): number { let key: string - const newApiFormat = value.match(/https?:\/\/www.mapillary.com\/app\/\?pKey=([0-9]*)/) - if (newApiFormat !== null) { - key = newApiFormat[1] - } else if (value.startsWith(Mapillary.valuePrefix)) { + if (value.startsWith("http")) { + try { + const url = new URL(value.toLowerCase()) + if (url.searchParams.has("pkey")) { + const pkey = Number(url.searchParams.get("pkey")) + if (!isNaN(pkey)) { + return pkey + } + } + } catch (e) { + console.log("Could not parse value for mapillary:", value) + } + } + if (value.startsWith(Mapillary.valuePrefix)) { key = value.substring(0, value.lastIndexOf("?")).substring(value.lastIndexOf("/") + 1) } else if (value.match("[0-9]*")) { key = value