chore: automated housekeeping...

This commit is contained in:
Pieter Vander Vennet 2025-07-10 18:26:31 +02:00
parent a190597905
commit 087e639020
382 changed files with 29496 additions and 2675 deletions

View file

@ -10,9 +10,7 @@ import ThemeConfig from "../../src/Models/ThemeConfig/ThemeConfig"
import { ThemeConfigJson } from "../../src/Models/ThemeConfig/Json/ThemeConfigJson"
import SpecialVisualizations from "../../src/UI/SpecialVisualizations"
import ValidationUtils from "../../src/Models/ThemeConfig/Conversion/ValidationUtils"
import {
QuestionableTagRenderingConfigJson,
} from "../../src/Models/ThemeConfig/Json/QuestionableTagRenderingConfigJson"
import { QuestionableTagRenderingConfigJson } from "../../src/Models/ThemeConfig/Json/QuestionableTagRenderingConfigJson"
import { LayerConfigJson } from "../../src/Models/ThemeConfig/Json/LayerConfigJson"
export interface ServerSourceInfo {
@ -23,7 +21,7 @@ export interface ServerSourceInfo {
sourceAvailable?: boolean | string
openData?: boolean | string
trigger?: ("always" | "specific_theme" | "specific_feature" | "clear_consent" | string)[]
moreInfo?: string[],
moreInfo?: string[]
logging?: "yes" | "probably" | "no"
}
@ -33,8 +31,10 @@ export interface ServerSourceInfo {
export class SourceOverview {
private eliUrlsCached: ServerSourceInfo[]
public async getOverview(layout?: ThemeConfig,
layoutJson?: ThemeConfigJson): Promise<(ServerSourceInfo | string)[]> {
public async getOverview(
layout?: ThemeConfig,
layoutJson?: ThemeConfigJson
): Promise<(ServerSourceInfo | string)[]> {
const apiUrls: (ServerSourceInfo | string)[] = [
...Constants.allServers,
<ServerSourceInfo>{
@ -54,11 +54,11 @@ export class SourceOverview {
apiUrls.push(...(sv.needsUrls ?? []))
}
const usedSpecialVisualisations = layoutJson?.layers?.flatMap((l) =>
ValidationUtils.getAllSpecialVisualisations(
<QuestionableTagRenderingConfigJson[]>(<LayerConfigJson>l).tagRenderings ?? [],
))
<QuestionableTagRenderingConfigJson[]>(<LayerConfigJson>l).tagRenderings ?? []
)
)
for (const usedSpecialVisualisation of usedSpecialVisualisations ?? []) {
if (typeof usedSpecialVisualisation === "string") {
@ -66,7 +66,9 @@ export class SourceOverview {
}
const neededUrls = usedSpecialVisualisation.func.needsUrls ?? []
if (typeof neededUrls === "function") {
let needed: string | string[] | ServerSourceInfo | ServerSourceInfo[] = neededUrls(usedSpecialVisualisation.args)
let needed: string | string[] | ServerSourceInfo | ServerSourceInfo[] = neededUrls(
usedSpecialVisualisation.args
)
if (Array.isArray(needed)) {
apiUrls.push(...needed)
} else {
@ -77,13 +79,12 @@ export class SourceOverview {
const geojsonSources: string[] = layout?.layers?.map((l) => l.source?.geojsonSource) ?? []
return Utils.NoNull(apiUrls.concat(...geojsonSources)).filter(item => {
return Utils.NoNull(apiUrls.concat(...geojsonSources)).filter((item) => {
if (typeof item === "string") {
return true
}
return item.url?.trim()?.length > 0
})
}
private async eliUrls(): Promise<ServerSourceInfo[]> {
@ -105,22 +106,28 @@ export class SourceOverview {
const match = url.match(regex)
const packageInInfo = (url: string) => {
if(typeof url !== "string"){
throw "invalid url"+url
if (typeof url !== "string") {
throw "invalid url" + url
}
return (<ServerSourceInfo>{
return <ServerSourceInfo>{
url,
description: "Background layer source or supporting sources for " + f.properties.id,
description:
"Background layer source or supporting sources for " + f.properties.id,
trigger: ["specific_feature"],
category: "maplayer",
moreInfo: Utils.NoEmpty(["https://github.com/osmlab/editor-layer-index", f.properties?.attribution?.url]),
})
moreInfo: Utils.NoEmpty([
"https://github.com/osmlab/editor-layer-index",
f.properties?.attribution?.url,
]),
}
}
if (match) {
const domains = match[1].split(",")
const subpart = match[0]
const info: ServerSourceInfo[] = domains.map((d) => packageInInfo(url.replace(subpart, d)))
const info: ServerSourceInfo[] = domains.map((d) =>
packageInInfo(url.replace(subpart, d))
)
urls.push(...info)
} else {
urls.push(packageInInfo(url))
@ -159,7 +166,11 @@ export class SourceOverview {
urls.push(packageInInfo(tileInfo["tiles"] ?? []))
}
}
urls.push(...(styleSpec["tiles"] ?? []).flatMap(ls => ls).map(url => packageInInfo(url)))
urls.push(
...(styleSpec["tiles"] ?? [])
.flatMap((ls) => ls)
.map((url) => packageInInfo(url))
)
urls.push(packageInInfo(styleSpec["sprite"]))
urls.push(packageInInfo(styleSpec["glyphs"]))
} catch (e) {
@ -169,11 +180,10 @@ export class SourceOverview {
}
}
}
urls = urls.filter(item => !!item.url)
urls.sort((a, b) => a < b ? -1 : 1)
urls = Utils.DedupOnId(urls, item => item.url)
urls = urls.filter((item) => !!item.url)
urls.sort((a, b) => (a < b ? -1 : 1))
urls = Utils.DedupOnId(urls, (item) => item.url)
this.eliUrlsCached = urls
return urls
}
}