From 8fccf784786074e22a4d437dc8a38c58bf54c375 Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Thu, 21 Sep 2023 00:25:04 +0200 Subject: [PATCH] Fix: use api.openstreetmap.org on many places, fix #1573 --- package.json | 6 +++--- .../FeatureSource/Sources/OsmFeatureSource.ts | 6 +++--- src/Logic/Osm/Actions/ReplaceGeometryAction.ts | 2 +- src/Logic/Osm/OsmConnection.ts | 6 ++---- src/Logic/Osm/OsmObject.ts | 2 +- src/Logic/Osm/OsmObjectDownloader.ts | 2 +- src/Logic/SimpleMetaTagger.ts | 2 +- src/UI/Popup/NoteCommentElement.ts | 2 +- src/Utils.ts | 3 +++ test/Logic/Actors/Actors.spec.ts | 2 +- .../OSM/Actions/RelationSplitHandler.spec.ts | 12 ++++++------ .../OSM/Actions/ReplaceGeometryAction.spec.ts | 6 +++--- test/Logic/OSM/Actions/SplitAction.spec.ts | 16 ++++++++-------- test/Logic/OSM/OsmObject.spec.ts | 4 ++-- 14 files changed, 36 insertions(+), 35 deletions(-) diff --git a/package.json b/package.json index 0b8d6a20b..540a1434b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mapcomplete", - "version": "0.33.0", + "version": "0.33.1", "repository": "https://github.com/pietervdvn/MapComplete", "description": "A small website to edit OSM easily", "bugs": "https://github.com/pietervdvn/MapComplete/issues", @@ -21,13 +21,13 @@ "#": "This client_id is registered by 'Pieter Vander Vennet' on OSM.org", "oauth_client_id": "sa1ngLJBJ8McmzHElN8NYtIDm5TZTYEYhq3-0snO4Qc", "oauth_secret": "XU_cD5Mvw9VKk9T0t_gO8V7cbRC4Hmw2Tb4Rv0Zmz-U", - "url": "https://www.openstreetmap.org" + "url": "https://api.openstreetmap.org" }, "osm": { "#": "This client-id is registered by 'MapComplete' on osm.org", "oauth_client_id": "K93H1d8ve7p-tVLE1ZwsQ4lAFLQk8INx5vfTLMu5DWk", "oauth_secret": "NBWGhWDrD3QDB35xtVuxv4aExnmIt4FA_WgeLtwxasg", - "url": "https://www.openstreetmap.org" + "url": "https://api.openstreetmap.org" }, "osm-test": { "oauth_client_id": "HwUn6GPxGm1m9WwMarxTglhy6dBTM4YkaV1I9h6pDGU", diff --git a/src/Logic/FeatureSource/Sources/OsmFeatureSource.ts b/src/Logic/FeatureSource/Sources/OsmFeatureSource.ts index 3890ce14f..e884b1799 100644 --- a/src/Logic/FeatureSource/Sources/OsmFeatureSource.ts +++ b/src/Logic/FeatureSource/Sources/OsmFeatureSource.ts @@ -20,7 +20,7 @@ export default class OsmFeatureSource extends FeatureSourceMerger { private options: { bounds: Store readonly allowedFeatures: TagsFilter - backend?: "https://openstreetmap.org/" | string + backend?: "https://api.openstreetmap.org/" | string /** * If given: this featureSwitch will not update if the store contains 'false' */ @@ -41,7 +41,7 @@ export default class OsmFeatureSource extends FeatureSourceMerger { constructor(options: { bounds: Store readonly allowedFeatures: TagsFilter - backend?: "https://openstreetmap.org/" | string + backend?: "https://api.openstreetmap.org/" | string /** * If given: this featureSwitch will not update if the store contains 'false' */ @@ -54,7 +54,7 @@ export default class OsmFeatureSource extends FeatureSourceMerger { this._bounds = options.bounds this.allowedTags = options.allowedFeatures this.isActive = options.isActive ?? new ImmutableStore(true) - this._backend = options.backend ?? "https://www.openstreetmap.org" + this._backend = options.backend ?? "https://api.openstreetmap.org" this._bounds.addCallbackAndRunD((bbox) => this.loadData(bbox)) this._patchRelations = options?.patchRelations ?? true } diff --git a/src/Logic/Osm/Actions/ReplaceGeometryAction.ts b/src/Logic/Osm/Actions/ReplaceGeometryAction.ts index 3dd23b73a..07be721fb 100644 --- a/src/Logic/Osm/Actions/ReplaceGeometryAction.ts +++ b/src/Logic/Osm/Actions/ReplaceGeometryAction.ts @@ -215,7 +215,7 @@ export default class ReplaceGeometryAction extends OsmChangeAction implements Pr throw "Invalid ID to conflate: " + this.wayToReplaceId } const url = `${ - this.state.osmConnection?._oauth_config?.url ?? "https://openstreetmap.org" + this.state.osmConnection?._oauth_config?.url ?? "https://api.openstreetmap.org" }/api/0.6/${this.wayToReplaceId}/full` const rawData = await Utils.downloadJsonCached(url, 1000) parsed = OsmObject.ParseObjects(rawData.elements) diff --git a/src/Logic/Osm/OsmConnection.ts b/src/Logic/Osm/OsmConnection.ts index b4b47d68e..b6ddddf0b 100644 --- a/src/Logic/Osm/OsmConnection.ts +++ b/src/Logic/Osm/OsmConnection.ts @@ -85,7 +85,7 @@ export class OsmConnection { this._oauth_config = { oauth_client_id: import.meta.env.VITE_OSM_OAUTH_CLIENT_ID, oauth_secret: import.meta.env.VITE_OSM_OAUTH_SECRET, - url: "https://www.openstreetmap.org", + url: "https://api.openstreetmap.org", } } @@ -179,7 +179,7 @@ export class OsmConnection { /** * The backend host, without path or trailing '/' * - * new OsmConnection().Backend() // => "https://www.openstreetmap.org" + * new OsmConnection().Backend() // => "https://api.openstreetmap.org" */ public Backend(): string { return this._oauth_config.url @@ -365,7 +365,6 @@ export class OsmConnection { ) }) } - const auth = this.auth const content = { lat, lon, text } const response = await this.post("notes.json", JSON.stringify(content), { "Content-Type": "application/json", @@ -414,7 +413,6 @@ export class OsmConnection { '"\r\nContent-Type: application/gpx+xml', } - const auth = this.auth const boundary = "987654" let body = "" diff --git a/src/Logic/Osm/OsmObject.ts b/src/Logic/Osm/OsmObject.ts index 44b809190..f0e0215cd 100644 --- a/src/Logic/Osm/OsmObject.ts +++ b/src/Logic/Osm/OsmObject.ts @@ -5,7 +5,7 @@ import OsmToGeoJson from "osmtogeojson" import { Feature, LineString, Polygon } from "geojson" export abstract class OsmObject { - private static defaultBackend = "https://www.openstreetmap.org/" + private static defaultBackend = "https://api.openstreetmap.org/" protected static backendURL = OsmObject.defaultBackend private static polygonFeatures = OsmObject.constructPolygonFeatures() type: "node" | "way" | "relation" diff --git a/src/Logic/Osm/OsmObjectDownloader.ts b/src/Logic/Osm/OsmObjectDownloader.ts index c6c238eb8..211827577 100644 --- a/src/Logic/Osm/OsmObjectDownloader.ts +++ b/src/Logic/Osm/OsmObjectDownloader.ts @@ -17,7 +17,7 @@ export default class OsmObjectDownloader { private historyCache = new Map>() constructor( - backend: string = "https://www.openstreetmap.org", + backend: string = "https://api.openstreetmap.org", changes?: { readonly pendingChanges: UIEventSource readonly isUploading: Store diff --git a/src/Logic/SimpleMetaTagger.ts b/src/Logic/SimpleMetaTagger.ts index 2d1a8688c..f9f4997ff 100644 --- a/src/Logic/SimpleMetaTagger.ts +++ b/src/Logic/SimpleMetaTagger.ts @@ -219,7 +219,7 @@ class RewriteMetaInfoTags extends SimpleMetaTagger { move("changeset", "_last_edit:changeset") move("timestamp", "_last_edit:timestamp") move("version", "_version_number") - feature.properties._backend = feature.properties._backend ?? "https://openstreetmap.org" + feature.properties._backend = feature.properties._backend ?? "https://api.openstreetmap.org" return movedSomething } } diff --git a/src/UI/Popup/NoteCommentElement.ts b/src/UI/Popup/NoteCommentElement.ts index c72244924..7e03686be 100644 --- a/src/UI/Popup/NoteCommentElement.ts +++ b/src/UI/Popup/NoteCommentElement.ts @@ -41,7 +41,7 @@ export default class NoteCommentElement extends Combine { let userinfo = Stores.FromPromise( Utils.downloadJsonCached( - "https://www.openstreetmap.org/api/0.6/user/" + comment.uid, + "https://api.openstreetmap.org/api/0.6/user/" + comment.uid, 24 * 60 * 60 * 1000 ) ) diff --git a/src/Utils.ts b/src/Utils.ts index cc09e8597..290c66bb2 100644 --- a/src/Utils.ts +++ b/src/Utils.ts @@ -27,6 +27,9 @@ Note that these values can be prepare with javascript in the theme by using a [c public static readonly imageExtensions = new Set(["jpg", "png", "svg", "jpeg", ".gif"]) public static initDomPurify() { + if (Utils.runningFromConsole) { + return + } DOMPurify.addHook("afterSanitizeAttributes", function (node) { // set all elements owning target to target=_blank + add noopener noreferrer if ("target" in node) { diff --git a/test/Logic/Actors/Actors.spec.ts b/test/Logic/Actors/Actors.spec.ts index ef31ee319..751964722 100644 --- a/test/Logic/Actors/Actors.spec.ts +++ b/test/Logic/Actors/Actors.spec.ts @@ -21,7 +21,7 @@ const latestTags = { "public_bookcase:type": "reading_box", } -Utils.injectJsonDownloadForTests("https://www.openstreetmap.org/api/0.6/node/5568693115", { +Utils.injectJsonDownloadForTests("https://api.openstreetmap.org/api/0.6/node/5568693115", { version: "0.6", generator: "CGImap 0.8.5 (1815943 spike-06.openstreetmap.org)", copyright: "OpenStreetMap and contributors", diff --git a/test/Logic/OSM/Actions/RelationSplitHandler.spec.ts b/test/Logic/OSM/Actions/RelationSplitHandler.spec.ts index fa90eafd3..8b3dede8b 100644 --- a/test/Logic/OSM/Actions/RelationSplitHandler.spec.ts +++ b/test/Logic/OSM/Actions/RelationSplitHandler.spec.ts @@ -11,7 +11,7 @@ import { ImmutableStore } from "../../../../src/Logic/UIEventSource" import { OsmConnection } from "../../../../src/Logic/Osm/OsmConnection" describe("RelationSplitHandler", () => { - Utils.injectJsonDownloadForTests("https://www.openstreetmap.org/api/0.6/node/1124134958/ways", { + Utils.injectJsonDownloadForTests("https://api.openstreetmap.org/api/0.6/node/1124134958/ways", { version: "0.6", generator: "CGImap 0.8.5 (2937646 spike-07.openstreetmap.org)", copyright: "OpenStreetMap and contributors", @@ -81,7 +81,7 @@ describe("RelationSplitHandler", () => { }) Utils.injectJsonDownloadForTests( - "https://www.openstreetmap.org/api/0.6/relation/9572808/full", + "https://api.openstreetmap.org/api/0.6/relation/9572808/full", { version: "0.6", generator: "CGImap 0.8.5 (3128319 spike-07.openstreetmap.org)", @@ -200,7 +200,7 @@ describe("RelationSplitHandler", () => { } ) - Utils.injectJsonDownloadForTests("https://www.openstreetmap.org/api/0.6/way/687866206/full", { + Utils.injectJsonDownloadForTests("https://api.openstreetmap.org/api/0.6/way/687866206/full", { version: "0.6", generator: "CGImap 0.8.5 (2601512 spike-07.openstreetmap.org)", copyright: "OpenStreetMap and contributors", @@ -250,7 +250,7 @@ describe("RelationSplitHandler", () => { ], }) - Utils.injectJsonDownloadForTests("https://www.openstreetmap.org/api/0.6/way/690497698/full", { + Utils.injectJsonDownloadForTests("https://api.openstreetmap.org/api/0.6/way/690497698/full", { version: "0.6", generator: "CGImap 0.8.5 (3023311 spike-07.openstreetmap.org)", copyright: "OpenStreetMap and contributors", @@ -311,7 +311,7 @@ describe("RelationSplitHandler", () => { ], }) Utils.injectJsonDownloadForTests( - "https://www.openstreetmap.org/api/0.6/relation/4374576/full", + "https://api.openstreetmap.org/api/0.6/relation/4374576/full", { version: "0.6", generator: "CGImap 0.8.5 (1266692 spike-06.openstreetmap.org)", @@ -342,7 +342,7 @@ describe("RelationSplitHandler", () => { } ) - Utils.injectJsonDownloadForTests("https://www.openstreetmap.org/api/0.6/way/143298912/full", { + Utils.injectJsonDownloadForTests("https://api.openstreetmap.org/api/0.6/way/143298912/full", { version: "0.6", generator: "CGImap 0.8.5 (4046166 spike-07.openstreetmap.org)", copyright: "OpenStreetMap and contributors", diff --git a/test/Logic/OSM/Actions/ReplaceGeometryAction.spec.ts b/test/Logic/OSM/Actions/ReplaceGeometryAction.spec.ts index 94098e525..bcc6e69d7 100644 --- a/test/Logic/OSM/Actions/ReplaceGeometryAction.spec.ts +++ b/test/Logic/OSM/Actions/ReplaceGeometryAction.spec.ts @@ -327,7 +327,7 @@ describe("ReplaceGeometryAction", () => { const wayId = "way/160909312" Utils.injectJsonDownloadForTests( - "https://www.openstreetmap.org/api/0.6/map.json?bbox=3.2166673243045807,51.21467321525788,3.217007964849472,51.21482442824023", + "https://api.openstreetmap.org/api/0.6/map.json?bbox=3.2166673243045807,51.21467321525788,3.217007964849472,51.21482442824023", { version: "0.6", generator: "CGImap 0.8.6 (1549677 spike-06.openstreetmap.org)", @@ -715,7 +715,7 @@ describe("ReplaceGeometryAction", () => { } ) - Utils.injectJsonDownloadForTests("https://www.openstreetmap.org/api/0.6/way/160909312/full", { + Utils.injectJsonDownloadForTests("https://api.openstreetmap.org/api/0.6/way/160909312/full", { version: "0.6", generator: "CGImap 0.8.6 (2407324 spike-06.openstreetmap.org)", copyright: "OpenStreetMap and contributors", @@ -880,7 +880,7 @@ describe("ReplaceGeometryAction", () => { [3.2166673243045807, 51.21467321525788], [3.217007964849472, 51.21482442824023], ]) - const url = `https://www.openstreetmap.org/api/0.6/map.json?bbox=${bbox.minLon},${bbox.minLat},${bbox.maxLon},${bbox.maxLat}` + const url = `https://api.openstreetmap.org/api/0.6/map.json?bbox=${bbox.minLon},${bbox.minLat},${bbox.maxLon},${bbox.maxLat}` const data = await Utils.downloadJson(url) const fullNodeDatabase = new FullNodeDatabaseSource() fullNodeDatabase.handleOsmJson(data, 0, 0, 0) diff --git a/test/Logic/OSM/Actions/SplitAction.spec.ts b/test/Logic/OSM/Actions/SplitAction.spec.ts index 53147d224..aee9a5860 100644 --- a/test/Logic/OSM/Actions/SplitAction.spec.ts +++ b/test/Logic/OSM/Actions/SplitAction.spec.ts @@ -9,7 +9,7 @@ describe("SplitAction", () => { { // Setup of download Utils.injectJsonDownloadForTests( - "https://www.openstreetmap.org/api/0.6/way/941079939/full", + "https://api.openstreetmap.org/api/0.6/way/941079939/full", { version: "0.6", generator: "CGImap 0.8.5 (957273 spike-08.openstreetmap.org)", @@ -210,7 +210,7 @@ describe("SplitAction", () => { ) Utils.injectJsonDownloadForTests( - "https://www.openstreetmap.org/api/0.6/way/941079939/relations", + "https://api.openstreetmap.org/api/0.6/way/941079939/relations", { version: "0.6", generator: "CGImap 0.8.5 (2419440 spike-07.openstreetmap.org)", @@ -222,7 +222,7 @@ describe("SplitAction", () => { ) Utils.injectJsonDownloadForTests( - "https://www.openstreetmap.org/api/0.6/way/295132739/full", + "https://api.openstreetmap.org/api/0.6/way/295132739/full", { version: "0.6", generator: "CGImap 0.8.5 (3138407 spike-07.openstreetmap.org)", @@ -409,7 +409,7 @@ describe("SplitAction", () => { } ) Utils.injectJsonDownloadForTests( - "https://www.openstreetmap.org/api/0.6/way/295132739/relations", + "https://api.openstreetmap.org/api/0.6/way/295132739/relations", // Mimick that there are no relations relation is missing { version: "0.6", @@ -422,7 +422,7 @@ describe("SplitAction", () => { ) Utils.injectJsonDownloadForTests( - "https://www.openstreetmap.org/api/0.6/way/61435323/full", + "https://api.openstreetmap.org/api/0.6/way/61435323/full", { version: "0.6", generator: "CGImap 0.8.5 (53092 spike-08.openstreetmap.org)", @@ -488,7 +488,7 @@ describe("SplitAction", () => { } ) Utils.injectJsonDownloadForTests( - "https://www.openstreetmap.org/api/0.6/way/61435323/relations", + "https://api.openstreetmap.org/api/0.6/way/61435323/relations", { version: "0.6", generator: "CGImap 0.8.5 (3622541 spike-06.openstreetmap.org)", @@ -2567,7 +2567,7 @@ describe("SplitAction", () => { } ) Utils.injectJsonDownloadForTests( - "https://www.openstreetmap.org/api/0.6/way/61435332/full", + "https://api.openstreetmap.org/api/0.6/way/61435332/full", { version: "0.6", generator: "CGImap 0.8.5 (3819319 spike-06.openstreetmap.org)", @@ -2620,7 +2620,7 @@ describe("SplitAction", () => { } ) Utils.injectJsonDownloadForTests( - "https://www.openstreetmap.org/api/0.6/way/509668834/full", + "https://api.openstreetmap.org/api/0.6/way/509668834/full", { version: "0.6", generator: "CGImap 0.8.5 (3735280 spike-06.openstreetmap.org)", diff --git a/test/Logic/OSM/OsmObject.spec.ts b/test/Logic/OSM/OsmObject.spec.ts index be8c416ef..01c962ec6 100644 --- a/test/Logic/OSM/OsmObject.spec.ts +++ b/test/Logic/OSM/OsmObject.spec.ts @@ -8,7 +8,7 @@ import OsmObjectDownloader from "../../../src/Logic/Osm/OsmObjectDownloader" describe("OsmObject", () => { describe("download referencing ways", () => { Utils.injectJsonDownloadForTests( - "https://www.openstreetmap.org/api/0.6/node/1124134958/ways", + "https://api.openstreetmap.org/api/0.6/node/1124134958/ways", { version: "0.6", generator: "CGImap 0.8.6 (49805 spike-06.openstreetmap.org)", @@ -89,7 +89,7 @@ describe("OsmObject", () => { it("should download full OSM-relations", async () => { ScriptUtils.fixUtils() Utils.injectJsonDownloadForTests( - "https://www.openstreetmap.org/api/0.6/relation/5759328/full", + "https://api.openstreetmap.org/api/0.6/relation/5759328/full", JSON.parse(readFileSync("./test/data/relation_5759328.json", { encoding: "utf-8" })) ) const r = await new OsmObjectDownloader()