move export to admin

This commit is contained in:
Umputun
2017-12-24 18:20:03 -06:00
parent bfed1ef547
commit bda663f0d1
3 changed files with 27 additions and 25 deletions
+3 -12
View File
@@ -32,7 +32,7 @@ type Server struct {
Exporter migrator.Exporter
DevMode bool
mod moderator
mod admin
}
// Run the lister and request's router, activate rest server
@@ -62,9 +62,8 @@ func (s *Server) Run() {
})
rapi.With(Auth(s.SessionStore, s.Admins, s.DevMode)).Group(func(radmin chi.Router) {
s.mod = moderator{dataStore: s.Store}
radmin.Get("/export", s.exportCtrl)
radmin.Mount("/moderate", s.mod.routes())
s.mod = admin{dataStore: s.Store, exporter: s.Exporter}
radmin.Mount("/admin", s.mod.routes())
})
})
@@ -252,14 +251,6 @@ func (s *Server) voteCtrl(w http.ResponseWriter, r *http.Request) {
render.JSON(w, r, comment)
}
// GET /export?site=site-id
func (s *Server) exportCtrl(w http.ResponseWriter, r *http.Request) {
siteID := r.URL.Query().Get("site")
if err := s.Exporter.Export(w, siteID); err != nil {
httpError(w, r, http.StatusInternalServerError, err, "export failed")
}
}
func httpError(w http.ResponseWriter, r *http.Request, code int, err error, details string) {
render.Status(r, code)
render.JSON(w, r, JSON{"error": err.Error(), "details": details})