feat: support download client priority

This commit is contained in:
Simon Ding
2024-10-04 11:12:06 +08:00
parent 7dfa4eafc4
commit 3af5f96cb0
13 changed files with 172 additions and 155 deletions

View File

@@ -330,18 +330,18 @@ func (c *Client) SaveDownloader(downloader *ent.DownloadClients) error {
count := c.ent.DownloadClients.Query().Where(downloadclients.Name(downloader.Name)).CountX(context.TODO()) count := c.ent.DownloadClients.Query().Where(downloadclients.Name(downloader.Name)).CountX(context.TODO())
if count != 0 { if count != 0 {
err := c.ent.DownloadClients.Update().Where(downloadclients.Name(downloader.Name)).SetImplementation(downloader.Implementation). err := c.ent.DownloadClients.Update().Where(downloadclients.Name(downloader.Name)).SetImplementation(downloader.Implementation).
SetURL(downloader.URL).SetUser(downloader.User).SetPassword(downloader.Password).Exec(context.TODO()) SetURL(downloader.URL).SetUser(downloader.User).SetPassword(downloader.Password).SetPriority1(downloader.Priority1).Exec(context.TODO())
return err return err
} }
_, err := c.ent.DownloadClients.Create().SetEnable(true).SetImplementation(downloader.Implementation). _, err := c.ent.DownloadClients.Create().SetEnable(true).SetImplementation(downloader.Implementation).
SetName(downloader.Name).SetURL(downloader.URL).SetUser(downloader.User).SetPassword(downloader.Password).Save(context.TODO()) SetName(downloader.Name).SetURL(downloader.URL).SetUser(downloader.User).SetPriority1(downloader.Priority1).SetPassword(downloader.Password).Save(context.TODO())
return err return err
} }
func (c *Client) GetAllDonloadClients() []*ent.DownloadClients { func (c *Client) GetAllDonloadClients() []*ent.DownloadClients {
cc, err := c.ent.DownloadClients.Query().Order(ent.Asc(downloadclients.FieldOrdering)).All(context.TODO()) cc, err := c.ent.DownloadClients.Query().Order(ent.Asc(downloadclients.FieldPriority1)).All(context.TODO())
if err != nil { if err != nil {
log.Errorf("no download client") log.Errorf("no download client")
return nil return nil

View File

@@ -30,8 +30,8 @@ type DownloadClients struct {
Password string `json:"password,omitempty"` Password string `json:"password,omitempty"`
// Settings holds the value of the "settings" field. // Settings holds the value of the "settings" field.
Settings string `json:"settings,omitempty"` Settings string `json:"settings,omitempty"`
// Ordering holds the value of the "ordering" field. // Priority1 holds the value of the "priority1" field.
Ordering int `json:"ordering,omitempty"` Priority1 int `json:"priority1,omitempty"`
// RemoveCompletedDownloads holds the value of the "remove_completed_downloads" field. // RemoveCompletedDownloads holds the value of the "remove_completed_downloads" field.
RemoveCompletedDownloads bool `json:"remove_completed_downloads,omitempty"` RemoveCompletedDownloads bool `json:"remove_completed_downloads,omitempty"`
// RemoveFailedDownloads holds the value of the "remove_failed_downloads" field. // RemoveFailedDownloads holds the value of the "remove_failed_downloads" field.
@@ -48,7 +48,7 @@ func (*DownloadClients) scanValues(columns []string) ([]any, error) {
switch columns[i] { switch columns[i] {
case downloadclients.FieldEnable, downloadclients.FieldRemoveCompletedDownloads, downloadclients.FieldRemoveFailedDownloads: case downloadclients.FieldEnable, downloadclients.FieldRemoveCompletedDownloads, downloadclients.FieldRemoveFailedDownloads:
values[i] = new(sql.NullBool) values[i] = new(sql.NullBool)
case downloadclients.FieldID, downloadclients.FieldOrdering: case downloadclients.FieldID, downloadclients.FieldPriority1:
values[i] = new(sql.NullInt64) values[i] = new(sql.NullInt64)
case downloadclients.FieldName, downloadclients.FieldImplementation, downloadclients.FieldURL, downloadclients.FieldUser, downloadclients.FieldPassword, downloadclients.FieldSettings, downloadclients.FieldTags: case downloadclients.FieldName, downloadclients.FieldImplementation, downloadclients.FieldURL, downloadclients.FieldUser, downloadclients.FieldPassword, downloadclients.FieldSettings, downloadclients.FieldTags:
values[i] = new(sql.NullString) values[i] = new(sql.NullString)
@@ -115,11 +115,11 @@ func (dc *DownloadClients) assignValues(columns []string, values []any) error {
} else if value.Valid { } else if value.Valid {
dc.Settings = value.String dc.Settings = value.String
} }
case downloadclients.FieldOrdering: case downloadclients.FieldPriority1:
if value, ok := values[i].(*sql.NullInt64); !ok { if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field ordering", values[i]) return fmt.Errorf("unexpected type %T for field priority1", values[i])
} else if value.Valid { } else if value.Valid {
dc.Ordering = int(value.Int64) dc.Priority1 = int(value.Int64)
} }
case downloadclients.FieldRemoveCompletedDownloads: case downloadclients.FieldRemoveCompletedDownloads:
if value, ok := values[i].(*sql.NullBool); !ok { if value, ok := values[i].(*sql.NullBool); !ok {
@@ -196,8 +196,8 @@ func (dc *DownloadClients) String() string {
builder.WriteString("settings=") builder.WriteString("settings=")
builder.WriteString(dc.Settings) builder.WriteString(dc.Settings)
builder.WriteString(", ") builder.WriteString(", ")
builder.WriteString("ordering=") builder.WriteString("priority1=")
builder.WriteString(fmt.Sprintf("%v", dc.Ordering)) builder.WriteString(fmt.Sprintf("%v", dc.Priority1))
builder.WriteString(", ") builder.WriteString(", ")
builder.WriteString("remove_completed_downloads=") builder.WriteString("remove_completed_downloads=")
builder.WriteString(fmt.Sprintf("%v", dc.RemoveCompletedDownloads)) builder.WriteString(fmt.Sprintf("%v", dc.RemoveCompletedDownloads))

View File

@@ -27,8 +27,8 @@ const (
FieldPassword = "password" FieldPassword = "password"
// FieldSettings holds the string denoting the settings field in the database. // FieldSettings holds the string denoting the settings field in the database.
FieldSettings = "settings" FieldSettings = "settings"
// FieldOrdering holds the string denoting the ordering field in the database. // FieldPriority1 holds the string denoting the priority1 field in the database.
FieldOrdering = "ordering" FieldPriority1 = "priority1"
// FieldRemoveCompletedDownloads holds the string denoting the remove_completed_downloads field in the database. // FieldRemoveCompletedDownloads holds the string denoting the remove_completed_downloads field in the database.
FieldRemoveCompletedDownloads = "remove_completed_downloads" FieldRemoveCompletedDownloads = "remove_completed_downloads"
// FieldRemoveFailedDownloads holds the string denoting the remove_failed_downloads field in the database. // FieldRemoveFailedDownloads holds the string denoting the remove_failed_downloads field in the database.
@@ -49,7 +49,7 @@ var Columns = []string{
FieldUser, FieldUser,
FieldPassword, FieldPassword,
FieldSettings, FieldSettings,
FieldOrdering, FieldPriority1,
FieldRemoveCompletedDownloads, FieldRemoveCompletedDownloads,
FieldRemoveFailedDownloads, FieldRemoveFailedDownloads,
FieldTags, FieldTags,
@@ -72,10 +72,10 @@ var (
DefaultPassword string DefaultPassword string
// DefaultSettings holds the default value on creation for the "settings" field. // DefaultSettings holds the default value on creation for the "settings" field.
DefaultSettings string DefaultSettings string
// DefaultOrdering holds the default value on creation for the "ordering" field. // DefaultPriority1 holds the default value on creation for the "priority1" field.
DefaultOrdering int DefaultPriority1 int
// OrderingValidator is a validator for the "ordering" field. It is called by the builders before save. // Priority1Validator is a validator for the "priority1" field. It is called by the builders before save.
OrderingValidator func(int) error Priority1Validator func(int) error
// DefaultRemoveCompletedDownloads holds the default value on creation for the "remove_completed_downloads" field. // DefaultRemoveCompletedDownloads holds the default value on creation for the "remove_completed_downloads" field.
DefaultRemoveCompletedDownloads bool DefaultRemoveCompletedDownloads bool
// DefaultRemoveFailedDownloads holds the default value on creation for the "remove_failed_downloads" field. // DefaultRemoveFailedDownloads holds the default value on creation for the "remove_failed_downloads" field.
@@ -150,9 +150,9 @@ func BySettings(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldSettings, opts...).ToFunc() return sql.OrderByField(FieldSettings, opts...).ToFunc()
} }
// ByOrdering orders the results by the ordering field. // ByPriority1 orders the results by the priority1 field.
func ByOrdering(opts ...sql.OrderTermOption) OrderOption { func ByPriority1(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldOrdering, opts...).ToFunc() return sql.OrderByField(FieldPriority1, opts...).ToFunc()
} }
// ByRemoveCompletedDownloads orders the results by the remove_completed_downloads field. // ByRemoveCompletedDownloads orders the results by the remove_completed_downloads field.

View File

@@ -83,9 +83,9 @@ func Settings(v string) predicate.DownloadClients {
return predicate.DownloadClients(sql.FieldEQ(FieldSettings, v)) return predicate.DownloadClients(sql.FieldEQ(FieldSettings, v))
} }
// Ordering applies equality check predicate on the "ordering" field. It's identical to OrderingEQ. // Priority1 applies equality check predicate on the "priority1" field. It's identical to Priority1EQ.
func Ordering(v int) predicate.DownloadClients { func Priority1(v int) predicate.DownloadClients {
return predicate.DownloadClients(sql.FieldEQ(FieldOrdering, v)) return predicate.DownloadClients(sql.FieldEQ(FieldPriority1, v))
} }
// RemoveCompletedDownloads applies equality check predicate on the "remove_completed_downloads" field. It's identical to RemoveCompletedDownloadsEQ. // RemoveCompletedDownloads applies equality check predicate on the "remove_completed_downloads" field. It's identical to RemoveCompletedDownloadsEQ.
@@ -458,44 +458,44 @@ func SettingsContainsFold(v string) predicate.DownloadClients {
return predicate.DownloadClients(sql.FieldContainsFold(FieldSettings, v)) return predicate.DownloadClients(sql.FieldContainsFold(FieldSettings, v))
} }
// OrderingEQ applies the EQ predicate on the "ordering" field. // Priority1EQ applies the EQ predicate on the "priority1" field.
func OrderingEQ(v int) predicate.DownloadClients { func Priority1EQ(v int) predicate.DownloadClients {
return predicate.DownloadClients(sql.FieldEQ(FieldOrdering, v)) return predicate.DownloadClients(sql.FieldEQ(FieldPriority1, v))
} }
// OrderingNEQ applies the NEQ predicate on the "ordering" field. // Priority1NEQ applies the NEQ predicate on the "priority1" field.
func OrderingNEQ(v int) predicate.DownloadClients { func Priority1NEQ(v int) predicate.DownloadClients {
return predicate.DownloadClients(sql.FieldNEQ(FieldOrdering, v)) return predicate.DownloadClients(sql.FieldNEQ(FieldPriority1, v))
} }
// OrderingIn applies the In predicate on the "ordering" field. // Priority1In applies the In predicate on the "priority1" field.
func OrderingIn(vs ...int) predicate.DownloadClients { func Priority1In(vs ...int) predicate.DownloadClients {
return predicate.DownloadClients(sql.FieldIn(FieldOrdering, vs...)) return predicate.DownloadClients(sql.FieldIn(FieldPriority1, vs...))
} }
// OrderingNotIn applies the NotIn predicate on the "ordering" field. // Priority1NotIn applies the NotIn predicate on the "priority1" field.
func OrderingNotIn(vs ...int) predicate.DownloadClients { func Priority1NotIn(vs ...int) predicate.DownloadClients {
return predicate.DownloadClients(sql.FieldNotIn(FieldOrdering, vs...)) return predicate.DownloadClients(sql.FieldNotIn(FieldPriority1, vs...))
} }
// OrderingGT applies the GT predicate on the "ordering" field. // Priority1GT applies the GT predicate on the "priority1" field.
func OrderingGT(v int) predicate.DownloadClients { func Priority1GT(v int) predicate.DownloadClients {
return predicate.DownloadClients(sql.FieldGT(FieldOrdering, v)) return predicate.DownloadClients(sql.FieldGT(FieldPriority1, v))
} }
// OrderingGTE applies the GTE predicate on the "ordering" field. // Priority1GTE applies the GTE predicate on the "priority1" field.
func OrderingGTE(v int) predicate.DownloadClients { func Priority1GTE(v int) predicate.DownloadClients {
return predicate.DownloadClients(sql.FieldGTE(FieldOrdering, v)) return predicate.DownloadClients(sql.FieldGTE(FieldPriority1, v))
} }
// OrderingLT applies the LT predicate on the "ordering" field. // Priority1LT applies the LT predicate on the "priority1" field.
func OrderingLT(v int) predicate.DownloadClients { func Priority1LT(v int) predicate.DownloadClients {
return predicate.DownloadClients(sql.FieldLT(FieldOrdering, v)) return predicate.DownloadClients(sql.FieldLT(FieldPriority1, v))
} }
// OrderingLTE applies the LTE predicate on the "ordering" field. // Priority1LTE applies the LTE predicate on the "priority1" field.
func OrderingLTE(v int) predicate.DownloadClients { func Priority1LTE(v int) predicate.DownloadClients {
return predicate.DownloadClients(sql.FieldLTE(FieldOrdering, v)) return predicate.DownloadClients(sql.FieldLTE(FieldPriority1, v))
} }
// RemoveCompletedDownloadsEQ applies the EQ predicate on the "remove_completed_downloads" field. // RemoveCompletedDownloadsEQ applies the EQ predicate on the "remove_completed_downloads" field.

View File

@@ -85,16 +85,16 @@ func (dcc *DownloadClientsCreate) SetNillableSettings(s *string) *DownloadClient
return dcc return dcc
} }
// SetOrdering sets the "ordering" field. // SetPriority1 sets the "priority1" field.
func (dcc *DownloadClientsCreate) SetOrdering(i int) *DownloadClientsCreate { func (dcc *DownloadClientsCreate) SetPriority1(i int) *DownloadClientsCreate {
dcc.mutation.SetOrdering(i) dcc.mutation.SetPriority1(i)
return dcc return dcc
} }
// SetNillableOrdering sets the "ordering" field if the given value is not nil. // SetNillablePriority1 sets the "priority1" field if the given value is not nil.
func (dcc *DownloadClientsCreate) SetNillableOrdering(i *int) *DownloadClientsCreate { func (dcc *DownloadClientsCreate) SetNillablePriority1(i *int) *DownloadClientsCreate {
if i != nil { if i != nil {
dcc.SetOrdering(*i) dcc.SetPriority1(*i)
} }
return dcc return dcc
} }
@@ -188,9 +188,9 @@ func (dcc *DownloadClientsCreate) defaults() {
v := downloadclients.DefaultSettings v := downloadclients.DefaultSettings
dcc.mutation.SetSettings(v) dcc.mutation.SetSettings(v)
} }
if _, ok := dcc.mutation.Ordering(); !ok { if _, ok := dcc.mutation.Priority1(); !ok {
v := downloadclients.DefaultOrdering v := downloadclients.DefaultPriority1
dcc.mutation.SetOrdering(v) dcc.mutation.SetPriority1(v)
} }
if _, ok := dcc.mutation.RemoveCompletedDownloads(); !ok { if _, ok := dcc.mutation.RemoveCompletedDownloads(); !ok {
v := downloadclients.DefaultRemoveCompletedDownloads v := downloadclients.DefaultRemoveCompletedDownloads
@@ -234,12 +234,12 @@ func (dcc *DownloadClientsCreate) check() error {
if _, ok := dcc.mutation.Settings(); !ok { if _, ok := dcc.mutation.Settings(); !ok {
return &ValidationError{Name: "settings", err: errors.New(`ent: missing required field "DownloadClients.settings"`)} return &ValidationError{Name: "settings", err: errors.New(`ent: missing required field "DownloadClients.settings"`)}
} }
if _, ok := dcc.mutation.Ordering(); !ok { if _, ok := dcc.mutation.Priority1(); !ok {
return &ValidationError{Name: "ordering", err: errors.New(`ent: missing required field "DownloadClients.ordering"`)} return &ValidationError{Name: "priority1", err: errors.New(`ent: missing required field "DownloadClients.priority1"`)}
} }
if v, ok := dcc.mutation.Ordering(); ok { if v, ok := dcc.mutation.Priority1(); ok {
if err := downloadclients.OrderingValidator(v); err != nil { if err := downloadclients.Priority1Validator(v); err != nil {
return &ValidationError{Name: "ordering", err: fmt.Errorf(`ent: validator failed for field "DownloadClients.ordering": %w`, err)} return &ValidationError{Name: "priority1", err: fmt.Errorf(`ent: validator failed for field "DownloadClients.priority1": %w`, err)}
} }
} }
if _, ok := dcc.mutation.RemoveCompletedDownloads(); !ok { if _, ok := dcc.mutation.RemoveCompletedDownloads(); !ok {
@@ -305,9 +305,9 @@ func (dcc *DownloadClientsCreate) createSpec() (*DownloadClients, *sqlgraph.Crea
_spec.SetField(downloadclients.FieldSettings, field.TypeString, value) _spec.SetField(downloadclients.FieldSettings, field.TypeString, value)
_node.Settings = value _node.Settings = value
} }
if value, ok := dcc.mutation.Ordering(); ok { if value, ok := dcc.mutation.Priority1(); ok {
_spec.SetField(downloadclients.FieldOrdering, field.TypeInt, value) _spec.SetField(downloadclients.FieldPriority1, field.TypeInt, value)
_node.Ordering = value _node.Priority1 = value
} }
if value, ok := dcc.mutation.RemoveCompletedDownloads(); ok { if value, ok := dcc.mutation.RemoveCompletedDownloads(); ok {
_spec.SetField(downloadclients.FieldRemoveCompletedDownloads, field.TypeBool, value) _spec.SetField(downloadclients.FieldRemoveCompletedDownloads, field.TypeBool, value)

View File

@@ -125,24 +125,24 @@ func (dcu *DownloadClientsUpdate) SetNillableSettings(s *string) *DownloadClient
return dcu return dcu
} }
// SetOrdering sets the "ordering" field. // SetPriority1 sets the "priority1" field.
func (dcu *DownloadClientsUpdate) SetOrdering(i int) *DownloadClientsUpdate { func (dcu *DownloadClientsUpdate) SetPriority1(i int) *DownloadClientsUpdate {
dcu.mutation.ResetOrdering() dcu.mutation.ResetPriority1()
dcu.mutation.SetOrdering(i) dcu.mutation.SetPriority1(i)
return dcu return dcu
} }
// SetNillableOrdering sets the "ordering" field if the given value is not nil. // SetNillablePriority1 sets the "priority1" field if the given value is not nil.
func (dcu *DownloadClientsUpdate) SetNillableOrdering(i *int) *DownloadClientsUpdate { func (dcu *DownloadClientsUpdate) SetNillablePriority1(i *int) *DownloadClientsUpdate {
if i != nil { if i != nil {
dcu.SetOrdering(*i) dcu.SetPriority1(*i)
} }
return dcu return dcu
} }
// AddOrdering adds i to the "ordering" field. // AddPriority1 adds i to the "priority1" field.
func (dcu *DownloadClientsUpdate) AddOrdering(i int) *DownloadClientsUpdate { func (dcu *DownloadClientsUpdate) AddPriority1(i int) *DownloadClientsUpdate {
dcu.mutation.AddOrdering(i) dcu.mutation.AddPriority1(i)
return dcu return dcu
} }
@@ -227,9 +227,9 @@ func (dcu *DownloadClientsUpdate) check() error {
return &ValidationError{Name: "implementation", err: fmt.Errorf(`ent: validator failed for field "DownloadClients.implementation": %w`, err)} return &ValidationError{Name: "implementation", err: fmt.Errorf(`ent: validator failed for field "DownloadClients.implementation": %w`, err)}
} }
} }
if v, ok := dcu.mutation.Ordering(); ok { if v, ok := dcu.mutation.Priority1(); ok {
if err := downloadclients.OrderingValidator(v); err != nil { if err := downloadclients.Priority1Validator(v); err != nil {
return &ValidationError{Name: "ordering", err: fmt.Errorf(`ent: validator failed for field "DownloadClients.ordering": %w`, err)} return &ValidationError{Name: "priority1", err: fmt.Errorf(`ent: validator failed for field "DownloadClients.priority1": %w`, err)}
} }
} }
return nil return nil
@@ -268,11 +268,11 @@ func (dcu *DownloadClientsUpdate) sqlSave(ctx context.Context) (n int, err error
if value, ok := dcu.mutation.Settings(); ok { if value, ok := dcu.mutation.Settings(); ok {
_spec.SetField(downloadclients.FieldSettings, field.TypeString, value) _spec.SetField(downloadclients.FieldSettings, field.TypeString, value)
} }
if value, ok := dcu.mutation.Ordering(); ok { if value, ok := dcu.mutation.Priority1(); ok {
_spec.SetField(downloadclients.FieldOrdering, field.TypeInt, value) _spec.SetField(downloadclients.FieldPriority1, field.TypeInt, value)
} }
if value, ok := dcu.mutation.AddedOrdering(); ok { if value, ok := dcu.mutation.AddedPriority1(); ok {
_spec.AddField(downloadclients.FieldOrdering, field.TypeInt, value) _spec.AddField(downloadclients.FieldPriority1, field.TypeInt, value)
} }
if value, ok := dcu.mutation.RemoveCompletedDownloads(); ok { if value, ok := dcu.mutation.RemoveCompletedDownloads(); ok {
_spec.SetField(downloadclients.FieldRemoveCompletedDownloads, field.TypeBool, value) _spec.SetField(downloadclients.FieldRemoveCompletedDownloads, field.TypeBool, value)
@@ -401,24 +401,24 @@ func (dcuo *DownloadClientsUpdateOne) SetNillableSettings(s *string) *DownloadCl
return dcuo return dcuo
} }
// SetOrdering sets the "ordering" field. // SetPriority1 sets the "priority1" field.
func (dcuo *DownloadClientsUpdateOne) SetOrdering(i int) *DownloadClientsUpdateOne { func (dcuo *DownloadClientsUpdateOne) SetPriority1(i int) *DownloadClientsUpdateOne {
dcuo.mutation.ResetOrdering() dcuo.mutation.ResetPriority1()
dcuo.mutation.SetOrdering(i) dcuo.mutation.SetPriority1(i)
return dcuo return dcuo
} }
// SetNillableOrdering sets the "ordering" field if the given value is not nil. // SetNillablePriority1 sets the "priority1" field if the given value is not nil.
func (dcuo *DownloadClientsUpdateOne) SetNillableOrdering(i *int) *DownloadClientsUpdateOne { func (dcuo *DownloadClientsUpdateOne) SetNillablePriority1(i *int) *DownloadClientsUpdateOne {
if i != nil { if i != nil {
dcuo.SetOrdering(*i) dcuo.SetPriority1(*i)
} }
return dcuo return dcuo
} }
// AddOrdering adds i to the "ordering" field. // AddPriority1 adds i to the "priority1" field.
func (dcuo *DownloadClientsUpdateOne) AddOrdering(i int) *DownloadClientsUpdateOne { func (dcuo *DownloadClientsUpdateOne) AddPriority1(i int) *DownloadClientsUpdateOne {
dcuo.mutation.AddOrdering(i) dcuo.mutation.AddPriority1(i)
return dcuo return dcuo
} }
@@ -516,9 +516,9 @@ func (dcuo *DownloadClientsUpdateOne) check() error {
return &ValidationError{Name: "implementation", err: fmt.Errorf(`ent: validator failed for field "DownloadClients.implementation": %w`, err)} return &ValidationError{Name: "implementation", err: fmt.Errorf(`ent: validator failed for field "DownloadClients.implementation": %w`, err)}
} }
} }
if v, ok := dcuo.mutation.Ordering(); ok { if v, ok := dcuo.mutation.Priority1(); ok {
if err := downloadclients.OrderingValidator(v); err != nil { if err := downloadclients.Priority1Validator(v); err != nil {
return &ValidationError{Name: "ordering", err: fmt.Errorf(`ent: validator failed for field "DownloadClients.ordering": %w`, err)} return &ValidationError{Name: "priority1", err: fmt.Errorf(`ent: validator failed for field "DownloadClients.priority1": %w`, err)}
} }
} }
return nil return nil
@@ -574,11 +574,11 @@ func (dcuo *DownloadClientsUpdateOne) sqlSave(ctx context.Context) (_node *Downl
if value, ok := dcuo.mutation.Settings(); ok { if value, ok := dcuo.mutation.Settings(); ok {
_spec.SetField(downloadclients.FieldSettings, field.TypeString, value) _spec.SetField(downloadclients.FieldSettings, field.TypeString, value)
} }
if value, ok := dcuo.mutation.Ordering(); ok { if value, ok := dcuo.mutation.Priority1(); ok {
_spec.SetField(downloadclients.FieldOrdering, field.TypeInt, value) _spec.SetField(downloadclients.FieldPriority1, field.TypeInt, value)
} }
if value, ok := dcuo.mutation.AddedOrdering(); ok { if value, ok := dcuo.mutation.AddedPriority1(); ok {
_spec.AddField(downloadclients.FieldOrdering, field.TypeInt, value) _spec.AddField(downloadclients.FieldPriority1, field.TypeInt, value)
} }
if value, ok := dcuo.mutation.RemoveCompletedDownloads(); ok { if value, ok := dcuo.mutation.RemoveCompletedDownloads(); ok {
_spec.SetField(downloadclients.FieldRemoveCompletedDownloads, field.TypeBool, value) _spec.SetField(downloadclients.FieldRemoveCompletedDownloads, field.TypeBool, value)

View File

@@ -30,7 +30,7 @@ var (
{Name: "user", Type: field.TypeString, Default: ""}, {Name: "user", Type: field.TypeString, Default: ""},
{Name: "password", Type: field.TypeString, Default: ""}, {Name: "password", Type: field.TypeString, Default: ""},
{Name: "settings", Type: field.TypeString, Default: ""}, {Name: "settings", Type: field.TypeString, Default: ""},
{Name: "ordering", Type: field.TypeInt, Default: 1}, {Name: "priority1", Type: field.TypeInt, Default: 1},
{Name: "remove_completed_downloads", Type: field.TypeBool, Default: true}, {Name: "remove_completed_downloads", Type: field.TypeBool, Default: true},
{Name: "remove_failed_downloads", Type: field.TypeBool, Default: true}, {Name: "remove_failed_downloads", Type: field.TypeBool, Default: true},
{Name: "tags", Type: field.TypeString, Default: ""}, {Name: "tags", Type: field.TypeString, Default: ""},

View File

@@ -439,8 +439,8 @@ type DownloadClientsMutation struct {
user *string user *string
password *string password *string
settings *string settings *string
ordering *int priority1 *int
addordering *int addpriority1 *int
remove_completed_downloads *bool remove_completed_downloads *bool
remove_failed_downloads *bool remove_failed_downloads *bool
tags *string tags *string
@@ -800,60 +800,60 @@ func (m *DownloadClientsMutation) ResetSettings() {
m.settings = nil m.settings = nil
} }
// SetOrdering sets the "ordering" field. // SetPriority1 sets the "priority1" field.
func (m *DownloadClientsMutation) SetOrdering(i int) { func (m *DownloadClientsMutation) SetPriority1(i int) {
m.ordering = &i m.priority1 = &i
m.addordering = nil m.addpriority1 = nil
} }
// Ordering returns the value of the "ordering" field in the mutation. // Priority1 returns the value of the "priority1" field in the mutation.
func (m *DownloadClientsMutation) Ordering() (r int, exists bool) { func (m *DownloadClientsMutation) Priority1() (r int, exists bool) {
v := m.ordering v := m.priority1
if v == nil { if v == nil {
return return
} }
return *v, true return *v, true
} }
// OldOrdering returns the old "ordering" field's value of the DownloadClients entity. // OldPriority1 returns the old "priority1" field's value of the DownloadClients entity.
// If the DownloadClients object wasn't provided to the builder, the object is fetched from the database. // If the DownloadClients 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 *DownloadClientsMutation) OldOrdering(ctx context.Context) (v int, err error) { func (m *DownloadClientsMutation) OldPriority1(ctx context.Context) (v int, err error) {
if !m.op.Is(OpUpdateOne) { if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldOrdering is only allowed on UpdateOne operations") return v, errors.New("OldPriority1 is only allowed on UpdateOne operations")
} }
if m.id == nil || m.oldValue == nil { if m.id == nil || m.oldValue == nil {
return v, errors.New("OldOrdering requires an ID field in the mutation") return v, errors.New("OldPriority1 requires an ID field in the mutation")
} }
oldValue, err := m.oldValue(ctx) oldValue, err := m.oldValue(ctx)
if err != nil { if err != nil {
return v, fmt.Errorf("querying old value for OldOrdering: %w", err) return v, fmt.Errorf("querying old value for OldPriority1: %w", err)
} }
return oldValue.Ordering, nil return oldValue.Priority1, nil
} }
// AddOrdering adds i to the "ordering" field. // AddPriority1 adds i to the "priority1" field.
func (m *DownloadClientsMutation) AddOrdering(i int) { func (m *DownloadClientsMutation) AddPriority1(i int) {
if m.addordering != nil { if m.addpriority1 != nil {
*m.addordering += i *m.addpriority1 += i
} else { } else {
m.addordering = &i m.addpriority1 = &i
} }
} }
// AddedOrdering returns the value that was added to the "ordering" field in this mutation. // AddedPriority1 returns the value that was added to the "priority1" field in this mutation.
func (m *DownloadClientsMutation) AddedOrdering() (r int, exists bool) { func (m *DownloadClientsMutation) AddedPriority1() (r int, exists bool) {
v := m.addordering v := m.addpriority1
if v == nil { if v == nil {
return return
} }
return *v, true return *v, true
} }
// ResetOrdering resets all changes to the "ordering" field. // ResetPriority1 resets all changes to the "priority1" field.
func (m *DownloadClientsMutation) ResetOrdering() { func (m *DownloadClientsMutation) ResetPriority1() {
m.ordering = nil m.priority1 = nil
m.addordering = nil m.addpriority1 = nil
} }
// SetRemoveCompletedDownloads sets the "remove_completed_downloads" field. // SetRemoveCompletedDownloads sets the "remove_completed_downloads" field.
@@ -1020,8 +1020,8 @@ func (m *DownloadClientsMutation) Fields() []string {
if m.settings != nil { if m.settings != nil {
fields = append(fields, downloadclients.FieldSettings) fields = append(fields, downloadclients.FieldSettings)
} }
if m.ordering != nil { if m.priority1 != nil {
fields = append(fields, downloadclients.FieldOrdering) fields = append(fields, downloadclients.FieldPriority1)
} }
if m.remove_completed_downloads != nil { if m.remove_completed_downloads != nil {
fields = append(fields, downloadclients.FieldRemoveCompletedDownloads) fields = append(fields, downloadclients.FieldRemoveCompletedDownloads)
@@ -1054,8 +1054,8 @@ func (m *DownloadClientsMutation) Field(name string) (ent.Value, bool) {
return m.Password() return m.Password()
case downloadclients.FieldSettings: case downloadclients.FieldSettings:
return m.Settings() return m.Settings()
case downloadclients.FieldOrdering: case downloadclients.FieldPriority1:
return m.Ordering() return m.Priority1()
case downloadclients.FieldRemoveCompletedDownloads: case downloadclients.FieldRemoveCompletedDownloads:
return m.RemoveCompletedDownloads() return m.RemoveCompletedDownloads()
case downloadclients.FieldRemoveFailedDownloads: case downloadclients.FieldRemoveFailedDownloads:
@@ -1085,8 +1085,8 @@ func (m *DownloadClientsMutation) OldField(ctx context.Context, name string) (en
return m.OldPassword(ctx) return m.OldPassword(ctx)
case downloadclients.FieldSettings: case downloadclients.FieldSettings:
return m.OldSettings(ctx) return m.OldSettings(ctx)
case downloadclients.FieldOrdering: case downloadclients.FieldPriority1:
return m.OldOrdering(ctx) return m.OldPriority1(ctx)
case downloadclients.FieldRemoveCompletedDownloads: case downloadclients.FieldRemoveCompletedDownloads:
return m.OldRemoveCompletedDownloads(ctx) return m.OldRemoveCompletedDownloads(ctx)
case downloadclients.FieldRemoveFailedDownloads: case downloadclients.FieldRemoveFailedDownloads:
@@ -1151,12 +1151,12 @@ func (m *DownloadClientsMutation) SetField(name string, value ent.Value) error {
} }
m.SetSettings(v) m.SetSettings(v)
return nil return nil
case downloadclients.FieldOrdering: case downloadclients.FieldPriority1:
v, ok := value.(int) v, ok := value.(int)
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)
} }
m.SetOrdering(v) m.SetPriority1(v)
return nil return nil
case downloadclients.FieldRemoveCompletedDownloads: case downloadclients.FieldRemoveCompletedDownloads:
v, ok := value.(bool) v, ok := value.(bool)
@@ -1187,8 +1187,8 @@ func (m *DownloadClientsMutation) SetField(name string, value ent.Value) error {
// this mutation. // this mutation.
func (m *DownloadClientsMutation) AddedFields() []string { func (m *DownloadClientsMutation) AddedFields() []string {
var fields []string var fields []string
if m.addordering != nil { if m.addpriority1 != nil {
fields = append(fields, downloadclients.FieldOrdering) fields = append(fields, downloadclients.FieldPriority1)
} }
return fields return fields
} }
@@ -1198,8 +1198,8 @@ func (m *DownloadClientsMutation) AddedFields() []string {
// was not set, or was not defined in the schema. // was not set, or was not defined in the schema.
func (m *DownloadClientsMutation) AddedField(name string) (ent.Value, bool) { func (m *DownloadClientsMutation) AddedField(name string) (ent.Value, bool) {
switch name { switch name {
case downloadclients.FieldOrdering: case downloadclients.FieldPriority1:
return m.AddedOrdering() return m.AddedPriority1()
} }
return nil, false return nil, false
} }
@@ -1209,12 +1209,12 @@ func (m *DownloadClientsMutation) AddedField(name string) (ent.Value, bool) {
// type. // type.
func (m *DownloadClientsMutation) AddField(name string, value ent.Value) error { func (m *DownloadClientsMutation) AddField(name string, value ent.Value) error {
switch name { switch name {
case downloadclients.FieldOrdering: case downloadclients.FieldPriority1:
v, ok := value.(int) v, ok := value.(int)
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)
} }
m.AddOrdering(v) m.AddPriority1(v)
return nil return nil
} }
return fmt.Errorf("unknown DownloadClients numeric field %s", name) return fmt.Errorf("unknown DownloadClients numeric field %s", name)
@@ -1264,8 +1264,8 @@ func (m *DownloadClientsMutation) ResetField(name string) error {
case downloadclients.FieldSettings: case downloadclients.FieldSettings:
m.ResetSettings() m.ResetSettings()
return nil return nil
case downloadclients.FieldOrdering: case downloadclients.FieldPriority1:
m.ResetOrdering() m.ResetPriority1()
return nil return nil
case downloadclients.FieldRemoveCompletedDownloads: case downloadclients.FieldRemoveCompletedDownloads:
m.ResetRemoveCompletedDownloads() m.ResetRemoveCompletedDownloads()

View File

@@ -32,12 +32,12 @@ func init() {
downloadclientsDescSettings := downloadclientsFields[6].Descriptor() downloadclientsDescSettings := downloadclientsFields[6].Descriptor()
// downloadclients.DefaultSettings holds the default value on creation for the settings field. // downloadclients.DefaultSettings holds the default value on creation for the settings field.
downloadclients.DefaultSettings = downloadclientsDescSettings.Default.(string) downloadclients.DefaultSettings = downloadclientsDescSettings.Default.(string)
// downloadclientsDescOrdering is the schema descriptor for ordering field. // downloadclientsDescPriority1 is the schema descriptor for priority1 field.
downloadclientsDescOrdering := downloadclientsFields[7].Descriptor() downloadclientsDescPriority1 := downloadclientsFields[7].Descriptor()
// downloadclients.DefaultOrdering holds the default value on creation for the ordering field. // downloadclients.DefaultPriority1 holds the default value on creation for the priority1 field.
downloadclients.DefaultOrdering = downloadclientsDescOrdering.Default.(int) downloadclients.DefaultPriority1 = downloadclientsDescPriority1.Default.(int)
// downloadclients.OrderingValidator is a validator for the "ordering" field. It is called by the builders before save. // downloadclients.Priority1Validator is a validator for the "priority1" field. It is called by the builders before save.
downloadclients.OrderingValidator = downloadclientsDescOrdering.Validators[0].(func(int) error) downloadclients.Priority1Validator = downloadclientsDescPriority1.Validators[0].(func(int) error)
// downloadclientsDescRemoveCompletedDownloads is the schema descriptor for remove_completed_downloads field. // downloadclientsDescRemoveCompletedDownloads is the schema descriptor for remove_completed_downloads field.
downloadclientsDescRemoveCompletedDownloads := downloadclientsFields[8].Descriptor() downloadclientsDescRemoveCompletedDownloads := downloadclientsFields[8].Descriptor()
// downloadclients.DefaultRemoveCompletedDownloads holds the default value on creation for the remove_completed_downloads field. // downloadclients.DefaultRemoveCompletedDownloads holds the default value on creation for the remove_completed_downloads field.

View File

@@ -22,7 +22,7 @@ func (DownloadClients) Fields() []ent.Field {
field.String("user").Default(""), field.String("user").Default(""),
field.String("password").Default(""), field.String("password").Default(""),
field.String("settings").Default(""), field.String("settings").Default(""),
field.Int("ordering").Default(1).Validate(func(i int) error { field.Int("priority1").Default(1).Validate(func(i int) error {
if i > 50 { if i > 50 {
return errors.ErrUnsupported return errors.ErrUnsupported
} }

View File

@@ -191,12 +191,14 @@ func (s *Server) GetAllIndexers(c *gin.Context) (interface{}, error) {
} }
return indexers, nil return indexers, nil
} }
type downloadClientIn struct { type downloadClientIn struct {
Name string `json:"name" binding:"required"` Name string `json:"name" binding:"required"`
URL string `json:"url" binding:"required"` URL string `json:"url" binding:"required"`
User string `json:"user"` User string `json:"user"`
Password string `json:"password"` Password string `json:"password"`
Implementation string `json:"implementation" binding:"required"` Implementation string `json:"implementation" binding:"required"`
Priority int `json:"priority"`
} }
func (s *Server) AddDownloadClient(c *gin.Context) (interface{}, error) { func (s *Server) AddDownloadClient(c *gin.Context) (interface{}, error) {
@@ -205,6 +207,9 @@ func (s *Server) AddDownloadClient(c *gin.Context) (interface{}, error) {
return nil, errors.Wrap(err, "bind json") return nil, errors.Wrap(err, "bind json")
} }
utils.TrimFields(&in) utils.TrimFields(&in)
if in.Priority == 0 {
in.Priority = 1 //make default
}
//test connection //test connection
if in.Implementation == downloadclients.ImplementationTransmission.String() { if in.Implementation == downloadclients.ImplementationTransmission.String() {
_, err := transmission.NewClient(transmission.Config{ _, err := transmission.NewClient(transmission.Config{
@@ -225,6 +230,7 @@ func (s *Server) AddDownloadClient(c *gin.Context) (interface{}, error) {
if err := s.db.SaveDownloader(&ent.DownloadClients{ if err := s.db.SaveDownloader(&ent.DownloadClients{
Name: in.Name, Name: in.Name,
Implementation: downloadclients.Implementation(in.Implementation), Implementation: downloadclients.Implementation(in.Implementation),
Priority1: in.Priority,
URL: in.URL, URL: in.URL,
User: in.User, User: in.User,
Password: in.Password, Password: in.Password,

View File

@@ -243,6 +243,7 @@ class DownloadClient {
String? password; String? password;
bool? removeCompletedDownloads; bool? removeCompletedDownloads;
bool? removeFailedDownloads; bool? removeFailedDownloads;
int? priority;
DownloadClient( DownloadClient(
{this.id, {this.id,
this.enable, this.enable,
@@ -252,6 +253,7 @@ class DownloadClient {
this.user, this.user,
this.password, this.password,
this.removeCompletedDownloads = true, this.removeCompletedDownloads = true,
this.priority = 1,
this.removeFailedDownloads = true}); this.removeFailedDownloads = true});
DownloadClient.fromJson(Map<String, dynamic> json) { DownloadClient.fromJson(Map<String, dynamic> json) {
@@ -262,6 +264,7 @@ class DownloadClient {
url = json['url']; url = json['url'];
user = json['user']; user = json['user'];
password = json['password']; password = json['password'];
priority = json["priority1"];
removeCompletedDownloads = json["remove_completed_downloads"] ?? false; removeCompletedDownloads = json["remove_completed_downloads"] ?? false;
removeFailedDownloads = json["remove_failed_downloads"] ?? false; removeFailedDownloads = json["remove_failed_downloads"] ?? false;
} }
@@ -275,6 +278,7 @@ class DownloadClient {
data['url'] = url; data['url'] = url;
data['user'] = user; data['user'] = user;
data['password'] = password; data['password'] = password;
data["priority"] = priority;
data["remove_completed_downloads"] = removeCompletedDownloads; data["remove_completed_downloads"] = removeCompletedDownloads;
data["remove_failed_downloads"] = removeFailedDownloads; data["remove_failed_downloads"] = removeFailedDownloads;
return data; return data;

View File

@@ -56,6 +56,7 @@ class _DownloaderState extends ConsumerState<DownloaderSettings> {
"impl": client.implementation, "impl": client.implementation,
"remove_completed_downloads": client.removeCompletedDownloads, "remove_completed_downloads": client.removeCompletedDownloads,
"remove_failed_downloads": client.removeFailedDownloads, "remove_failed_downloads": client.removeFailedDownloads,
"priority": client.priority.toString(),
}, },
child: Column( child: Column(
children: [ children: [
@@ -86,6 +87,11 @@ class _DownloaderState extends ConsumerState<DownloaderSettings> {
autovalidateMode: AutovalidateMode.onUserInteraction, autovalidateMode: AutovalidateMode.onUserInteraction,
validator: FormBuilderValidators.required(), validator: FormBuilderValidators.required(),
), ),
FormBuilderTextField(
name: "priority",
decoration: const InputDecoration(labelText: "优先级", helperText: "1-50, 1最高优先级50最低优先级"),
validator: FormBuilderValidators.integer(),
autovalidateMode: AutovalidateMode.onUserInteraction),
FormBuilderSwitch( FormBuilderSwitch(
name: "remove_completed_downloads", name: "remove_completed_downloads",
title: const Text("任务完成后删除")), title: const Text("任务完成后删除")),
@@ -148,6 +154,7 @@ class _DownloaderState extends ConsumerState<DownloaderSettings> {
url: values["url"], url: values["url"],
user: _enableAuth ? values["user"] : null, user: _enableAuth ? values["user"] : null,
password: _enableAuth ? values["password"] : null, password: _enableAuth ? values["password"] : null,
priority: int.parse(values["priority"]),
removeCompletedDownloads: values["remove_completed_downloads"], removeCompletedDownloads: values["remove_completed_downloads"],
removeFailedDownloads: values["remove_failed_downloads"])); removeFailedDownloads: values["remove_failed_downloads"]));
} else { } else {