Fix: fixes to etymology: load wikidata on mobile (which uses m.wikidata.org, tripping the CSP); fix 'upload image of the streetsign' parameters

This commit is contained in:
Pieter Vander Vennet 2023-10-22 00:51:43 +02:00
parent bc37deafb5
commit 480956d45d
6 changed files with 15 additions and 7 deletions

View file

@ -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",

View file

@ -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<OsmTags>): Promise<void> {
public async uploadImageAndApply(file: File, tagsStore: UIEventSource<OsmTags>, targetKey?: string): Promise<void> {
const sizeInBytes = file.size
const tags = tagsStore.data
const featureId = <OsmId>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<LinkImageAction> {
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",

View file

@ -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 = [

View file

@ -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

View file

@ -17,6 +17,7 @@
export let state: SpecialVisualizationState
export let tags: Store<OsmTags>
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)
}

View file

@ -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],
})
},
},