From 55cfd65f3bca63dc64c9a60ff6f92e2fa4320038 Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Fri, 27 Sep 2024 03:26:17 +0200 Subject: [PATCH] Feature: add support for panoramax picturs for non-default keys (e.g. image:menu) --- src/Logic/ImageProviders/AllImageProviders.ts | 11 ++++++----- src/Logic/ImageProviders/ImageProvider.ts | 2 +- src/Logic/ImageProviders/ImageUploadManager.ts | 14 +++++++++----- src/Logic/ImageProviders/ImageUploader.ts | 4 +--- src/Logic/ImageProviders/Panoramax.ts | 4 +++- 5 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/Logic/ImageProviders/AllImageProviders.ts b/src/Logic/ImageProviders/AllImageProviders.ts index 4304c0bd9..476571c1e 100644 --- a/src/Logic/ImageProviders/AllImageProviders.ts +++ b/src/Logic/ImageProviders/AllImageProviders.ts @@ -90,13 +90,14 @@ export default class AllImageProviders { this._cache.set(cacheKey, source) const allSources: Store[] = [] for (const imageProvider of AllImageProviders.ImageAttributionSource) { - let prefixes = imageProvider.defaultKeyPrefixes - if (tagKey !== undefined) { - prefixes = tagKey - } + const singleSource = imageProvider.GetRelevantUrls(tags, { - prefixes: prefixes, + /* + By default, 'GetRelevantUrls' uses the defaultKeyPrefixes. + However, we override them if a custom image tag is set, e.g. 'image:menu' + */ + prefixes: tagKey ?? imageProvider.defaultKeyPrefixes, }) allSources.push(singleSource) singleSource.addCallbackAndRunD((_) => { diff --git a/src/Logic/ImageProviders/ImageProvider.ts b/src/Logic/ImageProviders/ImageProvider.ts index 7fe3b7b02..999516ee1 100644 --- a/src/Logic/ImageProviders/ImageProvider.ts +++ b/src/Logic/ImageProviders/ImageProvider.ts @@ -49,7 +49,7 @@ export default abstract class ImageProvider { if(key === "panoramax"){ console.log("Inspecting", key,"against", prefixes) } - if (!prefixes.some((prefix) => key.startsWith(prefix))) { + if (!prefixes.some((prefix) => key === prefix || key.match(new RegExp(prefix+":[0-9]+")))) { continue } const values = Utils.NoEmpty(tags[key]?.split(";")?.map((v) => v.trim()) ?? []) diff --git a/src/Logic/ImageProviders/ImageUploadManager.ts b/src/Logic/ImageProviders/ImageUploadManager.ts index 798008f19..d726e10a2 100644 --- a/src/Logic/ImageProviders/ImageUploadManager.ts +++ b/src/Logic/ImageProviders/ImageUploadManager.ts @@ -62,7 +62,7 @@ export class ImageUploadManager { * Gets various counters. * Note that counters can only increase * If a retry was a success, both 'retrySuccess' _and_ 'uploadFinished' will be increased - * @param featureId: the id of the feature you want information for. '*' has a global counter + * @param featureId the id of the feature you want information for. '*' has a global counter */ public getCountsFor(featureId: string | "*"): { retried: Store @@ -157,13 +157,14 @@ export class ImageUploadManager { const feature = this._indexedFeatures.featuresById.data.get(featureId) location = GeoOperations.centerpointCoordinates(feature) } + let absoluteUrl: string try { - ;({ key, value } = await this._uploader.uploadImage(blob, location, author)) + ;({ key, value, absoluteUrl } = await this._uploader.uploadImage(blob, location, author)) } catch (e) { this.increaseCountFor(this._uploadRetried, featureId) console.error("Could not upload image, trying again:", e) try { - ;({ key, value } = await this._uploader.uploadImage(blob, location, author)) + ;({ key, value , absoluteUrl} = await this._uploader.uploadImage(blob, location, author)) this.increaseCountFor(this._uploadRetriedSuccess, featureId) } catch (e) { console.error("Could again not upload image due to", e) @@ -173,12 +174,15 @@ export class ImageUploadManager { } console.log("Uploading image done, creating action for", featureId) key = targetKey ?? key + if(targetKey){ + // This is a non-standard key, so we use the image link directly + value = absoluteUrl + } this.increaseCountFor(this._uploadFinished, featureId) - const action = new LinkImageAction(featureId, key, value, properties, { + return new LinkImageAction(featureId, key, value, properties, { theme: theme ?? this._layout.id, changeType: "add-image", }) - return action } private getCounterFor(collection: Map>, key: string | "*") { diff --git a/src/Logic/ImageProviders/ImageUploader.ts b/src/Logic/ImageProviders/ImageUploader.ts index fbfb56abc..dc9babe20 100644 --- a/src/Logic/ImageProviders/ImageUploader.ts +++ b/src/Logic/ImageProviders/ImageUploader.ts @@ -1,5 +1,3 @@ -import { Feature } from "geojson" - export interface ImageUploader { maxFileSizeInMegabytes?: number /** @@ -10,5 +8,5 @@ export interface ImageUploader { blob: File, currentGps: [number,number], author: string - ): Promise<{ key: string; value: string }> + ): Promise<{ key: string; value: string, absoluteUrl: string }> } diff --git a/src/Logic/ImageProviders/Panoramax.ts b/src/Logic/ImageProviders/Panoramax.ts index 67e82e0a9..6f8291d0f 100644 --- a/src/Logic/ImageProviders/Panoramax.ts +++ b/src/Logic/ImageProviders/Panoramax.ts @@ -18,7 +18,7 @@ export default class PanoramaxImageProvider extends ImageProvider { public static readonly singleton = new PanoramaxImageProvider() - public defaultKeyPrefixes: string[] = ["panoramax", "image"] + public defaultKeyPrefixes: string[] = ["panoramax"] public readonly name: string = "panoramax" private static knownMeta: Record = {} @@ -128,6 +128,7 @@ export class PanoramaxUploader implements ImageUploader { async uploadImage(blob: File, currentGps: [number, number], author: string): Promise<{ key: string; value: string; + absoluteUrl: string }> { const tags = await ExifReader.load(blob) @@ -152,6 +153,7 @@ export class PanoramaxUploader implements ImageUploader { return { key: "panoramax", value: img.id, + absoluteUrl: img.assets.hd.href } }