diff --git a/admin/admin.go b/admin/admin.go index a874bbf..593538d 100644 --- a/admin/admin.go +++ b/admin/admin.go @@ -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"))} diff --git a/static/admin.js b/static/admin.js index d72b466..df6ec81 100644 --- a/static/admin.js +++ b/static/admin.js @@ -21,13 +21,34 @@ async function getTable(name, pass) { infoHtml = "← table list
";
       infoHtml += await res.text();
       infoHtml += "
" + infoHtml += `` 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}`); } } diff --git a/static/socket.js b/static/socket.js index df7c055..ac974be 100644 --- a/static/socket.js +++ b/static/socket.js @@ -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 => {