Merge develop
This commit is contained in:
commit
d959b6b40b
290 changed files with 37178 additions and 2200 deletions
|
@ -15,6 +15,7 @@ import { ImmutableStore } from "../src/Logic/UIEventSource"
|
|||
import * as crypto from "crypto"
|
||||
import * as eli from "../src/assets/editor-layer-index.json"
|
||||
import * as eli_global from "../src/assets/global-raster-layers.json"
|
||||
import ValidationUtils from "../src/Models/ThemeConfig/Conversion/ValidationUtils"
|
||||
|
||||
const sharp = require("sharp")
|
||||
const template = readFileSync("theme.html", "utf8")
|
||||
|
@ -264,6 +265,7 @@ async function eliUrls(): Promise<string[]> {
|
|||
|
||||
async function generateCsp(
|
||||
layout: LayoutConfig,
|
||||
layoutJson: LayoutConfigJson,
|
||||
options: {
|
||||
scriptSrcs: string[]
|
||||
}
|
||||
|
@ -273,11 +275,28 @@ async function generateCsp(
|
|||
...Constants.defaultOverpassUrls,
|
||||
Constants.countryCoderEndpoint,
|
||||
Constants.nominatimEndpoint,
|
||||
"https://www.openstreetmap.org",
|
||||
"https://api.openstreetmap.org",
|
||||
"https://pietervdvn.goatcounter.com",
|
||||
]
|
||||
.concat(...SpecialVisualizations.specialVisualizations.map((sv) => sv.needsUrls))
|
||||
.concat(...(await eliUrls()))
|
||||
].concat(...(await eliUrls()))
|
||||
|
||||
SpecialVisualizations.specialVisualizations.forEach((sv) => {
|
||||
if (typeof sv.needsUrls === "function") {
|
||||
return
|
||||
}
|
||||
apiUrls.push(...sv.needsUrls)
|
||||
})
|
||||
|
||||
const usedSpecialVisualisations = ValidationUtils.getSpecialVisualisationsWithArgs(layoutJson)
|
||||
for (const usedSpecialVisualisation of usedSpecialVisualisations) {
|
||||
if (typeof usedSpecialVisualisation === "string") {
|
||||
continue
|
||||
}
|
||||
const neededUrls = usedSpecialVisualisation.func.needsUrls
|
||||
if (typeof neededUrls === "function") {
|
||||
apiUrls.push(...neededUrls(usedSpecialVisualisation.args))
|
||||
}
|
||||
}
|
||||
|
||||
const geojsonSources: string[] = layout.layers.map((l) => l.source?.geojsonSource)
|
||||
const hosts = new Set<string>()
|
||||
|
@ -299,6 +318,10 @@ async function generateCsp(
|
|||
}
|
||||
}
|
||||
|
||||
if (hosts.has("*")) {
|
||||
throw "* is not allowed as connect-src"
|
||||
}
|
||||
|
||||
const connectSrc = Array.from(hosts).sort()
|
||||
|
||||
const newSrcs = connectSrc.filter((newItem) => !previousSrc.has(newItem))
|
||||
|
@ -344,7 +367,13 @@ const removeOtherLanguagesHash = crypto
|
|||
.update(removeOtherLanguages)
|
||||
.digest("base64")
|
||||
|
||||
async function createLandingPage(layout: LayoutConfig, manifest, whiteIcons, alreadyWritten) {
|
||||
async function createLandingPage(
|
||||
layout: LayoutConfig,
|
||||
layoutJson: LayoutConfigJson,
|
||||
manifest,
|
||||
whiteIcons,
|
||||
alreadyWritten
|
||||
) {
|
||||
Locale.language.setData(layout.language[0])
|
||||
const targetLanguage = layout.language[0]
|
||||
const ogTitle = Translations.T(layout.title).textFor(targetLanguage).replace(/"/g, '\\"')
|
||||
|
@ -428,7 +457,7 @@ async function createLandingPage(layout: LayoutConfig, manifest, whiteIcons, alr
|
|||
.replace(/<!-- THEME-SPECIFIC -->.*<!-- THEME-SPECIFIC-END-->/s, themeSpecific)
|
||||
.replace(
|
||||
/<!-- CSP -->/,
|
||||
await generateCsp(layout, {
|
||||
await generateCsp(layout, layoutJson, {
|
||||
scriptSrcs: [`'sha256-${removeOtherLanguagesHash}'`],
|
||||
})
|
||||
)
|
||||
|
@ -518,7 +547,13 @@ async function main(): Promise<void> {
|
|||
writeFile("public/" + manifestLocation, manif, err)
|
||||
|
||||
// Create a landing page for the given theme
|
||||
const landing = await createLandingPage(layout, manifest, whiteIcons, alreadyWritten)
|
||||
const landing = await createLandingPage(
|
||||
layout,
|
||||
layoutConfigJson,
|
||||
manifest,
|
||||
whiteIcons,
|
||||
alreadyWritten
|
||||
)
|
||||
|
||||
writeFile(enc(layout.id) + ".html", landing, err)
|
||||
await createIndexFor(layout)
|
||||
|
|
|
@ -44,6 +44,36 @@ async function prepareFile(url: string): Promise<string> {
|
|||
}
|
||||
return null
|
||||
}
|
||||
async function handleDelete(req: http.IncomingMessage, res: ServerResponse) {
|
||||
let body = ""
|
||||
req.on("data", (chunk) => {
|
||||
body = body + chunk
|
||||
})
|
||||
const paths = req.url.split("/")
|
||||
console.log("Got a valid delete to:", paths.join("/"))
|
||||
for (let i = 1; i < paths.length; i++) {
|
||||
const p = paths.slice(0, i)
|
||||
const dir = STATIC_PATH + p.join("/")
|
||||
if (!fs.existsSync(dir)) {
|
||||
res.writeHead(304, { "Content-Type": MIME_TYPES.html })
|
||||
res.write("<html><body>No parent directory, nothing deleted</body></html>", "utf8")
|
||||
res.end()
|
||||
return
|
||||
}
|
||||
}
|
||||
const path = STATIC_PATH + paths.join("/")
|
||||
if(!fs.existsSync(path)){
|
||||
res.writeHead(304, { "Content-Type": MIME_TYPES.html })
|
||||
res.write("<html><body>File not found</body></html>", "utf8")
|
||||
res.end()
|
||||
return
|
||||
}
|
||||
|
||||
fs.renameSync(path, path+".bak")
|
||||
res.writeHead(200, { "Content-Type": MIME_TYPES.html })
|
||||
res.write("<html><body>File moved to backup</body></html>", "utf8")
|
||||
res.end()
|
||||
}
|
||||
|
||||
async function handlePost(req: http.IncomingMessage, res: ServerResponse) {
|
||||
let body = ""
|
||||
|
@ -53,6 +83,7 @@ async function handlePost(req: http.IncomingMessage, res: ServerResponse) {
|
|||
|
||||
await new Promise((resolve) => req.on("end", resolve))
|
||||
|
||||
console.log(new Date().toISOString())
|
||||
let parsed: any
|
||||
try {
|
||||
parsed = JSON.parse(body)
|
||||
|
@ -84,7 +115,7 @@ async function handlePost(req: http.IncomingMessage, res: ServerResponse) {
|
|||
|
||||
http.createServer(async (req: http.IncomingMessage, res) => {
|
||||
try {
|
||||
console.log(req.method + " " + req.url, "from:", req.headers.origin)
|
||||
console.log(req.method + " " + req.url, "from:", req.headers.origin, new Date().toISOString())
|
||||
res.setHeader(
|
||||
"Access-Control-Allow-Headers",
|
||||
"Origin, X-Requested-With, Content-Type, Accept"
|
||||
|
@ -101,6 +132,12 @@ http.createServer(async (req: http.IncomingMessage, res) => {
|
|||
return
|
||||
}
|
||||
|
||||
if(req.method === "DELETE"){
|
||||
console.log("Got a DELETE", new Date())
|
||||
await handleDelete(req, res)
|
||||
return
|
||||
}
|
||||
|
||||
const url = new URL(`http://127.0.0.1/` + req.url)
|
||||
console.log("URL pathname is")
|
||||
if (url.pathname.endsWith("overview")) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue