From abf75111b36b6ae81037da7617dba7556dfa1d9c Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Mon, 7 Jul 2025 01:06:38 +0200 Subject: [PATCH] Fix: image upload did not upload pictures that were added while a picture was uploaded (until a next retry); this is now fixed --- .../ImageProviders/ImageUploadManager.ts | 56 +++++++++---------- 1 file changed, 27 insertions(+), 29 deletions(-) diff --git a/src/Logic/ImageProviders/ImageUploadManager.ts b/src/Logic/ImageProviders/ImageUploadManager.ts index 4e3345e31..62ffb3612 100644 --- a/src/Logic/ImageProviders/ImageUploadManager.ts +++ b/src/Logic/ImageProviders/ImageUploadManager.ts @@ -14,6 +14,7 @@ import { GeoOperations } from "../GeoOperations" import NoteCommentElement from "../../UI/Popup/Notes/NoteCommentElement" import OsmObjectDownloader from "../Osm/OsmObjectDownloader" import ExifReader from "exifreader" +import { Utils } from "../../Utils" /** * The ImageUploadManager has a @@ -45,7 +46,7 @@ export class ImageUploadManager { * FeatureIDs of queued items */ public readonly queued: Store = this._queue.imagesInQueue.map((queue) => - queue.map((q) => q.featureId) + queue.map((q) => q.featureId), ) public readonly queuedArgs = this._queue.imagesInQueue /** @@ -55,7 +56,7 @@ export class ImageUploadManager { public readonly isUploading: Store = this._isUploading private readonly _reportError: ( message: string | Error | XMLHttpRequest, - extramessage?: string + extramessage?: string, ) => Promise private readonly _progressCurrentImage: UIEventSource = new UIEventSource(0) @@ -70,8 +71,8 @@ export class ImageUploadManager { gpsLocation: Store, reportError: ( message: string | Error | XMLHttpRequest, - extramessage?: string - ) => Promise + extramessage?: string, + ) => Promise, ) { this._uploader = uploader this._featureProperties = featureProperties @@ -131,7 +132,7 @@ export class ImageUploadManager { feature: Feature, options: { ignoreGPS: boolean | false - } + }, ): void { const tags: OsmTags = tagsStore.data const featureId = tags.id @@ -170,27 +171,24 @@ export class ImageUploadManager { if (this.uploadingAll) { return } - let queue = this._queue.imagesInQueue.data ?? [] - if (queue.length === 0) { - return - } - console.log("Checking image upload queue and uploading if needed") - this.uploadingAll = true try { - queue = [...queue] - while (queue.length > 0) { - const currentItem = queue.shift() - if (!currentItem) { - continue + let queue: ImageUploadArguments[] + const failed: Set = new Set() + this.uploadingAll = true + do { + queue = Utils.NoNull(this._queue.imagesInQueue.data ?? []) + .filter(item => !failed.has(item)) + + console.log("Checking image upload queue and uploading if needed") + for (const currentItem of queue) { + const uploadOk = await this.handleQueueItem(currentItem) + if (uploadOk) { + this._queue.delete(currentItem) + } else { + failed.add(currentItem) + } } - const uploadOk = await this.handleQueueItem(currentItem) - if (uploadOk) { - this._queue.delete(currentItem) - } else { - // Our local 'queue' is a copy where we've removed the failed item from - // A next attempt to 'uploadQueue' will retry the upload - } - } + } while (queue.length > 0) } catch (e) { console.error("Error while handling the queue:", e) await this._reportError("Image Upload Manager: queue stopped working:", e) @@ -235,7 +233,7 @@ export class ImageUploadManager { return false } let properties: UIEventSource> = this._featureProperties.getStore( - args.featureId + args.featureId, ) if (!isNaN(Number(args.featureId))) { @@ -255,7 +253,7 @@ export class ImageUploadManager { if (properties === undefined) { const downloaded = await new OsmObjectDownloader( this._osmConnection.Backend(), - this._changes + this._changes, ).DownloadObjectAsync(args.featureId) if (downloaded === "deleted") { this._queue.delete(args) @@ -290,7 +288,7 @@ export class ImageUploadManager { */ private async attemptSingleUpload( { featureId, author, blob, targetKey, noblur, location }: ImageUploadArguments, - reportOnFail: boolean + reportOnFail: boolean, ): Promise { let key: string let value: string @@ -302,7 +300,7 @@ export class ImageUploadManager { location, author, noblur, - this._progressCurrentImage + this._progressCurrentImage, )) } catch (e) { console.error("Could again not upload image due to", e) @@ -314,7 +312,7 @@ export class ImageUploadManager { featureId, author, targetKey, - }) + }), ) } return undefined