implement table deletion, get ready for map upload

This commit is contained in:
Iris Lightshard 2023-02-25 22:43:38 -07:00
parent 4f9ca53e1b
commit 4ea3e656d6
Signed by: nilix
GPG key ID: 3B7FBC22144E6398
3 changed files with 40 additions and 9 deletions

View file

@ -112,12 +112,10 @@ func apiDestroyTable(next http.Handler, udb auth.UserStore, dbAdapter mongodb.Db
destroy := false
i := 0
tableName := req.Context().Value("Slug")
tablePass := req.Form["passcode"][0]
table := models.TableKey{
Name: tableName.(string),
Passcode: tablePass,
table := models.TableKey{}
err = json.NewDecoder(req.Body).Decode(&table)
if err != nil {
w.WriteHeader(400)
}
for j, t := range tables {
@ -147,6 +145,18 @@ func apiDestroyTable(next http.Handler, udb auth.UserStore, dbAdapter mongodb.Db
return http.HandlerFunc(handlerFunc)
}
func apiUploadMapImg(next http.Handler, udb auth.UserStore, dbAdapter mongodb.DbAdapter) http.Handler {
handlerFunc := func(w http.ResponseWriter, req *http.Request) {
// ensure data storage dir exists
// check for filename; call create to overwrite regardless
// get file data from multipart form
// write to file
// respond with URL?
}
return handlerFunc
}
func CreateAdminInterface(udb auth.UserStore, dbAdapter mongodb.DbAdapter) http.Handler {
// create quartzgun router
rtr := &router.Router{Fallback: *template.Must(template.ParseFiles("static/error.html"))}

View file

@ -21,13 +21,34 @@ async function getTable(name, pass) {
infoHtml = "<a href='#' onclick='getTables()'>&larr; table list</a><br><pre>";
infoHtml += await res.text();
infoHtml += "</pre>"
infoHtml += `<button onclick='destroyTable()'>Destroy</button>`
adminZone.innerHTML = infoHtml;
}
else {
console.log(res.status);
}
} catch (err) {
console.dir(err)
setErr(`${err.name}: ${err.message}`);
}
}
async function destroyTable() {
try {
const headers = new Headers();
headers.set('Authorization', 'Bearer ' + adminToken.access_token);
const res = await fetch(`/admin/api/table/${tableKey.name}`, {
method: 'DELETE',
headers: headers,
body: JSON.stringify(tableKey)
});
if (res.ok) {
conn.close(1000);
getTables();
} else {
setErr(await res.json());
}
} catch (err) {
setErr(`${err.name}: ${err.message}`);
}
}

View file

@ -78,8 +78,8 @@ function dial() {
}
});
conn.addEventListener("error", e => {
setErr(JSON.stringify(e));
conn.close(1002);
setErr(`${e.name}: ${e.message}`);
conn.close(3000);
})
conn.addEventListener("message", e => {