Fix: enable external data sources from the ELI

This commit is contained in:
Pieter Vander Vennet 2023-10-02 00:15:49 +02:00
parent 394bad545d
commit 5ea08040d7

View file

@ -10,10 +10,11 @@ import ScriptUtils from "./ScriptUtils"
import { Utils } from "../src/Utils"
import SpecialVisualizations from "../src/UI/SpecialVisualizations"
import Constants from "../src/Models/Constants"
import { AvailableRasterLayers, RasterLayerPolygon } from "../src/Models/RasterLayers"
import { AvailableRasterLayers, EditorLayerIndexProperties, RasterLayerPolygon } from "../src/Models/RasterLayers";
import { ImmutableStore } from "../src/Logic/UIEventSource"
import * as crypto from "crypto"
import * as eli from "../src/assets/editor-layer-index.json"
import dom from "svelte/types/compiler/compile/render_dom";
const sharp = require("sharp")
const template = readFileSync("theme.html", "utf8")
const codeTemplate = readFileSync("src/index_theme.ts.template", "utf8")
@ -207,6 +208,28 @@ function asLangSpan(t: Translation, tag = "span"): string {
let previousSrc: Set<string> = new Set<string>()
let eliUrlsCached : string[]
function eliUrls(): string[]{
if(eliUrlsCached){
return eliUrlsCached
}
const urls: string[] = []
const regex =/{switch:([^}]+)}/
for (const feature of eli.features) {
const url = (<RasterLayerPolygon> feature).properties.url
const match = url.match(regex)
if(match){
const domains = match[1].split(",")
const subpart = match[0]
urls.push(...domains.map(d => url.replace(subpart, d)))
}else{
urls.push(url)
}
}
eliUrlsCached = urls
return urls
}
function generateCsp(
layout: LayoutConfig,
options: {
@ -221,6 +244,7 @@ function generateCsp(
"https://api.openstreetmap.org",
"https://pietervdvn.goatcounter.com",
].concat(...SpecialVisualizations.specialVisualizations.map((sv) => sv.needsUrls))
.concat(...eliUrls())
const geojsonSources: string[] = layout.layers.map((l) => l.source?.geojsonSource)
const hosts = new Set<string>()