diff --git a/admin/admin.go b/admin/admin.go index f17c8d0..222ad1e 100644 --- a/admin/admin.go +++ b/admin/admin.go @@ -150,7 +150,7 @@ func apiDestroyTable(next http.Handler, udb auth.UserStore, dbAdapter mongodb.Db return http.HandlerFunc(handlerFunc) } -func apiUploadImg(next http.Handler, udb auth.UserStore, dbAdapter mongodb.DbAdapter, uploads, uploadType string, uploadMax int) http.Handler { +func apiUploadImg(next http.Handler, dbAdapter mongodb.DbAdapter, uploads, uploadType string, uploadMax int) http.Handler { handlerFunc := func(w http.ResponseWriter, req *http.Request) { // get table from request body r, err := req.MultipartReader() @@ -218,12 +218,6 @@ func apiUploadImg(next http.Handler, udb auth.UserStore, dbAdapter mongodb.DbAda dest.Write(fileData) dest.Close() - err = dbAdapter.SetMapImageUrl(tableKey, "/uploads/"+tableKey.Name+"/"+uploadType+"/"+header.Filename) - if err != nil { - w.WriteHeader(500) - next.ServeHTTP(w, req) - return - } // respond with URL so UI can update AddContextValue(req, "location", "/uploads/"+tableKey.Name+"/"+uploadType+"/"+header.Filename) next.ServeHTTP(w, req) @@ -259,6 +253,16 @@ func apiListImages(next http.Handler, uploads string, uploadType string) http.Ha return http.HandlerFunc(handlerFunc) } +func apiDeleteImage(next http.Handler, uploads string, uploadType string) http.Handler { + handlerFunc := func(w http.ResponseWriter, req *http.Request) { + // put the path together + // if the file exists, delete it and return the deleted path + // otherwise, return an error + } + + return http.HandlerFunc(handlerFunc) +} + func CreateAdminInterface(udb auth.UserStore, dbAdapter mongodb.DbAdapter, uploads string, uploadMaxMB int) http.Handler { // create quartzgun router rtr := &router.Router{Fallback: *template.Must(template.ParseFiles("static/error.html"))} @@ -274,11 +278,12 @@ func CreateAdminInterface(udb auth.UserStore, dbAdapter mongodb.DbAdapter, uploa rtr.Delete(`/api/table/(?P\S+)`, Validate(apiDestroyTable(renderer.JSON("result"), udb, dbAdapter), udb, scopes)) // asset management - rtr.Post(`/api/upload/(?P\S+)/map/`, Validate(apiUploadImg(renderer.JSON("location"), udb, dbAdapter, uploads, "map", uploadMaxMB), udb, scopes)) + rtr.Post(`/api/upload/(?P\S+)/map/`, Validate(apiUploadImg(renderer.JSON("location"), dbAdapter, uploads, "map", uploadMaxMB), udb, scopes)) // GET /api/upload//map/ rtr.Get(`/api/upload/(?P\S+)/map/`, Validate(apiListImages(renderer.JSON("files"), uploads, "map"), udb, scopes)) // DELETE /api/upload/
/map/ - rtr.Post(`/api/upload/(?P\S+)/token/`, Validate(apiUploadImg(renderer.JSON("location"), udb, dbAdapter, uploads, "token", uploadMaxMB), udb, scopes)) + rtr.Post(`/api/upload/(?P\S+)/token/`, Validate(apiUploadImg(renderer.JSON("location"), dbAdapter, uploads, "token", uploadMaxMB), udb, scopes)) + rtr.Get(`/api/upload/(?P\S+)/token/`, Validate(apiListImages(renderer.JSON("files"), uploads, "token"), udb, scopes)) // DELETE /api/upload/
/token/ return http.HandlerFunc(rtr.ServeHTTP) diff --git a/static/index.html b/static/index.html index c2df305..7a1e829 100644 --- a/static/index.html +++ b/static/index.html @@ -60,8 +60,7 @@
- + diff --git a/static/style.css b/static/style.css index 65beb18..dcb2071 100644 --- a/static/style.css +++ b/static/style.css @@ -86,4 +86,17 @@ button:hover { height: auto; width: auto; border: solid 1px dimgray; +} + +#adminWrapper { + position: fixed; + top: 2em; + right: 0; + padding: 1em; + border: solid 1px #fff; + background: rgba(0,0,0,0.8); + color: #fff; + box-sizing: border-box; + max-height: calc(100vh - 4em); + overflow-y: auto; } \ No newline at end of file