This commit is contained in:
sentriz
2022-11-03 15:27:59 +00:00
parent 5c6855f671
commit 1f8de66fc0
6 changed files with 24 additions and 25 deletions

View File

@@ -17,8 +17,8 @@ import (
"github.com/peterbourgon/ff" "github.com/peterbourgon/ff"
"go.senan.xyz/gonic" "go.senan.xyz/gonic"
"go.senan.xyz/gonic/server"
"go.senan.xyz/gonic/db" "go.senan.xyz/gonic/db"
"go.senan.xyz/gonic/server"
) )
const ( const (

View File

@@ -349,7 +349,6 @@ func migratePodcastDropUserID(tx *gorm.DB, _ MigrationContext) error {
return nil return nil
} }
step = tx.Exec(` step = tx.Exec(`
ALTER TABLE podcasts DROP COLUMN user_id; ALTER TABLE podcasts DROP COLUMN user_id;
`) `)

View File

@@ -6,10 +6,10 @@ import (
"github.com/jinzhu/gorm" "github.com/jinzhu/gorm"
"go.senan.xyz/gonic/db"
"go.senan.xyz/gonic/server/ctrlsubsonic/params" "go.senan.xyz/gonic/server/ctrlsubsonic/params"
"go.senan.xyz/gonic/server/ctrlsubsonic/spec" "go.senan.xyz/gonic/server/ctrlsubsonic/spec"
"go.senan.xyz/gonic/server/ctrlsubsonic/specid" "go.senan.xyz/gonic/server/ctrlsubsonic/specid"
"go.senan.xyz/gonic/db"
) )
func (c *Controller) ServeGetBookmarks(r *http.Request) *spec.Response { func (c *Controller) ServeGetBookmarks(r *http.Request) *spec.Response {

View File

@@ -5,10 +5,10 @@ import (
"github.com/mmcdole/gofeed" "github.com/mmcdole/gofeed"
"go.senan.xyz/gonic/db"
"go.senan.xyz/gonic/server/ctrlsubsonic/params" "go.senan.xyz/gonic/server/ctrlsubsonic/params"
"go.senan.xyz/gonic/server/ctrlsubsonic/spec" "go.senan.xyz/gonic/server/ctrlsubsonic/spec"
"go.senan.xyz/gonic/server/ctrlsubsonic/specid" "go.senan.xyz/gonic/server/ctrlsubsonic/specid"
"go.senan.xyz/gonic/db"
) )
func (c *Controller) ServeGetPodcasts(r *http.Request) *spec.Response { func (c *Controller) ServeGetPodcasts(r *http.Request) *spec.Response {
@@ -45,7 +45,7 @@ func (c *Controller) ServeGetNewestPodcasts(r *http.Request) *spec.Response {
func (c *Controller) ServeDownloadPodcastEpisode(r *http.Request) *spec.Response { func (c *Controller) ServeDownloadPodcastEpisode(r *http.Request) *spec.Response {
user := r.Context().Value(CtxUser).(*db.User) user := r.Context().Value(CtxUser).(*db.User)
if (!user.IsAdmin) { if !user.IsAdmin {
return spec.NewError(50, "user not admin") return spec.NewError(50, "user not admin")
} }
params := r.Context().Value(CtxParams).(params.Params) params := r.Context().Value(CtxParams).(params.Params)
@@ -61,7 +61,7 @@ func (c *Controller) ServeDownloadPodcastEpisode(r *http.Request) *spec.Response
func (c *Controller) ServeCreatePodcastChannel(r *http.Request) *spec.Response { func (c *Controller) ServeCreatePodcastChannel(r *http.Request) *spec.Response {
user := r.Context().Value(CtxUser).(*db.User) user := r.Context().Value(CtxUser).(*db.User)
if (!user.IsAdmin) { if !user.IsAdmin {
return spec.NewError(50, "user not admin") return spec.NewError(50, "user not admin")
} }
params := r.Context().Value(CtxParams).(params.Params) params := r.Context().Value(CtxParams).(params.Params)
@@ -79,7 +79,7 @@ func (c *Controller) ServeCreatePodcastChannel(r *http.Request) *spec.Response {
func (c *Controller) ServeRefreshPodcasts(r *http.Request) *spec.Response { func (c *Controller) ServeRefreshPodcasts(r *http.Request) *spec.Response {
user := r.Context().Value(CtxUser).(*db.User) user := r.Context().Value(CtxUser).(*db.User)
if (!user.IsAdmin) { if !user.IsAdmin {
return spec.NewError(50, "user not admin") return spec.NewError(50, "user not admin")
} }
if err := c.Podcasts.RefreshPodcasts(); err != nil { if err := c.Podcasts.RefreshPodcasts(); err != nil {
@@ -90,7 +90,7 @@ func (c *Controller) ServeRefreshPodcasts(r *http.Request) *spec.Response {
func (c *Controller) ServeDeletePodcastChannel(r *http.Request) *spec.Response { func (c *Controller) ServeDeletePodcastChannel(r *http.Request) *spec.Response {
user := r.Context().Value(CtxUser).(*db.User) user := r.Context().Value(CtxUser).(*db.User)
if (!user.IsAdmin) { if !user.IsAdmin {
return spec.NewError(50, "user not admin") return spec.NewError(50, "user not admin")
} }
params := r.Context().Value(CtxParams).(params.Params) params := r.Context().Value(CtxParams).(params.Params)
@@ -106,7 +106,7 @@ func (c *Controller) ServeDeletePodcastChannel(r *http.Request) *spec.Response {
func (c *Controller) ServeDeletePodcastEpisode(r *http.Request) *spec.Response { func (c *Controller) ServeDeletePodcastEpisode(r *http.Request) *spec.Response {
user := r.Context().Value(CtxUser).(*db.User) user := r.Context().Value(CtxUser).(*db.User)
if (!user.IsAdmin) { if !user.IsAdmin {
return spec.NewError(50, "user not admin") return spec.NewError(50, "user not admin")
} }
params := r.Context().Value(CtxParams).(params.Params) params := r.Context().Value(CtxParams).(params.Params)

View File

@@ -75,15 +75,15 @@ func (i ID) MarshalJSON() ([]byte, error) {
return json.Marshal(i.String()) return json.Marshal(i.String())
} }
func (i *ID) UnmarshalJSON(data []byte) (error) { func (i *ID) UnmarshalJSON(data []byte) error {
if (len(data) <= 2) { if len(data) <= 2 {
return fmt.Errorf("too short: %w", ErrBadJSON) return fmt.Errorf("too short: %w", ErrBadJSON)
} }
id, err := New(string(data[1:len(data)-1])) // Strip quotes id, err := New(string(data[1 : len(data)-1])) // Strip quotes
if (err == nil) { if err == nil {
*i = id; *i = id
} }
return err; return err
} }
func (i ID) MarshalText() ([]byte, error) { func (i ID) MarshalText() ([]byte, error) {

View File

@@ -11,10 +11,6 @@ import (
"github.com/gorilla/securecookie" "github.com/gorilla/securecookie"
"github.com/sentriz/gormstore" "github.com/sentriz/gormstore"
"go.senan.xyz/gonic/server/assets"
"go.senan.xyz/gonic/server/ctrladmin"
"go.senan.xyz/gonic/server/ctrlbase"
"go.senan.xyz/gonic/server/ctrlsubsonic"
"go.senan.xyz/gonic/db" "go.senan.xyz/gonic/db"
"go.senan.xyz/gonic/jukebox" "go.senan.xyz/gonic/jukebox"
"go.senan.xyz/gonic/podcasts" "go.senan.xyz/gonic/podcasts"
@@ -23,6 +19,10 @@ import (
"go.senan.xyz/gonic/scrobble" "go.senan.xyz/gonic/scrobble"
"go.senan.xyz/gonic/scrobble/lastfm" "go.senan.xyz/gonic/scrobble/lastfm"
"go.senan.xyz/gonic/scrobble/listenbrainz" "go.senan.xyz/gonic/scrobble/listenbrainz"
"go.senan.xyz/gonic/server/assets"
"go.senan.xyz/gonic/server/ctrladmin"
"go.senan.xyz/gonic/server/ctrlbase"
"go.senan.xyz/gonic/server/ctrlsubsonic"
"go.senan.xyz/gonic/transcode" "go.senan.xyz/gonic/transcode"
) )
@@ -298,12 +298,12 @@ type (
func (s *Server) StartHTTP(listenAddr string, tlsCert string, tlsKey string) (FuncExecute, FuncInterrupt) { func (s *Server) StartHTTP(listenAddr string, tlsCert string, tlsKey string) (FuncExecute, FuncInterrupt) {
list := &http.Server{ list := &http.Server{
Addr: listenAddr, Addr: listenAddr,
Handler: s.router, Handler: s.router,
ReadTimeout: 5 * time.Second, ReadTimeout: 5 * time.Second,
ReadHeaderTimeout: 5 * time.Second, ReadHeaderTimeout: 5 * time.Second,
WriteTimeout: 80 * time.Second, WriteTimeout: 80 * time.Second,
IdleTimeout: 60 * time.Second, IdleTimeout: 60 * time.Second,
} }
return func() error { return func() error {
log.Print("starting job 'http'\n") log.Print("starting job 'http'\n")