forked from MapComplete/MapComplete
Add delete option for layers
This commit is contained in:
parent
2b3853e3c7
commit
9994258707
1 changed files with 35 additions and 0 deletions
|
@ -44,6 +44,36 @@ async function prepareFile(url: string): Promise<string> {
|
||||||
}
|
}
|
||||||
return null
|
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) {
|
async function handlePost(req: http.IncomingMessage, res: ServerResponse) {
|
||||||
let body = ""
|
let body = ""
|
||||||
|
@ -101,6 +131,11 @@ http.createServer(async (req: http.IncomingMessage, res) => {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(req.method === "DELETE"){
|
||||||
|
await handleDelete(req, res)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const url = new URL(`http://127.0.0.1/` + req.url)
|
const url = new URL(`http://127.0.0.1/` + req.url)
|
||||||
console.log("URL pathname is")
|
console.log("URL pathname is")
|
||||||
if (url.pathname.endsWith("overview")) {
|
if (url.pathname.endsWith("overview")) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue