diff --git a/server/assets/pages/home.tmpl b/server/assets/pages/home.tmpl index 2801f31..008d7a7 100644 --- a/server/assets/pages/home.tmpl +++ b/server/assets/pages/home.tmpl @@ -71,7 +71,7 @@
recent folders
-
+
{{ range $folder := .RecentFolders }} @@ -80,6 +80,7 @@ {{ end }}
+ start scan
{{ end }} diff --git a/server/handler/handler_admin.go b/server/handler/handler_admin.go index 293a174..8ded909 100644 --- a/server/handler/handler_admin.go +++ b/server/handler/handler_admin.go @@ -2,12 +2,14 @@ package handler import ( "fmt" + "log" "net/http" "github.com/gorilla/sessions" "github.com/jinzhu/gorm" "github.com/sentriz/gonic/model" + "github.com/sentriz/gonic/scanner" "github.com/sentriz/gonic/server/lastfm" ) @@ -258,3 +260,18 @@ func (c *Controller) ServeUpdateLastFMAPIKeyDo(w http.ResponseWriter, r *http.Re c.SetSetting("lastfm_secret", secret) http.Redirect(w, r, "/admin/home", http.StatusSeeOther) } + +func (c *Controller) ServeStartScanDo(w http.ResponseWriter, r *http.Request) { + session := r.Context().Value(contextSessionKey).(*sessions.Session) + session.AddFlash("scan started") + sessionLogSave(w, r, session) + http.Redirect(w, r, "/admin/home", http.StatusSeeOther) + go func() { + err := scanner. + New(c.DB, c.MusicPath). + Start() + if err != nil { + log.Printf("error while scanning: %v\n", err) + } + }() +} diff --git a/server/server_admin.go b/server/server_admin.go index ca28313..3b8cbc8 100644 --- a/server/server_admin.go +++ b/server/server_admin.go @@ -144,5 +144,6 @@ func (s *Server) SetupAdmin() error { s.mux.HandleFunc("/admin/create_user_do", withAdminWare(s.ServeCreateUserDo)) s.mux.HandleFunc("/admin/update_lastfm_api_key", withAdminWare(s.ServeUpdateLastFMAPIKey)) s.mux.HandleFunc("/admin/update_lastfm_api_key_do", withAdminWare(s.ServeUpdateLastFMAPIKeyDo)) + s.mux.HandleFunc("/admin/start_scan_do", withAdminWare(s.ServeStartScanDo)) return nil }