Fix: image upload did not upload pictures that were added while a picture was uploaded (until a next retry); this is now fixed

This commit is contained in:
Pieter Vander Vennet 2025-07-07 01:06:38 +02:00
parent ca1c9cbac1
commit abf75111b3

View file

@ -14,6 +14,7 @@ import { GeoOperations } from "../GeoOperations"
import NoteCommentElement from "../../UI/Popup/Notes/NoteCommentElement" import NoteCommentElement from "../../UI/Popup/Notes/NoteCommentElement"
import OsmObjectDownloader from "../Osm/OsmObjectDownloader" import OsmObjectDownloader from "../Osm/OsmObjectDownloader"
import ExifReader from "exifreader" import ExifReader from "exifreader"
import { Utils } from "../../Utils"
/** /**
* The ImageUploadManager has a * The ImageUploadManager has a
@ -45,7 +46,7 @@ export class ImageUploadManager {
* FeatureIDs of queued items * FeatureIDs of queued items
*/ */
public readonly queued: Store<string[]> = this._queue.imagesInQueue.map((queue) => public readonly queued: Store<string[]> = this._queue.imagesInQueue.map((queue) =>
queue.map((q) => q.featureId) queue.map((q) => q.featureId),
) )
public readonly queuedArgs = this._queue.imagesInQueue public readonly queuedArgs = this._queue.imagesInQueue
/** /**
@ -55,7 +56,7 @@ export class ImageUploadManager {
public readonly isUploading: Store<string | undefined> = this._isUploading public readonly isUploading: Store<string | undefined> = this._isUploading
private readonly _reportError: ( private readonly _reportError: (
message: string | Error | XMLHttpRequest, message: string | Error | XMLHttpRequest,
extramessage?: string extramessage?: string,
) => Promise<void> ) => Promise<void>
private readonly _progressCurrentImage: UIEventSource<number> = new UIEventSource(0) private readonly _progressCurrentImage: UIEventSource<number> = new UIEventSource(0)
@ -70,8 +71,8 @@ export class ImageUploadManager {
gpsLocation: Store<GeolocationCoordinates | undefined>, gpsLocation: Store<GeolocationCoordinates | undefined>,
reportError: ( reportError: (
message: string | Error | XMLHttpRequest, message: string | Error | XMLHttpRequest,
extramessage?: string extramessage?: string,
) => Promise<void> ) => Promise<void>,
) { ) {
this._uploader = uploader this._uploader = uploader
this._featureProperties = featureProperties this._featureProperties = featureProperties
@ -131,7 +132,7 @@ export class ImageUploadManager {
feature: Feature, feature: Feature,
options: { options: {
ignoreGPS: boolean | false ignoreGPS: boolean | false
} },
): void { ): void {
const tags: OsmTags = tagsStore.data const tags: OsmTags = tagsStore.data
const featureId = <OsmId | NoteId>tags.id const featureId = <OsmId | NoteId>tags.id
@ -170,27 +171,24 @@ export class ImageUploadManager {
if (this.uploadingAll) { if (this.uploadingAll) {
return 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 { try {
queue = [...queue] let queue: ImageUploadArguments[]
while (queue.length > 0) { const failed: Set<ImageUploadArguments> = new Set()
const currentItem = queue.shift() this.uploadingAll = true
if (!currentItem) { do {
continue 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) } while (queue.length > 0)
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
}
}
} catch (e) { } catch (e) {
console.error("Error while handling the queue:", e) console.error("Error while handling the queue:", e)
await this._reportError("Image Upload Manager: queue stopped working:", e) await this._reportError("Image Upload Manager: queue stopped working:", e)
@ -235,7 +233,7 @@ export class ImageUploadManager {
return false return false
} }
let properties: UIEventSource<Record<string, string>> = this._featureProperties.getStore( let properties: UIEventSource<Record<string, string>> = this._featureProperties.getStore(
args.featureId args.featureId,
) )
if (!isNaN(Number(args.featureId))) { if (!isNaN(Number(args.featureId))) {
@ -255,7 +253,7 @@ export class ImageUploadManager {
if (properties === undefined) { if (properties === undefined) {
const downloaded = await new OsmObjectDownloader( const downloaded = await new OsmObjectDownloader(
this._osmConnection.Backend(), this._osmConnection.Backend(),
this._changes this._changes,
).DownloadObjectAsync(args.featureId) ).DownloadObjectAsync(args.featureId)
if (downloaded === "deleted") { if (downloaded === "deleted") {
this._queue.delete(args) this._queue.delete(args)
@ -290,7 +288,7 @@ export class ImageUploadManager {
*/ */
private async attemptSingleUpload( private async attemptSingleUpload(
{ featureId, author, blob, targetKey, noblur, location }: ImageUploadArguments, { featureId, author, blob, targetKey, noblur, location }: ImageUploadArguments,
reportOnFail: boolean reportOnFail: boolean,
): Promise<UploadResult | undefined> { ): Promise<UploadResult | undefined> {
let key: string let key: string
let value: string let value: string
@ -302,7 +300,7 @@ export class ImageUploadManager {
location, location,
author, author,
noblur, noblur,
this._progressCurrentImage this._progressCurrentImage,
)) ))
} catch (e) { } catch (e) {
console.error("Could again not upload image due to", e) console.error("Could again not upload image due to", e)
@ -314,7 +312,7 @@ export class ImageUploadManager {
featureId, featureId,
author, author,
targetKey, targetKey,
}) }),
) )
} }
return undefined return undefined