chore: automated housekeeping...

This commit is contained in:
Pieter Vander Vennet 2024-09-02 12:48:15 +02:00
parent c10fecb7e8
commit f5d7686c98
234 changed files with 3493 additions and 2482 deletions

View file

@ -21,8 +21,11 @@ export type ChangesetMetadata = {
uid: number
user: string
changes_count: number
tags: Record<string, string>,
minlat: number, minlon: number, maxlat: number, maxlon: number
tags: Record<string, string>
minlat: number
minlon: number
maxlat: number
maxlon: number
comments_count: number
}
@ -49,7 +52,7 @@ export class ChangesetHandler {
| { addAlias: (id0: string, id1: string) => void }
| undefined,
changes: Changes,
reportError: (e: string | Error, extramessage: string) => void,
reportError: (e: string | Error, extramessage: string) => void
) {
this.osmConnection = osmConnection
this._reportError = reportError
@ -107,27 +110,27 @@ export class ChangesetHandler {
return hasChange
}
private async UploadWithNew(generateChangeXML: (csid: number, remappings: Map<string, string>) => string, openChangeset: UIEventSource<number>, extraMetaTags: ChangesetTag[]) {
private async UploadWithNew(
generateChangeXML: (csid: number, remappings: Map<string, string>) => string,
openChangeset: UIEventSource<number>,
extraMetaTags: ChangesetTag[]
) {
const csId = await this.OpenChangeset(extraMetaTags)
openChangeset.setData(csId)
const changeset = generateChangeXML(csId, this._remappings)
console.log(
"Opened a new changeset (openChangeset.data is undefined):",
changeset,
extraMetaTags,
extraMetaTags
)
const changes = await this.UploadChange(csId, changeset)
const hasSpecialMotivationChanges = ChangesetHandler.rewriteMetaTags(
extraMetaTags,
changes,
)
const hasSpecialMotivationChanges = ChangesetHandler.rewriteMetaTags(extraMetaTags, changes)
if (hasSpecialMotivationChanges) {
// At this point, 'extraMetaTags' will have changed - we need to set the tags again
await this.UpdateTags(csId, extraMetaTags)
}
}
/**
* The full logic to upload a change to one or more elements.
*
@ -141,7 +144,7 @@ export class ChangesetHandler {
public async UploadChangeset(
generateChangeXML: (csid: number, remappings: Map<string, string>) => string,
extraMetaTags: ChangesetTag[],
openChangeset: UIEventSource<number>,
openChangeset: UIEventSource<number>
): Promise<void> {
if (
!extraMetaTags.some((tag) => tag.key === "comment") ||
@ -174,30 +177,30 @@ export class ChangesetHandler {
// We can hopefully reuse the changeset
try {
const rewritings = await this.UploadChange(
csId,
generateChangeXML(csId, this._remappings),
generateChangeXML(csId, this._remappings)
)
const rewrittenTags = this.RewriteTagsOf(
extraMetaTags,
rewritings,
oldChangesetMeta,
oldChangesetMeta
)
await this.UpdateTags(csId, rewrittenTags)
return // We are done!
} catch (e) {
this._reportError(e, "While reusing a changeset " + openChangeset.data)
}
}
} catch (e) {
this._reportError(e, "While getting metadata from a changeset " + openChangeset.data)
this._reportError(
e,
"While getting metadata from a changeset " + openChangeset.data
)
}
}
// We have to open a new changeset
try {
return await this.UploadWithNew(generateChangeXML, openChangeset, extraMetaTags)
@ -212,7 +215,7 @@ export class ChangesetHandler {
console.warn(
"Could not open/upload changeset due to ",
e,
"trying again with a another fresh changeset ",
"trying again with a another fresh changeset "
)
openChangeset.setData(undefined)
@ -238,7 +241,7 @@ export class ChangesetHandler {
uid: number // User ID
changes_count: number
tags: any
},
}
): ChangesetTag[] {
// Note: extraMetaTags is where all the tags are collected into
@ -375,7 +378,7 @@ export class ChangesetHandler {
tag.key !== undefined &&
tag.value !== undefined &&
tag.key !== "" &&
tag.value !== "",
tag.value !== ""
)
const metadata = tags.map((kv) => `<tag k="${kv.key}" v="${escapeHtml(kv.value)}"/>`)
const content = [`<osm><changeset>`, metadata, `</changeset></osm>`].join("")
@ -415,7 +418,7 @@ export class ChangesetHandler {
const csId = await this.osmConnection.put(
"changeset/create",
[`<osm><changeset>`, metadata, `</changeset></osm>`].join(""),
{ "Content-Type": "text/xml" },
{ "Content-Type": "text/xml" }
)
return Number(csId)
}
@ -425,12 +428,12 @@ export class ChangesetHandler {
*/
private async UploadChange(
changesetId: number,
changesetXML: string,
changesetXML: string
): Promise<Map<string, string>> {
const response = await this.osmConnection.post<XMLDocument>(
"changeset/" + changesetId + "/upload",
changesetXML,
{ "Content-Type": "text/xml" },
{ "Content-Type": "text/xml" }
)
const changes = this.parseUploadChangesetResponse(response)
console.log("Uploaded changeset ", changesetId)