feat: change db

This commit is contained in:
Simon Ding
2024-08-07 10:46:30 +08:00
parent bd385d4f85
commit d8d570f1b2
8 changed files with 39 additions and 15 deletions

View File

@@ -563,7 +563,7 @@ type EditMediaData struct {
ID int `json:"id"` ID int `json:"id"`
Resolution media.Resolution `json:"resolution"` Resolution media.Resolution `json:"resolution"`
TargetDir string `json:"target_dir"` TargetDir string `json:"target_dir"`
Limiter *schema.MediaLimiter `json:"limiter"` Limiter schema.MediaLimiter `json:"limiter"`
} }
func (c *Client) EditMediaMetadata(in EditMediaData) error { func (c *Client) EditMediaMetadata(in EditMediaData) error {

View File

@@ -46,7 +46,7 @@ type Media struct {
// tv series only // tv series only
DownloadHistoryEpisodes bool `json:"download_history_episodes,omitempty"` DownloadHistoryEpisodes bool `json:"download_history_episodes,omitempty"`
// Limiter holds the value of the "limiter" field. // 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. // Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the MediaQuery when eager-loading is set. // The values are being populated by the MediaQuery when eager-loading is set.
Edges MediaEdges `json:"edges"` Edges MediaEdges `json:"edges"`

View File

@@ -157,11 +157,19 @@ func (mc *MediaCreate) SetNillableDownloadHistoryEpisodes(b *bool) *MediaCreate
} }
// SetLimiter sets the "limiter" field. // 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) mc.mutation.SetLimiter(sl)
return mc 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. // AddEpisodeIDs adds the "episodes" edge to the Episode entity by IDs.
func (mc *MediaCreate) AddEpisodeIDs(ids ...int) *MediaCreate { func (mc *MediaCreate) AddEpisodeIDs(ids ...int) *MediaCreate {
mc.mutation.AddEpisodeIDs(ids...) mc.mutation.AddEpisodeIDs(ids...)

View File

@@ -251,11 +251,19 @@ func (mu *MediaUpdate) ClearDownloadHistoryEpisodes() *MediaUpdate {
} }
// SetLimiter sets the "limiter" field. // 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) mu.mutation.SetLimiter(sl)
return mu 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. // ClearLimiter clears the value of the "limiter" field.
func (mu *MediaUpdate) ClearLimiter() *MediaUpdate { func (mu *MediaUpdate) ClearLimiter() *MediaUpdate {
mu.mutation.ClearLimiter() mu.mutation.ClearLimiter()
@@ -706,11 +714,19 @@ func (muo *MediaUpdateOne) ClearDownloadHistoryEpisodes() *MediaUpdateOne {
} }
// SetLimiter sets the "limiter" field. // 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) muo.mutation.SetLimiter(sl)
return muo 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. // ClearLimiter clears the value of the "limiter" field.
func (muo *MediaUpdateOne) ClearLimiter() *MediaUpdateOne { func (muo *MediaUpdateOne) ClearLimiter() *MediaUpdateOne {
muo.mutation.ClearLimiter() muo.mutation.ClearLimiter()

View File

@@ -3601,7 +3601,7 @@ type MediaMutation struct {
addstorage_id *int addstorage_id *int
target_dir *string target_dir *string
download_history_episodes *bool download_history_episodes *bool
limiter **schema.MediaLimiter limiter *schema.MediaLimiter
clearedFields map[string]struct{} clearedFields map[string]struct{}
episodes map[int]struct{} episodes map[int]struct{}
removedepisodes map[int]struct{} removedepisodes map[int]struct{}
@@ -4271,12 +4271,12 @@ func (m *MediaMutation) ResetDownloadHistoryEpisodes() {
} }
// SetLimiter sets the "limiter" field. // SetLimiter sets the "limiter" field.
func (m *MediaMutation) SetLimiter(sl *schema.MediaLimiter) { func (m *MediaMutation) SetLimiter(sl schema.MediaLimiter) {
m.limiter = &sl m.limiter = &sl
} }
// Limiter returns the value of the "limiter" field in the mutation. // 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 v := m.limiter
if v == nil { if v == nil {
return 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. // 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. // 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. // 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) { if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldLimiter is only allowed on UpdateOne operations") 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) m.SetDownloadHistoryEpisodes(v)
return nil return nil
case media.FieldLimiter: case media.FieldLimiter:
v, ok := value.(*schema.MediaLimiter) v, ok := value.(schema.MediaLimiter)
if !ok { if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name) return fmt.Errorf("unexpected type %T for field %s", value, name)
} }

View File

@@ -29,7 +29,7 @@ func (Media) Fields() []ent.Field {
field.Int("storage_id").Optional(), field.Int("storage_id").Optional(),
field.String("target_dir").Optional(), field.String("target_dir").Optional(),
field.Bool("download_history_episodes").Optional().Default(false).Comment("tv series only"), field.Bool("download_history_episodes").Optional().Default(false).Comment("tv series only"),
field.JSON("limiter", &MediaLimiter{}).Optional(), field.JSON("limiter", MediaLimiter{}).Optional(),
} }
} }

View File

@@ -56,7 +56,7 @@ func SearchTvSeries(db1 *db.Client, seriesId, seasonNum int, episodes []int, che
continue continue
} }
if checkFileSize && series.Limiter != nil { if checkFileSize {
if series.Limiter.SizeMin > 0 && r.Size < series.Limiter.SizeMin { if series.Limiter.SizeMin > 0 && r.Size < series.Limiter.SizeMin {
//min size not satified //min size not satified
continue continue
@@ -115,7 +115,7 @@ func SearchMovie(db1 *db.Client, movieId int, checkResolution bool, checkFileSiz
continue continue
} }
if checkFileSize && movieDetail.Limiter != nil { if checkFileSize {
if movieDetail.Limiter.SizeMin > 0 && r.Size < movieDetail.Limiter.SizeMin { if movieDetail.Limiter.SizeMin > 0 && r.Size < movieDetail.Limiter.SizeMin {
//min size not satified //min size not satified
continue continue

View File

@@ -149,7 +149,7 @@ func (s *Server) AddTv2Watchlist(c *gin.Context) (interface{}, error) {
StorageID: in.StorageID, StorageID: in.StorageID,
TargetDir: in.Folder, TargetDir: in.Folder,
DownloadHistoryEpisodes: in.DownloadHistoryEpisodes, 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) 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), Resolution: media.Resolution(in.Resolution),
StorageID: in.StorageID, StorageID: in.StorageID,
TargetDir: in.Folder, TargetDir: in.Folder,
Limiter: &schema.MediaLimiter{SizeMin: in.SizeMin, SizeMax: in.SizeMax}, Limiter: schema.MediaLimiter{SizeMin: in.SizeMin, SizeMax: in.SizeMax},
}, []int{epid}) }, []int{epid})
if err != nil { if err != nil {
return nil, errors.Wrap(err, "add to list") return nil, errors.Wrap(err, "add to list")