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 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<string[]> = 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<string | undefined> = this._isUploading
private readonly _reportError: (
message: string | Error | XMLHttpRequest,
extramessage?: string
extramessage?: string,
) => Promise<void>
private readonly _progressCurrentImage: UIEventSource<number> = new UIEventSource(0)
@ -70,8 +71,8 @@ export class ImageUploadManager {
gpsLocation: Store<GeolocationCoordinates | undefined>,
reportError: (
message: string | Error | XMLHttpRequest,
extramessage?: string
) => Promise<void>
extramessage?: string,
) => Promise<void>,
) {
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 = <OsmId | NoteId>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<ImageUploadArguments> = 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<Record<string, string>> = 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<UploadResult | undefined> {
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