From 480956d45dc767c77848ba32b176af373e73060a Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Sun, 22 Oct 2023 00:51:43 +0200 Subject: [PATCH] Fix: fixes to etymology: load wikidata on mobile (which uses m.wikidata.org, tripping the CSP); fix 'upload image of the streetsign' parameters --- package.json | 2 +- src/Logic/ImageProviders/ImageUploadManager.ts | 11 ++++++++--- src/Logic/Web/Wikidata.ts | 1 + src/UI/BigComponents/ThemeIntroPanel.svelte | 2 +- src/UI/Image/UploadImage.svelte | 3 ++- src/UI/SpecialVisualizations.ts | 3 ++- 6 files changed, 15 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 4376061cbd..9877e15575 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mapcomplete", - "version": "0.33.10", + "version": "0.33.11", "repository": "https://github.com/pietervdvn/MapComplete", "description": "A small website to edit OSM easily", "bugs": "https://github.com/pietervdvn/MapComplete/issues", diff --git a/src/Logic/ImageProviders/ImageUploadManager.ts b/src/Logic/ImageProviders/ImageUploadManager.ts index ca0487d9b7..732c281097 100644 --- a/src/Logic/ImageProviders/ImageUploadManager.ts +++ b/src/Logic/ImageProviders/ImageUploadManager.ts @@ -64,8 +64,11 @@ export class ImageUploadManager { /** * Uploads the given image, applies the correct title and license for the known user. * Will then add this image to the OSM-feature or the OSM-note + * @param file a jpg file to upload + * @param tagsStore The tags of the feature + * @param targetKey Use this key to save the attribute under. Default: 'image' */ - public async uploadImageAndApply(file: File, tagsStore: UIEventSource): Promise { + public async uploadImageAndApply(file: File, tagsStore: UIEventSource, targetKey?: string): Promise { const sizeInBytes = file.size const tags = tagsStore.data const featureId = tags.id @@ -95,7 +98,7 @@ export class ImageUploadManager { ].join("\n") console.log("Upload done, creating ") - const action = await this.uploadImageWithLicense(featureId, title, description, file) + const action = await this.uploadImageWithLicense(featureId, title, description, file, targetKey) if (!isNaN(Number(featureId))) { // This is a map note const url = action._url @@ -112,7 +115,8 @@ export class ImageUploadManager { featureId: OsmId, title: string, description: string, - blob: File + blob: File, + targetKey: string | undefined ): Promise { this.increaseCountFor(this._uploadStarted, featureId) const properties = this._featureProperties.getStore(featureId) @@ -132,6 +136,7 @@ export class ImageUploadManager { } } console.log("Uploading done, creating action for", featureId) + key = targetKey ?? key const action = new LinkImageAction(featureId, key, value, properties, { theme: this._layout.id, changeType: "add-image", diff --git a/src/Logic/Web/Wikidata.ts b/src/Logic/Web/Wikidata.ts index 1f60f32ecb..7a2f68ddef 100644 --- a/src/Logic/Web/Wikidata.ts +++ b/src/Logic/Web/Wikidata.ts @@ -127,6 +127,7 @@ export default class Wikidata { "https://www.wikidata.org/", "https://wikidata.org/", "https://query.wikidata.org", + "https://m.wikidata.org", // Important: a mobile browser will request m.wikidata.org instead of www.wikidata.org ; this URL needs to be listed for the CSP ] private static readonly _identifierPrefixes = ["Q", "L"].map((str) => str.toLowerCase()) private static readonly _prefixesToRemove = [ diff --git a/src/UI/BigComponents/ThemeIntroPanel.svelte b/src/UI/BigComponents/ThemeIntroPanel.svelte index 2a419b928b..370d737916 100644 --- a/src/UI/BigComponents/ThemeIntroPanel.svelte +++ b/src/UI/BigComponents/ThemeIntroPanel.svelte @@ -14,7 +14,7 @@ import { GeoLocationState } from "../../Logic/State/GeoLocationState" import If from "../Base/If.svelte" import { ExclamationTriangleIcon } from "@babeard/svelte-heroicons/mini" - import { Readable } from "svelte/store" + import type { Readable } from "svelte/store" /** * The theme introduction panel diff --git a/src/UI/Image/UploadImage.svelte b/src/UI/Image/UploadImage.svelte index cac0f38ad9..4f26ba307c 100644 --- a/src/UI/Image/UploadImage.svelte +++ b/src/UI/Image/UploadImage.svelte @@ -17,6 +17,7 @@ export let state: SpecialVisualizationState export let tags: Store + export let targetKey: string = undefined /** * Image to show in the button * NOT the image to upload! @@ -35,7 +36,7 @@ const file = files.item(i) console.log("Got file", file.name) try { - state.imageUploadManager.uploadImageAndApply(file, tags) + state.imageUploadManager.uploadImageAndApply(file, tags, targetKey) } catch (e) { alert(e) } diff --git a/src/UI/SpecialVisualizations.ts b/src/UI/SpecialVisualizations.ts index 8300cb8878..ce917c6851 100644 --- a/src/UI/SpecialVisualizations.ts +++ b/src/UI/SpecialVisualizations.ts @@ -691,8 +691,9 @@ export default class SpecialVisualizations { return new SvelteUIElement(UploadImage, { state, tags, + targetKey: args[0], labelText: args[1], - image: args[0], + image: args[2], }) }, },