move cache path from base controller to subsonic controller

This commit is contained in:
sentriz
2020-03-26 01:26:05 +00:00
parent b63428344a
commit b3a623ffe1
5 changed files with 14 additions and 7 deletions

View File

@@ -47,7 +47,6 @@ func statusToBlock(code int) string {
type Controller struct { type Controller struct {
DB *db.DB DB *db.DB
MusicPath string MusicPath string
CachePath string
Scanner *scanner.Scanner Scanner *scanner.Scanner
ProxyPrefix string ProxyPrefix string
} }

View File

@@ -24,11 +24,13 @@ const (
type Controller struct { type Controller struct {
*ctrlbase.Controller *ctrlbase.Controller
cachePath string
} }
func New(base *ctrlbase.Controller) *Controller { func New(base *ctrlbase.Controller, cachePath string) *Controller {
return &Controller{ return &Controller{
Controller: base, Controller: base,
cachePath: cachePath,
} }
} }

View File

@@ -30,7 +30,10 @@ func init() {
if err != nil { if err != nil {
log.Fatalf("error opening database: %v\n", err) log.Fatalf("error opening database: %v\n", err)
} }
testController = New(&ctrlbase.Controller{DB: db}) testController = New(
&ctrlbase.Controller{DB: db},
"",
)
} }
type queryCase struct { type queryCase struct {

View File

@@ -136,7 +136,7 @@ func (c *Controller) ServeStream(w http.ResponseWriter, r *http.Request) *spec.R
} }
servOpts.pref = pref servOpts.pref = pref
servOpts.maxBitrate = params.GetIntOr("maxBitRate", 0) servOpts.maxBitrate = params.GetIntOr("maxBitRate", 0)
servOpts.cachePath = c.CachePath servOpts.cachePath = c.cachePath
serveTrackEncode(w, r, servOpts) serveTrackEncode(w, r, servOpts)
return nil return nil
} }

View File

@@ -39,10 +39,11 @@ func New(opts Options) *Server {
opts.CachePath = filepath.Clean(opts.CachePath) opts.CachePath = filepath.Clean(opts.CachePath)
// ** begin controllers // ** begin controllers
scanner := scanner.New(opts.DB, opts.MusicPath) scanner := scanner.New(opts.DB, opts.MusicPath)
// the base controller, it's fields/middlewares are embedded/used by the
// other two admin ui and subsonic controllers
base := &ctrlbase.Controller{ base := &ctrlbase.Controller{
DB: opts.DB, DB: opts.DB,
MusicPath: opts.MusicPath, MusicPath: opts.MusicPath,
CachePath: opts.CachePath,
ProxyPrefix: opts.ProxyPrefix, ProxyPrefix: opts.ProxyPrefix,
Scanner: scanner, Scanner: scanner,
} }
@@ -51,8 +52,10 @@ func New(opts Options) *Server {
r.Use(base.WithLogging) r.Use(base.WithLogging)
r.Use(base.WithCORS) r.Use(base.WithCORS)
setupMisc(r, base) setupMisc(r, base)
setupAdmin(r.PathPrefix("/admin").Subrouter(), ctrladmin.New(base)) setupAdminRouter := r.PathPrefix("/admin").Subrouter()
setupSubsonic(r.PathPrefix("/rest").Subrouter(), ctrlsubsonic.New(base)) setupAdmin(setupAdminRouter, ctrladmin.New(base))
setupSubsonicRouter := r.PathPrefix("/rest").Subrouter()
setupSubsonic(setupSubsonicRouter, ctrlsubsonic.New(base, opts.CachePath))
// //
server := &http.Server{ server := &http.Server{
Addr: opts.ListenAddr, Addr: opts.ListenAddr,