From 73f0ffff5d21703bb1e24ba920d65994e3993100 Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Tue, 10 Dec 2024 02:45:30 +0100 Subject: [PATCH] Fix: fix #2306 by using a cutof of 150m --- .../ImageProviders/ImageUploadManager.ts | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/Logic/ImageProviders/ImageUploadManager.ts b/src/Logic/ImageProviders/ImageUploadManager.ts index aced3e88b..b2b686f80 100644 --- a/src/Logic/ImageProviders/ImageUploadManager.ts +++ b/src/Logic/ImageProviders/ImageUploadManager.ts @@ -85,7 +85,7 @@ export class ImageUploadManager { uploadFinished: this.getCounterFor(this._uploadFinished, featureId), retried: this.getCounterFor(this._uploadRetried, featureId), failed: this.getCounterFor(this._uploadFailed, featureId), - retrySuccess: this.getCounterFor(this._uploadRetriedSuccess, featureId), + retrySuccess: this.getCounterFor(this._uploadRetriedSuccess, featureId) } } @@ -94,7 +94,7 @@ export class ImageUploadManager { if (sizeInBytes > this._uploader.maxFileSizeInMegabytes * 1000000) { const error = Translations.t.image.toBig.Subs({ actual_size: Math.floor(sizeInBytes / 1000000) + "MB", - max_size: this._uploader.maxFileSizeInMegabytes + "MB", + max_size: this._uploader.maxFileSizeInMegabytes + "MB" }) return { error } } @@ -144,7 +144,7 @@ export class ImageUploadManager { properties, { theme: tags?.data?.["_orig_theme"] ?? this._theme.id, - changeType: "add-image", + changeType: "add-image" } ) @@ -168,15 +168,22 @@ export class ImageUploadManager { if (this._gps.data && !ignoreGps) { location = [this._gps.data.longitude, this._gps.data.latitude] } - if (location === undefined || location?.some((l) => l === undefined)) { + { feature ??= this._indexedFeatures.featuresById.data.get(featureId) - if(feature === undefined){ + if (feature === undefined) { throw "ImageUploadManager: no feature given and no feature found in the indexedFeature. Cannot upload this image" } - location = GeoOperations.centerpointCoordinates(feature) + const featureCenterpoint = GeoOperations.centerpointCoordinates(feature) + if (location === undefined || location?.some((l) => l === undefined) || + GeoOperations.distanceBetween(location, featureCenterpoint) > 150) { + /* GPS location is either unknown or very far away from the photographed location. + * Default to the centerpoint + */ + location = featureCenterpoint + } } try { - ;({ key, value, absoluteUrl } = await this._uploader.uploadImage( + ({ key, value, absoluteUrl } = await this._uploader.uploadImage( blob, location, author, @@ -186,7 +193,7 @@ export class ImageUploadManager { this.increaseCountFor(this._uploadRetried, featureId) console.error("Could not upload image, trying again:", e) try { - ;({ key, value, absoluteUrl } = await this._uploader.uploadImage( + ({ key, value, absoluteUrl } = await this._uploader.uploadImage( blob, location, author, @@ -202,7 +209,7 @@ export class ImageUploadManager { ctx: "While uploading an image in the Image Upload Manager", featureId, author, - targetKey, + targetKey }) ) return undefined