diff --git a/db/db.go b/db/db.go index b39345a..2b62017 100644 --- a/db/db.go +++ b/db/db.go @@ -563,7 +563,7 @@ type EditMediaData struct { ID int `json:"id"` Resolution media.Resolution `json:"resolution"` TargetDir string `json:"target_dir"` - Limiter *schema.MediaLimiter `json:"limiter"` + Limiter schema.MediaLimiter `json:"limiter"` } func (c *Client) EditMediaMetadata(in EditMediaData) error { diff --git a/ent/media.go b/ent/media.go index 08acf93..1873d72 100644 --- a/ent/media.go +++ b/ent/media.go @@ -46,7 +46,7 @@ type Media struct { // tv series only DownloadHistoryEpisodes bool `json:"download_history_episodes,omitempty"` // Limiter holds the value of the "limiter" field. - Limiter *schema.MediaLimiter `json:"limiter,omitempty"` + Limiter schema.MediaLimiter `json:"limiter,omitempty"` // Edges holds the relations/edges for other nodes in the graph. // The values are being populated by the MediaQuery when eager-loading is set. Edges MediaEdges `json:"edges"` diff --git a/ent/media_create.go b/ent/media_create.go index bf70d62..e6ae0eb 100644 --- a/ent/media_create.go +++ b/ent/media_create.go @@ -157,11 +157,19 @@ func (mc *MediaCreate) SetNillableDownloadHistoryEpisodes(b *bool) *MediaCreate } // SetLimiter sets the "limiter" field. -func (mc *MediaCreate) SetLimiter(sl *schema.MediaLimiter) *MediaCreate { +func (mc *MediaCreate) SetLimiter(sl schema.MediaLimiter) *MediaCreate { mc.mutation.SetLimiter(sl) return mc } +// SetNillableLimiter sets the "limiter" field if the given value is not nil. +func (mc *MediaCreate) SetNillableLimiter(sl *schema.MediaLimiter) *MediaCreate { + if sl != nil { + mc.SetLimiter(*sl) + } + return mc +} + // AddEpisodeIDs adds the "episodes" edge to the Episode entity by IDs. func (mc *MediaCreate) AddEpisodeIDs(ids ...int) *MediaCreate { mc.mutation.AddEpisodeIDs(ids...) diff --git a/ent/media_update.go b/ent/media_update.go index 29d746a..65fcb51 100644 --- a/ent/media_update.go +++ b/ent/media_update.go @@ -251,11 +251,19 @@ func (mu *MediaUpdate) ClearDownloadHistoryEpisodes() *MediaUpdate { } // SetLimiter sets the "limiter" field. -func (mu *MediaUpdate) SetLimiter(sl *schema.MediaLimiter) *MediaUpdate { +func (mu *MediaUpdate) SetLimiter(sl schema.MediaLimiter) *MediaUpdate { mu.mutation.SetLimiter(sl) return mu } +// SetNillableLimiter sets the "limiter" field if the given value is not nil. +func (mu *MediaUpdate) SetNillableLimiter(sl *schema.MediaLimiter) *MediaUpdate { + if sl != nil { + mu.SetLimiter(*sl) + } + return mu +} + // ClearLimiter clears the value of the "limiter" field. func (mu *MediaUpdate) ClearLimiter() *MediaUpdate { mu.mutation.ClearLimiter() @@ -706,11 +714,19 @@ func (muo *MediaUpdateOne) ClearDownloadHistoryEpisodes() *MediaUpdateOne { } // SetLimiter sets the "limiter" field. -func (muo *MediaUpdateOne) SetLimiter(sl *schema.MediaLimiter) *MediaUpdateOne { +func (muo *MediaUpdateOne) SetLimiter(sl schema.MediaLimiter) *MediaUpdateOne { muo.mutation.SetLimiter(sl) return muo } +// SetNillableLimiter sets the "limiter" field if the given value is not nil. +func (muo *MediaUpdateOne) SetNillableLimiter(sl *schema.MediaLimiter) *MediaUpdateOne { + if sl != nil { + muo.SetLimiter(*sl) + } + return muo +} + // ClearLimiter clears the value of the "limiter" field. func (muo *MediaUpdateOne) ClearLimiter() *MediaUpdateOne { muo.mutation.ClearLimiter() diff --git a/ent/mutation.go b/ent/mutation.go index e801820..8825486 100644 --- a/ent/mutation.go +++ b/ent/mutation.go @@ -3601,7 +3601,7 @@ type MediaMutation struct { addstorage_id *int target_dir *string download_history_episodes *bool - limiter **schema.MediaLimiter + limiter *schema.MediaLimiter clearedFields map[string]struct{} episodes map[int]struct{} removedepisodes map[int]struct{} @@ -4271,12 +4271,12 @@ func (m *MediaMutation) ResetDownloadHistoryEpisodes() { } // SetLimiter sets the "limiter" field. -func (m *MediaMutation) SetLimiter(sl *schema.MediaLimiter) { +func (m *MediaMutation) SetLimiter(sl schema.MediaLimiter) { m.limiter = &sl } // Limiter returns the value of the "limiter" field in the mutation. -func (m *MediaMutation) Limiter() (r *schema.MediaLimiter, exists bool) { +func (m *MediaMutation) Limiter() (r schema.MediaLimiter, exists bool) { v := m.limiter if v == nil { return @@ -4287,7 +4287,7 @@ func (m *MediaMutation) Limiter() (r *schema.MediaLimiter, exists bool) { // OldLimiter returns the old "limiter" field's value of the Media entity. // If the Media object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. -func (m *MediaMutation) OldLimiter(ctx context.Context) (v *schema.MediaLimiter, err error) { +func (m *MediaMutation) OldLimiter(ctx context.Context) (v schema.MediaLimiter, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldLimiter is only allowed on UpdateOne operations") } @@ -4624,7 +4624,7 @@ func (m *MediaMutation) SetField(name string, value ent.Value) error { m.SetDownloadHistoryEpisodes(v) return nil case media.FieldLimiter: - v, ok := value.(*schema.MediaLimiter) + v, ok := value.(schema.MediaLimiter) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } diff --git a/ent/schema/media.go b/ent/schema/media.go index 880258a..b605fe0 100644 --- a/ent/schema/media.go +++ b/ent/schema/media.go @@ -29,7 +29,7 @@ func (Media) Fields() []ent.Field { field.Int("storage_id").Optional(), field.String("target_dir").Optional(), field.Bool("download_history_episodes").Optional().Default(false).Comment("tv series only"), - field.JSON("limiter", &MediaLimiter{}).Optional(), + field.JSON("limiter", MediaLimiter{}).Optional(), } } diff --git a/server/core/torrent.go b/server/core/torrent.go index 640361f..9bbf9c7 100644 --- a/server/core/torrent.go +++ b/server/core/torrent.go @@ -56,7 +56,7 @@ func SearchTvSeries(db1 *db.Client, seriesId, seasonNum int, episodes []int, che continue } - if checkFileSize && series.Limiter != nil { + if checkFileSize { if series.Limiter.SizeMin > 0 && r.Size < series.Limiter.SizeMin { //min size not satified continue @@ -115,7 +115,7 @@ func SearchMovie(db1 *db.Client, movieId int, checkResolution bool, checkFileSiz continue } - if checkFileSize && movieDetail.Limiter != nil { + if checkFileSize { if movieDetail.Limiter.SizeMin > 0 && r.Size < movieDetail.Limiter.SizeMin { //min size not satified continue diff --git a/server/watchlist.go b/server/watchlist.go index ddab964..ca46a3e 100644 --- a/server/watchlist.go +++ b/server/watchlist.go @@ -149,7 +149,7 @@ func (s *Server) AddTv2Watchlist(c *gin.Context) (interface{}, error) { StorageID: in.StorageID, TargetDir: in.Folder, DownloadHistoryEpisodes: in.DownloadHistoryEpisodes, - Limiter: &schema.MediaLimiter{SizeMin: in.SizeMin, SizeMax: in.SizeMax}, + Limiter: schema.MediaLimiter{SizeMin: in.SizeMin, SizeMax: in.SizeMax}, } r, err := s.db.AddMediaWatchlist(m, epIds) @@ -219,7 +219,7 @@ func (s *Server) AddMovie2Watchlist(c *gin.Context) (interface{}, error) { Resolution: media.Resolution(in.Resolution), StorageID: in.StorageID, TargetDir: in.Folder, - Limiter: &schema.MediaLimiter{SizeMin: in.SizeMin, SizeMax: in.SizeMax}, + Limiter: schema.MediaLimiter{SizeMin: in.SizeMin, SizeMax: in.SizeMax}, }, []int{epid}) if err != nil { return nil, errors.Wrap(err, "add to list")