implement table deletion, get ready for map upload
This commit is contained in:
parent
4f9ca53e1b
commit
4ea3e656d6
3 changed files with 40 additions and 9 deletions
|
@ -112,12 +112,10 @@ func apiDestroyTable(next http.Handler, udb auth.UserStore, dbAdapter mongodb.Db
|
||||||
destroy := false
|
destroy := false
|
||||||
i := 0
|
i := 0
|
||||||
|
|
||||||
tableName := req.Context().Value("Slug")
|
table := models.TableKey{}
|
||||||
tablePass := req.Form["passcode"][0]
|
err = json.NewDecoder(req.Body).Decode(&table)
|
||||||
|
if err != nil {
|
||||||
table := models.TableKey{
|
w.WriteHeader(400)
|
||||||
Name: tableName.(string),
|
|
||||||
Passcode: tablePass,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for j, t := range tables {
|
for j, t := range tables {
|
||||||
|
@ -147,6 +145,18 @@ func apiDestroyTable(next http.Handler, udb auth.UserStore, dbAdapter mongodb.Db
|
||||||
return http.HandlerFunc(handlerFunc)
|
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 {
|
func CreateAdminInterface(udb auth.UserStore, dbAdapter mongodb.DbAdapter) http.Handler {
|
||||||
// create quartzgun router
|
// create quartzgun router
|
||||||
rtr := &router.Router{Fallback: *template.Must(template.ParseFiles("static/error.html"))}
|
rtr := &router.Router{Fallback: *template.Must(template.ParseFiles("static/error.html"))}
|
||||||
|
|
|
@ -21,13 +21,34 @@ async function getTable(name, pass) {
|
||||||
infoHtml = "<a href='#' onclick='getTables()'>← table list</a><br><pre>";
|
infoHtml = "<a href='#' onclick='getTables()'>← table list</a><br><pre>";
|
||||||
infoHtml += await res.text();
|
infoHtml += await res.text();
|
||||||
infoHtml += "</pre>"
|
infoHtml += "</pre>"
|
||||||
|
infoHtml += `<button onclick='destroyTable()'>Destroy</button>`
|
||||||
adminZone.innerHTML = infoHtml;
|
adminZone.innerHTML = infoHtml;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
console.log(res.status);
|
console.log(res.status);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} 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}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -78,8 +78,8 @@ function dial() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
conn.addEventListener("error", e => {
|
conn.addEventListener("error", e => {
|
||||||
setErr(JSON.stringify(e));
|
setErr(`${e.name}: ${e.message}`);
|
||||||
conn.close(1002);
|
conn.close(3000);
|
||||||
})
|
})
|
||||||
|
|
||||||
conn.addEventListener("message", e => {
|
conn.addEventListener("message", e => {
|
||||||
|
|
Loading…
Reference in a new issue