add start scan button
This commit is contained in:
@@ -71,7 +71,7 @@
|
||||
<div class="box-title">
|
||||
<i class="mdi mdi-folder-multiple"></i> recent folders
|
||||
</div>
|
||||
<div class="block-right">
|
||||
<div class="block-right text-right">
|
||||
<table id="recent-folders">
|
||||
{{ range $folder := .RecentFolders }}
|
||||
<tr>
|
||||
@@ -80,6 +80,7 @@
|
||||
</tr>
|
||||
{{ end }}
|
||||
</table>
|
||||
<a href="/admin/start_scan_do">start scan</a>
|
||||
</div>
|
||||
</div>
|
||||
{{ end }}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user