From ce363dfb59c3237e20aed87ab51da42b9652cb01 Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Sat, 28 Sep 2024 02:44:03 +0200 Subject: [PATCH 1/3] Fix: note themes uses full URL now instead of Panoramax-id --- .../ImageProviders/ImageUploadManager.ts | 41 ++++++++----------- src/Logic/ImageProviders/ImageUploader.ts | 4 +- src/UI/Image/UploadImage.svelte | 23 +++++++++-- src/UI/SpecialVisualizations.ts | 5 +-- 4 files changed, 41 insertions(+), 32 deletions(-) diff --git a/src/Logic/ImageProviders/ImageUploadManager.ts b/src/Logic/ImageProviders/ImageUploadManager.ts index d726e10a2..c90e2ab07 100644 --- a/src/Logic/ImageProviders/ImageUploadManager.ts +++ b/src/Logic/ImageProviders/ImageUploadManager.ts @@ -1,4 +1,4 @@ -import { ImageUploader } from "./ImageUploader" +import { ImageUploader, UploadResult } from "./ImageUploader" import LinkImageAction from "../Osm/Actions/LinkImageAction" import FeaturePropertiesStore from "../FeatureSource/Actors/FeaturePropertiesStore" import { OsmId, OsmTags } from "../../Models/OsmFeature" @@ -111,44 +111,40 @@ export class ImageUploadManager { } const tags = tagsStore.data + const featureId = tags.id const author = this._osmConnection.userDetails.data.name - const action = await this.uploadImageWithLicense( + const uploadResult = await this.uploadImageWithLicense( featureId, author, file, targetKey, - tags?.data?.["_orig_theme"], ) + if (!uploadResult) { + return + } + const properties = this._featureProperties.getStore(featureId) + + const action = new LinkImageAction(featureId, uploadResult. key, uploadResult . value, properties, { + theme: tags?.data?.["_orig_theme"] ?? this._layout.id, + changeType: "add-image", + }) - if (!action) { - return - } - if (!isNaN(Number(featureId))) { - // This is a map note - const url = action._url - await this._osmConnection.addCommentToNote(featureId, url) - NoteCommentElement.addCommentTo(url, >tagsStore, { - osmConnection: this._osmConnection, - }) - return - } await this._changes.applyAction(action) } - private async uploadImageWithLicense( + public async uploadImageWithLicense( featureId: OsmId, author: string, blob: File, targetKey: string | undefined, - theme?: string, - ): Promise { + ): Promise { this.increaseCountFor(this._uploadStarted, featureId) - const properties = this._featureProperties.getStore(featureId) let key: string let value: string + let absoluteUrl: string let location: [number, number] = undefined if (this._gps.data) { location = [this._gps.data.longitude, this._gps.data.latitude] @@ -157,7 +153,6 @@ export class ImageUploadManager { const feature = this._indexedFeatures.featuresById.data.get(featureId) location = GeoOperations.centerpointCoordinates(feature) } - let absoluteUrl: string try { ;({ key, value, absoluteUrl } = await this._uploader.uploadImage(blob, location, author)) } catch (e) { @@ -179,10 +174,8 @@ export class ImageUploadManager { value = absoluteUrl } this.increaseCountFor(this._uploadFinished, featureId) - return new LinkImageAction(featureId, key, value, properties, { - theme: theme ?? this._layout.id, - changeType: "add-image", - }) + return {key, absoluteUrl, value} + } private getCounterFor(collection: Map>, key: string | "*") { diff --git a/src/Logic/ImageProviders/ImageUploader.ts b/src/Logic/ImageProviders/ImageUploader.ts index dc9babe20..bd49baa48 100644 --- a/src/Logic/ImageProviders/ImageUploader.ts +++ b/src/Logic/ImageProviders/ImageUploader.ts @@ -8,5 +8,7 @@ export interface ImageUploader { blob: File, currentGps: [number,number], author: string - ): Promise<{ key: string; value: string, absoluteUrl: string }> + ): Promise } + +export interface UploadResult{ key: string; value: string, absoluteUrl: string } diff --git a/src/UI/Image/UploadImage.svelte b/src/UI/Image/UploadImage.svelte index ab74d4b52..2b0f97c8a 100644 --- a/src/UI/Image/UploadImage.svelte +++ b/src/UI/Image/UploadImage.svelte @@ -14,11 +14,14 @@ import LoginButton from "../Base/LoginButton.svelte" import { Translation } from "../i18n/Translation" import Camera from "@babeard/svelte-heroicons/solid/Camera" + import LayerConfig from "../../Models/ThemeConfig/LayerConfig" + import NoteCommentElement from "../Popup/Notes/NoteCommentElement" export let state: SpecialVisualizationState export let tags: UIEventSource export let targetKey: string = undefined + export let layer: LayerConfig /** * Image to show in the button * NOT the image to upload! @@ -30,11 +33,9 @@ export let labelText: string = undefined const t = Translations.t.image - let licenseStore = state?.userRelatedState?.imageLicense ?? new ImmutableStore("CC0") - let errors = new UIEventSource([]) - function handleFiles(files: FileList) { + async function handleFiles(files: FileList) { const errs = [] for (let i = 0; i < files.length; i++) { const file = files.item(i) @@ -45,7 +46,21 @@ errs.push(canBeUploaded.error) continue } - state?.imageUploadManager.uploadImageAndApply(file, tags, targetKey) + + if(layer.id === "note"){ + const uploadResult = await state?.imageUploadManager.uploadImageWithLicense(file, tags, targetKey) + if(!uploadResult){ + return + } + const url = uploadResult.absoluteUrl + await this._osmConnection.addCommentToNote(tags.data.id, url) + NoteCommentElement.addCommentTo(url, >tags, { + osmConnection: this._osmConnection, + }) + return + } + + await state?.imageUploadManager.uploadImageAndApply(file, tags, targetKey) } catch (e) { alert(e) } diff --git a/src/UI/SpecialVisualizations.ts b/src/UI/SpecialVisualizations.ts index cc5a88691..0f595186b 100644 --- a/src/UI/SpecialVisualizations.ts +++ b/src/UI/SpecialVisualizations.ts @@ -1100,11 +1100,10 @@ export default class SpecialVisualizations { ], needsUrls: [Imgur.apiUrl, ...Imgur.supportingUrls], - constr: (state, tags, args) => { + constr: (state, tags, args, feature, layer) => { const id = tags.data[args[0] ?? "id"] tags = state.featureProperties.getStore(id) - console.log("Id is", id) - return new SvelteUIElement(UploadImage, { state, tags }) + return new SvelteUIElement(UploadImage, { state, tags, layer }) }, }, { From ba1eb28f274ac6cc6be4614456ca3d2137d9ba64 Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Sat, 28 Sep 2024 12:01:10 +0200 Subject: [PATCH 2/3] Fix: quickfixes to image upload flow --- src/Logic/ImageProviders/ImageUploadManager.ts | 3 +-- src/UI/Image/UploadImage.svelte | 15 +++++++++------ src/UI/SpecialVisualization.ts | 3 ++- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/Logic/ImageProviders/ImageUploadManager.ts b/src/Logic/ImageProviders/ImageUploadManager.ts index c90e2ab07..0363f3b21 100644 --- a/src/Logic/ImageProviders/ImageUploadManager.ts +++ b/src/Logic/ImageProviders/ImageUploadManager.ts @@ -7,7 +7,6 @@ import { Store, UIEventSource } from "../UIEventSource" import { OsmConnection } from "../Osm/OsmConnection" import { Changes } from "../Osm/Changes" import Translations from "../../UI/i18n/Translations" -import NoteCommentElement from "../../UI/Popup/Notes/NoteCommentElement" import { Translation } from "../../UI/i18n/Translation" import { IndexedFeatureSource } from "../FeatureSource/FeatureSource" import { GeoOperations } from "../GeoOperations" @@ -136,7 +135,7 @@ export class ImageUploadManager { } public async uploadImageWithLicense( - featureId: OsmId, + featureId: string, author: string, blob: File, targetKey: string | undefined, diff --git a/src/UI/Image/UploadImage.svelte b/src/UI/Image/UploadImage.svelte index 2b0f97c8a..4495f025b 100644 --- a/src/UI/Image/UploadImage.svelte +++ b/src/UI/Image/UploadImage.svelte @@ -5,7 +5,7 @@ import type { SpecialVisualizationState } from "../SpecialVisualization" import { ImmutableStore, UIEventSource } from "../../Logic/UIEventSource" - import type { OsmTags } from "../../Models/OsmFeature" + import type { OsmId, OsmTags } from "../../Models/OsmFeature" import LoginToggle from "../Base/LoginToggle.svelte" import Translations from "../i18n/Translations" import Tr from "../Base/Tr.svelte" @@ -47,22 +47,25 @@ continue } - if(layer.id === "note"){ - const uploadResult = await state?.imageUploadManager.uploadImageWithLicense(file, tags, targetKey) + if(layer?.id === "note"){ + const uploadResult = await state?.imageUploadManager.uploadImageWithLicense(tags.data.id, + state.osmConnection.userDetails.data?.name ?? "Anonymous", + file, "image") if(!uploadResult){ return } const url = uploadResult.absoluteUrl - await this._osmConnection.addCommentToNote(tags.data.id, url) + await state.osmConnection.addCommentToNote(tags.data.id, url) NoteCommentElement.addCommentTo(url, >tags, { - osmConnection: this._osmConnection, + osmConnection: state.osmConnection, }) return } await state?.imageUploadManager.uploadImageAndApply(file, tags, targetKey) } catch (e) { - alert(e) + console.error(e) + state.reportError(e, "Could not upload image") } } errors.setData(errs) diff --git a/src/UI/SpecialVisualization.ts b/src/UI/SpecialVisualization.ts index 37aa7229e..a28689027 100644 --- a/src/UI/SpecialVisualization.ts +++ b/src/UI/SpecialVisualization.ts @@ -88,7 +88,8 @@ export interface SpecialVisualizationState { readonly geocodedImages : UIEventSource showCurrentLocationOn(map: Store): ShowDataLayer - reportError(message: string): Promise + reportError(message: string | Error | XMLHttpRequest, extramessage?: string): Promise + } export interface SpecialVisualization { From feee0aee580eb05a8eb79ab8a974c2aaac86ec76 Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Sat, 28 Sep 2024 12:01:15 +0200 Subject: [PATCH 3/3] chore(release): 0.46.11 --- CHANGELOG.md | 14 ++++++++++++++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a319cdb35..e5099f6d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,20 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +### [0.46.11](https://github.com/USERNAME/REPOSITORY_NAME/compare/v0.46.10...v0.46.11) (2024-09-28) + + +### Features + +* check if the image was blurred, attempt to reload if it is done; refactoring of ImageProvider code ([4650170](https://github.com/USERNAME/REPOSITORY_NAME/commits4650170db4bdd3b9e4fbd1900147a7433652dd6f)) + + +### Bug Fixes + +* fix tests with some refactoring ([0b992e7](https://github.com/USERNAME/REPOSITORY_NAME/commits0b992e75a481ffa5156f68d9a9fa3495a1fec4c9)) +* note themes uses full URL now instead of Panoramax-id ([ce363df](https://github.com/USERNAME/REPOSITORY_NAME/commitsce363dfb59c3237e20aed87ab51da42b9652cb01)) +* quickfixes to image upload flow ([ba1eb28](https://github.com/USERNAME/REPOSITORY_NAME/commitsba1eb28f274ac6cc6be4614456ca3d2137d9ba64)) + ### [0.46.10](https://github.com/USERNAME/REPOSITORY_NAME/compare/v0.46.9...v0.46.10) (2024-09-26) diff --git a/package-lock.json b/package-lock.json index b98b93d1f..62850a967 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "mapcomplete", - "version": "0.46.10", + "version": "0.46.11", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "mapcomplete", - "version": "0.46.10", + "version": "0.46.11", "license": "GPL-3.0-or-later", "dependencies": { "@comunica/core": "^3.0.1", diff --git a/package.json b/package.json index 457371e9e..451e73084 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mapcomplete", - "version": "0.46.10", + "version": "0.46.11", "repository": "https://github.com/pietervdvn/MapComplete", "description": "A small website to edit OSM easily", "bugs": "https://github.com/pietervdvn/MapComplete/issues",