From 3570cfbaa8aa3fcee2dab8e267e4eea0928e9114 Mon Sep 17 00:00:00 2001 From: pietervdvn Date: Thu, 11 Nov 2021 17:35:24 +0100 Subject: [PATCH] Drop support for mapillary v3.0, small fix for custom themes --- Logic/ImageProviders/Mapillary.ts | 95 +++++++------------------ Models/ThemeConfig/LegacyJsonConvert.ts | 2 +- 2 files changed, 27 insertions(+), 70 deletions(-) diff --git a/Logic/ImageProviders/Mapillary.ts b/Logic/ImageProviders/Mapillary.ts index 184af3a8e4..1486c73a21 100644 --- a/Logic/ImageProviders/Mapillary.ts +++ b/Logic/ImageProviders/Mapillary.ts @@ -12,42 +12,26 @@ export class Mapillary extends ImageProvider { public static readonly valuePrefixes = [Mapillary.valuePrefix, "http://mapillary.com", "https://mapillary.com", "http://www.mapillary.com", "https://www.mapillary.com"] defaultKeyPrefixes = ["mapillary", "image"] - private static ExtractKeyFromURL(value: string, failIfNoMath = false): { - key: string, - isApiv4?: boolean - } { + /** + * Returns the correct key for API v4.0 + */ + private static ExtractKeyFromURL(value: string): number { + + let key: string; - if (value.startsWith(Mapillary.valuePrefix)) { - const key = value.substring(0, value.lastIndexOf("?")).substring(value.lastIndexOf("/") + 1) - return {key: key, isApiv4: !isNaN(Number(key))}; - } const newApiFormat = value.match(/https?:\/\/www.mapillary.com\/app\/\?pKey=([0-9]*)/) if (newApiFormat !== null) { - return {key: newApiFormat[1], isApiv4: true} + key = newApiFormat[1] + } else if (value.startsWith(Mapillary.valuePrefix)) { + key = value.substring(0, value.lastIndexOf("?")).substring(value.lastIndexOf("/") + 1) } - const mapview = value.match(/https?:\/\/www.mapillary.com\/map\/im\/(.*)/) - if (mapview !== null) { - const key = mapview[1] - return {key: key, isApiv4: !isNaN(Number(key))}; + const keyAsNumber = Number(key) + if (!isNaN(keyAsNumber)) { + return keyAsNumber } - - if (value.toLowerCase().startsWith("https://www.mapillary.com/map/im/")) { - // Extract the key of the image - value = value.substring("https://www.mapillary.com/map/im/".length); - } - - const matchApi = value.match(/https?:\/\/images.mapillary.com\/([^/]*)(&.*)?/) - if (matchApi !== null) { - return {key: matchApi[1]}; - } - - if (failIfNoMath) { - return undefined; - } - - return {key: value, isApiv4: !isNaN(Number(value))}; + return undefined } SourceIcon(backlinkSource?: string): BaseUIElement { @@ -59,54 +43,27 @@ export class Mapillary extends ImageProvider { } protected async DownloadAttribution(url: string): Promise { - - const keyV = Mapillary.ExtractKeyFromURL(url) - if (keyV.isApiv4) { - const license = new LicenseInfo() - license.artist = "Contributor name unavailable"; - license.license = "CC BY-SA 4.0"; - // license.license = "Creative Commons Attribution-ShareAlike 4.0 International License"; - license.attributionRequired = true; - return license - - } - const key = keyV.key - - const metadataURL = `https://a.mapillary.com/v3/images/${key}?client_id=TXhLaWthQ1d4RUg0czVxaTVoRjFJZzowNDczNjUzNmIyNTQyYzI2` - const data = await Utils.downloadJson(metadataURL) - const license = new LicenseInfo(); - license.artist = data.properties?.username; - license.licenseShortName = "CC BY-SA 4.0"; - license.license = "Creative Commons Attribution-ShareAlike 4.0 International License"; + const license = new LicenseInfo() + license.artist = "Contributor name unavailable"; + license.license = "CC BY-SA 4.0"; + // license.license = "Creative Commons Attribution-ShareAlike 4.0 International License"; license.attributionRequired = true; - return license } private async PrepareUrlAsync(key: string, value: string): Promise { - const failIfNoMatch = key.indexOf("mapillary") < 0 - const keyV = Mapillary.ExtractKeyFromURL(value, failIfNoMatch) - if (keyV === undefined) { + const mapillaryId = Mapillary.ExtractKeyFromURL(value) + if (mapillaryId === undefined) { return undefined; } - if (!keyV.isApiv4) { - const url = `https://images.mapillary.com/${keyV.key}/thumb-640.jpg?client_id=${Constants.mapillary_client_token_v3}` - return { - url: url, - provider: this, - key: key - } - } else { - const mapillaryId = keyV.key; - const metadataUrl = 'https://graph.mapillary.com/' + mapillaryId + '?fields=thumb_1024_url&&access_token=' + Constants.mapillary_client_token_v4; - const response = await Utils.downloadJson(metadataUrl) - const url = response["thumb_1024_url"]; - return { - url: url, - provider: this, - key: key - } + const metadataUrl = 'https://graph.mapillary.com/' + mapillaryId + '?fields=thumb_1024_url&&access_token=' + Constants.mapillary_client_token_v4; + const response = await Utils.downloadJson(metadataUrl) + const url = response["thumb_1024_url"]; + return { + url: url, + provider: this, + key: key } } } \ No newline at end of file diff --git a/Models/ThemeConfig/LegacyJsonConvert.ts b/Models/ThemeConfig/LegacyJsonConvert.ts index b30473edc4..5a691e0a29 100644 --- a/Models/ThemeConfig/LegacyJsonConvert.ts +++ b/Models/ThemeConfig/LegacyJsonConvert.ts @@ -32,7 +32,7 @@ export default class LegacyJsonConvert { // This is a legacy format, lets create a pointRendering let location: ("point" | "centroid")[] = ["point"] let wayHandling: number = config["wayHandling"] ?? 0 - if (wayHandling === 2) { + if (wayHandling !== 0) { location = ["point", "centroid"] } config.mapRendering = [