add start scan button

This commit is contained in:
sentriz
2019-07-03 12:57:22 +01:00
parent ada62d1511
commit c7c9ecbf04
3 changed files with 20 additions and 1 deletions

View File

@@ -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)
}
}()
}