chore: automated housekeeping...

This commit is contained in:
Pieter Vander Vennet 2025-04-15 18:18:44 +02:00
parent 79b6927b56
commit 42ded4c1b1
328 changed files with 4062 additions and 1284 deletions

View file

@ -36,12 +36,16 @@ export class ImageUploadManager {
* Keeps track of the _features_ for which an upload failed. Only used to give an indication to the user.
* Every time an image upload fails, the featureID is added to the list. Not persisted (and should not be)
*/
private readonly _fails: UIEventSource<ImageUploadArguments[]> = new UIEventSource<ImageUploadArguments[]>([])
public readonly fails: Store<string[]> = this._fails.map(args => args.map(a => a.featureId))
private readonly _fails: UIEventSource<ImageUploadArguments[]> = new UIEventSource<
ImageUploadArguments[]
>([])
public readonly fails: Store<string[]> = this._fails.map((args) => args.map((a) => a.featureId))
/**
* FeatureIDs of queued items
*/
public readonly queued: Store<string[]> = this._queue.imagesInQueue.map(queue => queue.map(q => q.featureId))
public readonly queued: Store<string[]> = this._queue.imagesInQueue.map((queue) =>
queue.map((q) => q.featureId)
)
public readonly queuedArgs = this._queue.imagesInQueue
/**
* The feature for which an upload is currently running
@ -79,7 +83,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 }
}
@ -118,7 +122,6 @@ export class ImageUploadManager {
const tags: OsmTags = tagsStore.data
const featureId = <OsmId | NoteId>tags.id
const author = this._osmConnection?.userDetails?.data?.name ?? "Anonymous" // Might be a note upload
/**
@ -134,13 +137,16 @@ export class ImageUploadManager {
location,
date: new Date().getTime(),
layoutId: this._theme.id,
author, blob: file, featureId, noblur, targetKey
author,
blob: file,
featureId,
noblur,
targetKey,
}
console.log("Args are", args)
this._queue.add(args)
this.uploadQueue()
}
/**
@ -201,23 +207,29 @@ export class ImageUploadManager {
this._fails.ping()
return
}
this._fails.set(this._fails.data.filter(a => a !== args))
let properties: UIEventSource<Record<string, string>> = this._featureProperties.getStore(args.featureId)
this._fails.set(this._fails.data.filter((a) => a !== args))
let properties: UIEventSource<Record<string, string>> = this._featureProperties.getStore(
args.featureId
)
if (args.featureId.startsWith("note/")) {
// This is an OSM-note
const url = result.absoluteUrl
await this._osmConnection.addCommentToNote(args.featureId, url)
const properties: UIEventSource<Record<string, string>> = this._featureProperties.getStore(args.featureId)
const properties: UIEventSource<Record<string, string>> =
this._featureProperties.getStore(args.featureId)
if (properties) {
// Properties will not be defined if the note isn't loaded, but that is no problem as the below code is only relevant if the note is shown
NoteCommentElement.addCommentTo(url, properties, {
osmConnection: this._osmConnection
osmConnection: this._osmConnection,
})
}
} else {
if (properties === undefined) {
const downloaded = await new OsmObjectDownloader(this._osmConnection.Backend(), this._changes).DownloadObjectAsync(args.featureId)
const downloaded = await new OsmObjectDownloader(
this._osmConnection.Backend(),
this._changes
).DownloadObjectAsync(args.featureId)
if (downloaded === "deleted") {
this._queue.delete(args)
return
@ -232,7 +244,7 @@ export class ImageUploadManager {
properties,
{
theme: properties?.data?.["_orig_theme"] ?? this._theme.id,
changeType: "add-image"
changeType: "add-image",
}
)
await this._changes.applyAction(action)
@ -240,7 +252,6 @@ export class ImageUploadManager {
}
this._queue.delete(args)
}
/**
@ -259,23 +270,15 @@ export class ImageUploadManager {
* @private
*/
private async attemptSingleUpload(
{
featureId,
author,
blob,
targetKey,
noblur,
location
}: ImageUploadArguments,
{ featureId, author, blob, targetKey, noblur, location }: ImageUploadArguments,
reportOnFail: boolean
): Promise<UploadResult | undefined> {
let key: string
let value: string
let absoluteUrl: string
try {
({ key, value, absoluteUrl } = await this._uploader.uploadImage(
;({ key, value, absoluteUrl } = await this._uploader.uploadImage(
blob,
location,
author,
@ -284,14 +287,13 @@ export class ImageUploadManager {
} catch (e) {
console.error("Could again not upload image due to", e)
if (reportOnFail) {
await this._reportError(
e,
JSON.stringify({
ctx: "While uploading an image in the Image Upload Manager",
featureId,
author,
targetKey
targetKey,
})
)
}
@ -304,5 +306,4 @@ export class ImageUploadManager {
}
return { key, absoluteUrl, value }
}
}