Drop support for mapillary v3.0, small fix for custom themes

This commit is contained in:
pietervdvn 2021-11-11 17:35:24 +01:00
parent f9c4b7ae6d
commit 3570cfbaa8
2 changed files with 27 additions and 70 deletions

View file

@ -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<LicenseInfo> {
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<ProvidedImage> {
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 = <string>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 = <string>response["thumb_1024_url"];
return {
url: url,
provider: this,
key: key
}
}
}

View file

@ -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 = [