From 4b32bc0e4df82086e9416a0ee82d0cd3b9623e1e Mon Sep 17 00:00:00 2001 From: sentriz Date: Sun, 15 Mar 2020 00:03:15 +0000 Subject: [PATCH] move admin playlist handlers to own file --- server/ctrladmin/handlers.go | 30 ------------------ .../{playlist.go => handlers_playlist.go} | 31 +++++++++++++++++++ server/ctrlsubsonic/handlers_raw.go | 1 + 3 files changed, 32 insertions(+), 30 deletions(-) rename server/ctrladmin/{playlist.go => handlers_playlist.go} (71%) diff --git a/server/ctrladmin/handlers.go b/server/ctrladmin/handlers.go index 70c5589..ba97022 100644 --- a/server/ctrladmin/handlers.go +++ b/server/ctrladmin/handlers.go @@ -274,36 +274,6 @@ func (c *Controller) ServeStartScanDo(r *http.Request) *Response { } } -func (c *Controller) ServeUploadPlaylist(r *http.Request) *Response { - return &Response{template: "upload_playlist.tmpl"} -} - -func (c *Controller) ServeUploadPlaylistDo(r *http.Request) *Response { - if err := r.ParseMultipartForm((1 << 10) * 24); nil != err { - return &Response{ - err: "couldn't parse mutlipart", - code: 500, - } - } - user := r.Context().Value(CtxUser).(*db.User) - var playlistCount int - var errors []string - for _, headers := range r.MultipartForm.File { - for _, header := range headers { - headerErrors, created := playlistParseUpload(c, user.ID, header) - if created { - playlistCount++ - } - errors = append(errors, headerErrors...) - } - } - return &Response{ - redirect: "/admin/home", - flashN: []string{fmt.Sprintf("%d playlist(s) created", playlistCount)}, - flashW: errors, - } -} - func (c *Controller) ServeCreateTranscodePrefDo(r *http.Request) *Response { client := r.FormValue("client") profile := r.FormValue("profile") diff --git a/server/ctrladmin/playlist.go b/server/ctrladmin/handlers_playlist.go similarity index 71% rename from server/ctrladmin/playlist.go rename to server/ctrladmin/handlers_playlist.go index 90c0ff4..7b1dbe7 100644 --- a/server/ctrladmin/playlist.go +++ b/server/ctrladmin/handlers_playlist.go @@ -4,6 +4,7 @@ import ( "bufio" "fmt" "mime/multipart" + "net/http" "strings" "github.com/jinzhu/gorm" @@ -71,3 +72,33 @@ func playlistParseUpload(c *Controller, userID int, header *multipart.FileHeader c.DB.Save(playlist) return errors, true } + +func (c *Controller) ServeUploadPlaylist(r *http.Request) *Response { + return &Response{template: "upload_playlist.tmpl"} +} + +func (c *Controller) ServeUploadPlaylistDo(r *http.Request) *Response { + if err := r.ParseMultipartForm((1 << 10) * 24); nil != err { + return &Response{ + err: "couldn't parse mutlipart", + code: 500, + } + } + user := r.Context().Value(CtxUser).(*db.User) + var playlistCount int + var errors []string + for _, headers := range r.MultipartForm.File { + for _, header := range headers { + headerErrors, created := playlistParseUpload(c, user.ID, header) + if created { + playlistCount++ + } + errors = append(errors, headerErrors...) + } + } + return &Response{ + redirect: "/admin/home", + flashN: []string{fmt.Sprintf("%d playlist(s) created", playlistCount)}, + flashW: errors, + } +} diff --git a/server/ctrlsubsonic/handlers_raw.go b/server/ctrlsubsonic/handlers_raw.go index 7ff5e22..2396949 100644 --- a/server/ctrlsubsonic/handlers_raw.go +++ b/server/ctrlsubsonic/handlers_raw.go @@ -20,6 +20,7 @@ import ( // a) write to response writer // b) return a non-nil spec.Response // _but not both_ + func (c *Controller) ServeGetCoverArt(w http.ResponseWriter, r *http.Request) *spec.Response { params := r.Context().Value(CtxParams).(params.Params) id, err := params.GetInt("id")