mirror of
https://github.com/simon-ding/polaris.git
synced 2026-02-06 15:10:49 +08:00
feat: prowlarr refactor and support prowlarr seed ratio
This commit is contained in:
65
db/db.go
65
db/db.go
@@ -38,13 +38,14 @@ func Open() (*Client, error) {
|
||||
return nil, errors.Wrap(err, "failed opening connection to sqlite")
|
||||
}
|
||||
//defer client.Close()
|
||||
// Run the auto migration tool.
|
||||
if err := client.Schema.Create(context.Background()); err != nil {
|
||||
return nil, errors.Wrap(err, "failed creating schema resources")
|
||||
}
|
||||
c := &Client{
|
||||
ent: client,
|
||||
}
|
||||
// Run the auto migration tool.
|
||||
if err := c.migrate(); err != nil {
|
||||
return nil, errors.Wrap(err, "migrate")
|
||||
}
|
||||
|
||||
c.init()
|
||||
|
||||
return c, nil
|
||||
@@ -265,20 +266,22 @@ type TorznabSetting struct {
|
||||
|
||||
func (c *Client) SaveIndexer(in *ent.Indexers) error {
|
||||
|
||||
if in.ID != 0 {
|
||||
count := c.ent.Indexers.Query().Where(indexers.Name(in.Name)).CountX(context.TODO())
|
||||
|
||||
if count > 0 || in.ID != 0 {
|
||||
//update setting
|
||||
return c.ent.Indexers.Update().Where(indexers.ID(in.ID)).SetName(in.Name).SetImplementation(in.Implementation).
|
||||
SetPriority(in.Priority).SetSettings(in.Settings).SetSeedRatio(in.SeedRatio).SetDisabled(in.Disabled).Exec(context.Background())
|
||||
SetPriority(in.Priority).SetSeedRatio(in.SeedRatio).SetDisabled(in.Disabled).
|
||||
SetTvSearch(in.TvSearch).SetMovieSearch(in.MovieSearch).SetSettings("").SetSynced(in.Synced).
|
||||
SetAPIKey(in.APIKey).SetURL(in.URL).
|
||||
Exec(context.Background())
|
||||
}
|
||||
//create new one
|
||||
count := c.ent.Indexers.Query().Where(indexers.Name(in.Name)).CountX(context.TODO())
|
||||
if count > 0 {
|
||||
return fmt.Errorf("name already esxits: %v", in.Name)
|
||||
}
|
||||
|
||||
_, err := c.ent.Indexers.Create().
|
||||
SetName(in.Name).SetImplementation(in.Implementation).SetPriority(in.Priority).SetSettings(in.Settings).SetSeedRatio(in.SeedRatio).
|
||||
SetDisabled(in.Disabled).Save(context.TODO())
|
||||
SetName(in.Name).SetImplementation(in.Implementation).SetPriority(in.Priority).SetSeedRatio(in.SeedRatio).
|
||||
SetTvSearch(in.TvSearch).SetMovieSearch(in.MovieSearch).SetSettings("").SetSynced(in.Synced).
|
||||
SetAPIKey(in.APIKey).SetURL(in.URL).SetDisabled(in.Disabled).Save(context.TODO())
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "save db")
|
||||
}
|
||||
@@ -286,46 +289,21 @@ func (c *Client) SaveIndexer(in *ent.Indexers) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Client) DeleteTorznab(id int) {
|
||||
func (c *Client) DeleteIndexer(id int) {
|
||||
c.ent.Indexers.Delete().Where(indexers.ID(id)).Exec(context.TODO())
|
||||
}
|
||||
|
||||
func (c *Client) GetIndexer(id int) (*TorznabInfo, error) {
|
||||
func (c *Client) GetIndexer(id int) (*ent.Indexers, error) {
|
||||
res, err := c.ent.Indexers.Query().Where(indexers.ID(id)).First(context.TODO())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var ss TorznabSetting
|
||||
err = json.Unmarshal([]byte(res.Settings), &ss)
|
||||
if err != nil {
|
||||
|
||||
return nil, fmt.Errorf("unmarshal torznab %s error: %v", res.Name, err)
|
||||
}
|
||||
return &TorznabInfo{Indexers: res, TorznabSetting: ss}, nil
|
||||
return res, nil
|
||||
}
|
||||
|
||||
type TorznabInfo struct {
|
||||
*ent.Indexers
|
||||
TorznabSetting
|
||||
}
|
||||
|
||||
func (c *Client) GetAllTorznabInfo() []*TorznabInfo {
|
||||
res := c.ent.Indexers.Query().Where(indexers.Implementation(IndexerTorznabImpl)).AllX(context.TODO())
|
||||
|
||||
var l = make([]*TorznabInfo, 0, len(res))
|
||||
for _, r := range res {
|
||||
var ss TorznabSetting
|
||||
err := json.Unmarshal([]byte(r.Settings), &ss)
|
||||
if err != nil {
|
||||
log.Errorf("unmarshal torznab %s error: %v", r.Name, err)
|
||||
continue
|
||||
}
|
||||
l = append(l, &TorznabInfo{
|
||||
Indexers: r,
|
||||
TorznabSetting: ss,
|
||||
})
|
||||
}
|
||||
return l
|
||||
func (c *Client) GetAllIndexers() []*ent.Indexers {
|
||||
res := c.ent.Indexers.Query().Where(indexers.Implementation(IndexerTorznabImpl)).Order(ent.Asc(indexers.FieldID)).AllX(context.TODO())
|
||||
return res
|
||||
}
|
||||
|
||||
func (c *Client) SaveDownloader(downloader *ent.DownloadClients) error {
|
||||
@@ -712,7 +690,6 @@ func (c *Client) SaveProwlarrSetting(se *ProwlarrSetting) error {
|
||||
return c.SetSetting(SettingProwlarrInfo, string(data))
|
||||
}
|
||||
|
||||
|
||||
func (c *Client) getAcceptedFormats(key string) ([]string, error) {
|
||||
v := c.GetSetting(key)
|
||||
if v == "" {
|
||||
|
||||
46
db/migrate.go
Normal file
46
db/migrate.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"polaris/log"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func (c *Client) migrate() error {
|
||||
// Run the auto migration tool.
|
||||
if err := c.ent.Schema.Create(context.Background()); err != nil {
|
||||
return errors.Wrap(err, "failed creating schema resources")
|
||||
}
|
||||
|
||||
if err := c.migrateIndexerSetting(); err != nil {
|
||||
return errors.Wrap(err, "migrate indexer setting")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Client) migrateIndexerSetting() error {
|
||||
indexers := c.GetAllIndexers()
|
||||
for _, in := range indexers {
|
||||
|
||||
if in.Settings == "" {
|
||||
continue
|
||||
}
|
||||
if in.APIKey != "" && in.URL != "" {
|
||||
continue
|
||||
}
|
||||
var setting TorznabSetting
|
||||
err := json.Unmarshal([]byte(in.Settings), &setting)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
in.APIKey = setting.ApiKey
|
||||
in.URL = setting.URL
|
||||
if err := c.SaveIndexer(in); err != nil {
|
||||
return errors.Wrap(err, "save indexer")
|
||||
}
|
||||
log.Infof("success migrate indexer setting field: %s", in.Name)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -20,7 +20,7 @@ type Indexers struct {
|
||||
Name string `json:"name,omitempty"`
|
||||
// Implementation holds the value of the "implementation" field.
|
||||
Implementation string `json:"implementation,omitempty"`
|
||||
// Settings holds the value of the "settings" field.
|
||||
// deprecated, use api_key and url
|
||||
Settings string `json:"settings,omitempty"`
|
||||
// EnableRss holds the value of the "enable_rss" field.
|
||||
EnableRss bool `json:"enable_rss,omitempty"`
|
||||
@@ -30,6 +30,16 @@ type Indexers struct {
|
||||
SeedRatio float32 `json:"seed_ratio,omitempty"`
|
||||
// Disabled holds the value of the "disabled" field.
|
||||
Disabled bool `json:"disabled,omitempty"`
|
||||
// TvSearch holds the value of the "tv_search" field.
|
||||
TvSearch bool `json:"tv_search,omitempty"`
|
||||
// MovieSearch holds the value of the "movie_search" field.
|
||||
MovieSearch bool `json:"movie_search,omitempty"`
|
||||
// APIKey holds the value of the "api_key" field.
|
||||
APIKey string `json:"api_key,omitempty"`
|
||||
// URL holds the value of the "url" field.
|
||||
URL string `json:"url,omitempty"`
|
||||
// synced from prowlarr
|
||||
Synced bool `json:"synced,omitempty"`
|
||||
selectValues sql.SelectValues
|
||||
}
|
||||
|
||||
@@ -38,13 +48,13 @@ func (*Indexers) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case indexers.FieldEnableRss, indexers.FieldDisabled:
|
||||
case indexers.FieldEnableRss, indexers.FieldDisabled, indexers.FieldTvSearch, indexers.FieldMovieSearch, indexers.FieldSynced:
|
||||
values[i] = new(sql.NullBool)
|
||||
case indexers.FieldSeedRatio:
|
||||
values[i] = new(sql.NullFloat64)
|
||||
case indexers.FieldID, indexers.FieldPriority:
|
||||
values[i] = new(sql.NullInt64)
|
||||
case indexers.FieldName, indexers.FieldImplementation, indexers.FieldSettings:
|
||||
case indexers.FieldName, indexers.FieldImplementation, indexers.FieldSettings, indexers.FieldAPIKey, indexers.FieldURL:
|
||||
values[i] = new(sql.NullString)
|
||||
default:
|
||||
values[i] = new(sql.UnknownType)
|
||||
@@ -109,6 +119,36 @@ func (i *Indexers) assignValues(columns []string, values []any) error {
|
||||
} else if value.Valid {
|
||||
i.Disabled = value.Bool
|
||||
}
|
||||
case indexers.FieldTvSearch:
|
||||
if value, ok := values[j].(*sql.NullBool); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field tv_search", values[j])
|
||||
} else if value.Valid {
|
||||
i.TvSearch = value.Bool
|
||||
}
|
||||
case indexers.FieldMovieSearch:
|
||||
if value, ok := values[j].(*sql.NullBool); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field movie_search", values[j])
|
||||
} else if value.Valid {
|
||||
i.MovieSearch = value.Bool
|
||||
}
|
||||
case indexers.FieldAPIKey:
|
||||
if value, ok := values[j].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field api_key", values[j])
|
||||
} else if value.Valid {
|
||||
i.APIKey = value.String
|
||||
}
|
||||
case indexers.FieldURL:
|
||||
if value, ok := values[j].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field url", values[j])
|
||||
} else if value.Valid {
|
||||
i.URL = value.String
|
||||
}
|
||||
case indexers.FieldSynced:
|
||||
if value, ok := values[j].(*sql.NullBool); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field synced", values[j])
|
||||
} else if value.Valid {
|
||||
i.Synced = value.Bool
|
||||
}
|
||||
default:
|
||||
i.selectValues.Set(columns[j], values[j])
|
||||
}
|
||||
@@ -165,6 +205,21 @@ func (i *Indexers) String() string {
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("disabled=")
|
||||
builder.WriteString(fmt.Sprintf("%v", i.Disabled))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("tv_search=")
|
||||
builder.WriteString(fmt.Sprintf("%v", i.TvSearch))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("movie_search=")
|
||||
builder.WriteString(fmt.Sprintf("%v", i.MovieSearch))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("api_key=")
|
||||
builder.WriteString(i.APIKey)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("url=")
|
||||
builder.WriteString(i.URL)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("synced=")
|
||||
builder.WriteString(fmt.Sprintf("%v", i.Synced))
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
@@ -25,6 +25,16 @@ const (
|
||||
FieldSeedRatio = "seed_ratio"
|
||||
// FieldDisabled holds the string denoting the disabled field in the database.
|
||||
FieldDisabled = "disabled"
|
||||
// FieldTvSearch holds the string denoting the tv_search field in the database.
|
||||
FieldTvSearch = "tv_search"
|
||||
// FieldMovieSearch holds the string denoting the movie_search field in the database.
|
||||
FieldMovieSearch = "movie_search"
|
||||
// FieldAPIKey holds the string denoting the api_key field in the database.
|
||||
FieldAPIKey = "api_key"
|
||||
// FieldURL holds the string denoting the url field in the database.
|
||||
FieldURL = "url"
|
||||
// FieldSynced holds the string denoting the synced field in the database.
|
||||
FieldSynced = "synced"
|
||||
// Table holds the table name of the indexers in the database.
|
||||
Table = "indexers"
|
||||
)
|
||||
@@ -39,6 +49,11 @@ var Columns = []string{
|
||||
FieldPriority,
|
||||
FieldSeedRatio,
|
||||
FieldDisabled,
|
||||
FieldTvSearch,
|
||||
FieldMovieSearch,
|
||||
FieldAPIKey,
|
||||
FieldURL,
|
||||
FieldSynced,
|
||||
}
|
||||
|
||||
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||
@@ -52,6 +67,8 @@ func ValidColumn(column string) bool {
|
||||
}
|
||||
|
||||
var (
|
||||
// DefaultSettings holds the default value on creation for the "settings" field.
|
||||
DefaultSettings string
|
||||
// DefaultEnableRss holds the default value on creation for the "enable_rss" field.
|
||||
DefaultEnableRss bool
|
||||
// DefaultPriority holds the default value on creation for the "priority" field.
|
||||
@@ -60,6 +77,12 @@ var (
|
||||
DefaultSeedRatio float32
|
||||
// DefaultDisabled holds the default value on creation for the "disabled" field.
|
||||
DefaultDisabled bool
|
||||
// DefaultTvSearch holds the default value on creation for the "tv_search" field.
|
||||
DefaultTvSearch bool
|
||||
// DefaultMovieSearch holds the default value on creation for the "movie_search" field.
|
||||
DefaultMovieSearch bool
|
||||
// DefaultSynced holds the default value on creation for the "synced" field.
|
||||
DefaultSynced bool
|
||||
)
|
||||
|
||||
// OrderOption defines the ordering options for the Indexers queries.
|
||||
@@ -104,3 +127,28 @@ func BySeedRatio(opts ...sql.OrderTermOption) OrderOption {
|
||||
func ByDisabled(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldDisabled, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByTvSearch orders the results by the tv_search field.
|
||||
func ByTvSearch(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldTvSearch, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByMovieSearch orders the results by the movie_search field.
|
||||
func ByMovieSearch(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldMovieSearch, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByAPIKey orders the results by the api_key field.
|
||||
func ByAPIKey(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldAPIKey, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByURL orders the results by the url field.
|
||||
func ByURL(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldURL, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// BySynced orders the results by the synced field.
|
||||
func BySynced(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldSynced, opts...).ToFunc()
|
||||
}
|
||||
|
||||
@@ -88,6 +88,31 @@ func Disabled(v bool) predicate.Indexers {
|
||||
return predicate.Indexers(sql.FieldEQ(FieldDisabled, v))
|
||||
}
|
||||
|
||||
// TvSearch applies equality check predicate on the "tv_search" field. It's identical to TvSearchEQ.
|
||||
func TvSearch(v bool) predicate.Indexers {
|
||||
return predicate.Indexers(sql.FieldEQ(FieldTvSearch, v))
|
||||
}
|
||||
|
||||
// MovieSearch applies equality check predicate on the "movie_search" field. It's identical to MovieSearchEQ.
|
||||
func MovieSearch(v bool) predicate.Indexers {
|
||||
return predicate.Indexers(sql.FieldEQ(FieldMovieSearch, v))
|
||||
}
|
||||
|
||||
// APIKey applies equality check predicate on the "api_key" field. It's identical to APIKeyEQ.
|
||||
func APIKey(v string) predicate.Indexers {
|
||||
return predicate.Indexers(sql.FieldEQ(FieldAPIKey, v))
|
||||
}
|
||||
|
||||
// URL applies equality check predicate on the "url" field. It's identical to URLEQ.
|
||||
func URL(v string) predicate.Indexers {
|
||||
return predicate.Indexers(sql.FieldEQ(FieldURL, v))
|
||||
}
|
||||
|
||||
// Synced applies equality check predicate on the "synced" field. It's identical to SyncedEQ.
|
||||
func Synced(v bool) predicate.Indexers {
|
||||
return predicate.Indexers(sql.FieldEQ(FieldSynced, v))
|
||||
}
|
||||
|
||||
// NameEQ applies the EQ predicate on the "name" field.
|
||||
func NameEQ(v string) predicate.Indexers {
|
||||
return predicate.Indexers(sql.FieldEQ(FieldName, v))
|
||||
@@ -273,6 +298,16 @@ func SettingsHasSuffix(v string) predicate.Indexers {
|
||||
return predicate.Indexers(sql.FieldHasSuffix(FieldSettings, v))
|
||||
}
|
||||
|
||||
// SettingsIsNil applies the IsNil predicate on the "settings" field.
|
||||
func SettingsIsNil() predicate.Indexers {
|
||||
return predicate.Indexers(sql.FieldIsNull(FieldSettings))
|
||||
}
|
||||
|
||||
// SettingsNotNil applies the NotNil predicate on the "settings" field.
|
||||
func SettingsNotNil() predicate.Indexers {
|
||||
return predicate.Indexers(sql.FieldNotNull(FieldSettings))
|
||||
}
|
||||
|
||||
// SettingsEqualFold applies the EqualFold predicate on the "settings" field.
|
||||
func SettingsEqualFold(v string) predicate.Indexers {
|
||||
return predicate.Indexers(sql.FieldEqualFold(FieldSettings, v))
|
||||
@@ -403,6 +438,216 @@ func DisabledNotNil() predicate.Indexers {
|
||||
return predicate.Indexers(sql.FieldNotNull(FieldDisabled))
|
||||
}
|
||||
|
||||
// TvSearchEQ applies the EQ predicate on the "tv_search" field.
|
||||
func TvSearchEQ(v bool) predicate.Indexers {
|
||||
return predicate.Indexers(sql.FieldEQ(FieldTvSearch, v))
|
||||
}
|
||||
|
||||
// TvSearchNEQ applies the NEQ predicate on the "tv_search" field.
|
||||
func TvSearchNEQ(v bool) predicate.Indexers {
|
||||
return predicate.Indexers(sql.FieldNEQ(FieldTvSearch, v))
|
||||
}
|
||||
|
||||
// TvSearchIsNil applies the IsNil predicate on the "tv_search" field.
|
||||
func TvSearchIsNil() predicate.Indexers {
|
||||
return predicate.Indexers(sql.FieldIsNull(FieldTvSearch))
|
||||
}
|
||||
|
||||
// TvSearchNotNil applies the NotNil predicate on the "tv_search" field.
|
||||
func TvSearchNotNil() predicate.Indexers {
|
||||
return predicate.Indexers(sql.FieldNotNull(FieldTvSearch))
|
||||
}
|
||||
|
||||
// MovieSearchEQ applies the EQ predicate on the "movie_search" field.
|
||||
func MovieSearchEQ(v bool) predicate.Indexers {
|
||||
return predicate.Indexers(sql.FieldEQ(FieldMovieSearch, v))
|
||||
}
|
||||
|
||||
// MovieSearchNEQ applies the NEQ predicate on the "movie_search" field.
|
||||
func MovieSearchNEQ(v bool) predicate.Indexers {
|
||||
return predicate.Indexers(sql.FieldNEQ(FieldMovieSearch, v))
|
||||
}
|
||||
|
||||
// MovieSearchIsNil applies the IsNil predicate on the "movie_search" field.
|
||||
func MovieSearchIsNil() predicate.Indexers {
|
||||
return predicate.Indexers(sql.FieldIsNull(FieldMovieSearch))
|
||||
}
|
||||
|
||||
// MovieSearchNotNil applies the NotNil predicate on the "movie_search" field.
|
||||
func MovieSearchNotNil() predicate.Indexers {
|
||||
return predicate.Indexers(sql.FieldNotNull(FieldMovieSearch))
|
||||
}
|
||||
|
||||
// APIKeyEQ applies the EQ predicate on the "api_key" field.
|
||||
func APIKeyEQ(v string) predicate.Indexers {
|
||||
return predicate.Indexers(sql.FieldEQ(FieldAPIKey, v))
|
||||
}
|
||||
|
||||
// APIKeyNEQ applies the NEQ predicate on the "api_key" field.
|
||||
func APIKeyNEQ(v string) predicate.Indexers {
|
||||
return predicate.Indexers(sql.FieldNEQ(FieldAPIKey, v))
|
||||
}
|
||||
|
||||
// APIKeyIn applies the In predicate on the "api_key" field.
|
||||
func APIKeyIn(vs ...string) predicate.Indexers {
|
||||
return predicate.Indexers(sql.FieldIn(FieldAPIKey, vs...))
|
||||
}
|
||||
|
||||
// APIKeyNotIn applies the NotIn predicate on the "api_key" field.
|
||||
func APIKeyNotIn(vs ...string) predicate.Indexers {
|
||||
return predicate.Indexers(sql.FieldNotIn(FieldAPIKey, vs...))
|
||||
}
|
||||
|
||||
// APIKeyGT applies the GT predicate on the "api_key" field.
|
||||
func APIKeyGT(v string) predicate.Indexers {
|
||||
return predicate.Indexers(sql.FieldGT(FieldAPIKey, v))
|
||||
}
|
||||
|
||||
// APIKeyGTE applies the GTE predicate on the "api_key" field.
|
||||
func APIKeyGTE(v string) predicate.Indexers {
|
||||
return predicate.Indexers(sql.FieldGTE(FieldAPIKey, v))
|
||||
}
|
||||
|
||||
// APIKeyLT applies the LT predicate on the "api_key" field.
|
||||
func APIKeyLT(v string) predicate.Indexers {
|
||||
return predicate.Indexers(sql.FieldLT(FieldAPIKey, v))
|
||||
}
|
||||
|
||||
// APIKeyLTE applies the LTE predicate on the "api_key" field.
|
||||
func APIKeyLTE(v string) predicate.Indexers {
|
||||
return predicate.Indexers(sql.FieldLTE(FieldAPIKey, v))
|
||||
}
|
||||
|
||||
// APIKeyContains applies the Contains predicate on the "api_key" field.
|
||||
func APIKeyContains(v string) predicate.Indexers {
|
||||
return predicate.Indexers(sql.FieldContains(FieldAPIKey, v))
|
||||
}
|
||||
|
||||
// APIKeyHasPrefix applies the HasPrefix predicate on the "api_key" field.
|
||||
func APIKeyHasPrefix(v string) predicate.Indexers {
|
||||
return predicate.Indexers(sql.FieldHasPrefix(FieldAPIKey, v))
|
||||
}
|
||||
|
||||
// APIKeyHasSuffix applies the HasSuffix predicate on the "api_key" field.
|
||||
func APIKeyHasSuffix(v string) predicate.Indexers {
|
||||
return predicate.Indexers(sql.FieldHasSuffix(FieldAPIKey, v))
|
||||
}
|
||||
|
||||
// APIKeyIsNil applies the IsNil predicate on the "api_key" field.
|
||||
func APIKeyIsNil() predicate.Indexers {
|
||||
return predicate.Indexers(sql.FieldIsNull(FieldAPIKey))
|
||||
}
|
||||
|
||||
// APIKeyNotNil applies the NotNil predicate on the "api_key" field.
|
||||
func APIKeyNotNil() predicate.Indexers {
|
||||
return predicate.Indexers(sql.FieldNotNull(FieldAPIKey))
|
||||
}
|
||||
|
||||
// APIKeyEqualFold applies the EqualFold predicate on the "api_key" field.
|
||||
func APIKeyEqualFold(v string) predicate.Indexers {
|
||||
return predicate.Indexers(sql.FieldEqualFold(FieldAPIKey, v))
|
||||
}
|
||||
|
||||
// APIKeyContainsFold applies the ContainsFold predicate on the "api_key" field.
|
||||
func APIKeyContainsFold(v string) predicate.Indexers {
|
||||
return predicate.Indexers(sql.FieldContainsFold(FieldAPIKey, v))
|
||||
}
|
||||
|
||||
// URLEQ applies the EQ predicate on the "url" field.
|
||||
func URLEQ(v string) predicate.Indexers {
|
||||
return predicate.Indexers(sql.FieldEQ(FieldURL, v))
|
||||
}
|
||||
|
||||
// URLNEQ applies the NEQ predicate on the "url" field.
|
||||
func URLNEQ(v string) predicate.Indexers {
|
||||
return predicate.Indexers(sql.FieldNEQ(FieldURL, v))
|
||||
}
|
||||
|
||||
// URLIn applies the In predicate on the "url" field.
|
||||
func URLIn(vs ...string) predicate.Indexers {
|
||||
return predicate.Indexers(sql.FieldIn(FieldURL, vs...))
|
||||
}
|
||||
|
||||
// URLNotIn applies the NotIn predicate on the "url" field.
|
||||
func URLNotIn(vs ...string) predicate.Indexers {
|
||||
return predicate.Indexers(sql.FieldNotIn(FieldURL, vs...))
|
||||
}
|
||||
|
||||
// URLGT applies the GT predicate on the "url" field.
|
||||
func URLGT(v string) predicate.Indexers {
|
||||
return predicate.Indexers(sql.FieldGT(FieldURL, v))
|
||||
}
|
||||
|
||||
// URLGTE applies the GTE predicate on the "url" field.
|
||||
func URLGTE(v string) predicate.Indexers {
|
||||
return predicate.Indexers(sql.FieldGTE(FieldURL, v))
|
||||
}
|
||||
|
||||
// URLLT applies the LT predicate on the "url" field.
|
||||
func URLLT(v string) predicate.Indexers {
|
||||
return predicate.Indexers(sql.FieldLT(FieldURL, v))
|
||||
}
|
||||
|
||||
// URLLTE applies the LTE predicate on the "url" field.
|
||||
func URLLTE(v string) predicate.Indexers {
|
||||
return predicate.Indexers(sql.FieldLTE(FieldURL, v))
|
||||
}
|
||||
|
||||
// URLContains applies the Contains predicate on the "url" field.
|
||||
func URLContains(v string) predicate.Indexers {
|
||||
return predicate.Indexers(sql.FieldContains(FieldURL, v))
|
||||
}
|
||||
|
||||
// URLHasPrefix applies the HasPrefix predicate on the "url" field.
|
||||
func URLHasPrefix(v string) predicate.Indexers {
|
||||
return predicate.Indexers(sql.FieldHasPrefix(FieldURL, v))
|
||||
}
|
||||
|
||||
// URLHasSuffix applies the HasSuffix predicate on the "url" field.
|
||||
func URLHasSuffix(v string) predicate.Indexers {
|
||||
return predicate.Indexers(sql.FieldHasSuffix(FieldURL, v))
|
||||
}
|
||||
|
||||
// URLIsNil applies the IsNil predicate on the "url" field.
|
||||
func URLIsNil() predicate.Indexers {
|
||||
return predicate.Indexers(sql.FieldIsNull(FieldURL))
|
||||
}
|
||||
|
||||
// URLNotNil applies the NotNil predicate on the "url" field.
|
||||
func URLNotNil() predicate.Indexers {
|
||||
return predicate.Indexers(sql.FieldNotNull(FieldURL))
|
||||
}
|
||||
|
||||
// URLEqualFold applies the EqualFold predicate on the "url" field.
|
||||
func URLEqualFold(v string) predicate.Indexers {
|
||||
return predicate.Indexers(sql.FieldEqualFold(FieldURL, v))
|
||||
}
|
||||
|
||||
// URLContainsFold applies the ContainsFold predicate on the "url" field.
|
||||
func URLContainsFold(v string) predicate.Indexers {
|
||||
return predicate.Indexers(sql.FieldContainsFold(FieldURL, v))
|
||||
}
|
||||
|
||||
// SyncedEQ applies the EQ predicate on the "synced" field.
|
||||
func SyncedEQ(v bool) predicate.Indexers {
|
||||
return predicate.Indexers(sql.FieldEQ(FieldSynced, v))
|
||||
}
|
||||
|
||||
// SyncedNEQ applies the NEQ predicate on the "synced" field.
|
||||
func SyncedNEQ(v bool) predicate.Indexers {
|
||||
return predicate.Indexers(sql.FieldNEQ(FieldSynced, v))
|
||||
}
|
||||
|
||||
// SyncedIsNil applies the IsNil predicate on the "synced" field.
|
||||
func SyncedIsNil() predicate.Indexers {
|
||||
return predicate.Indexers(sql.FieldIsNull(FieldSynced))
|
||||
}
|
||||
|
||||
// SyncedNotNil applies the NotNil predicate on the "synced" field.
|
||||
func SyncedNotNil() predicate.Indexers {
|
||||
return predicate.Indexers(sql.FieldNotNull(FieldSynced))
|
||||
}
|
||||
|
||||
// And groups predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.Indexers) predicate.Indexers {
|
||||
return predicate.Indexers(sql.AndPredicates(predicates...))
|
||||
|
||||
@@ -37,6 +37,14 @@ func (ic *IndexersCreate) SetSettings(s string) *IndexersCreate {
|
||||
return ic
|
||||
}
|
||||
|
||||
// SetNillableSettings sets the "settings" field if the given value is not nil.
|
||||
func (ic *IndexersCreate) SetNillableSettings(s *string) *IndexersCreate {
|
||||
if s != nil {
|
||||
ic.SetSettings(*s)
|
||||
}
|
||||
return ic
|
||||
}
|
||||
|
||||
// SetEnableRss sets the "enable_rss" field.
|
||||
func (ic *IndexersCreate) SetEnableRss(b bool) *IndexersCreate {
|
||||
ic.mutation.SetEnableRss(b)
|
||||
@@ -93,6 +101,76 @@ func (ic *IndexersCreate) SetNillableDisabled(b *bool) *IndexersCreate {
|
||||
return ic
|
||||
}
|
||||
|
||||
// SetTvSearch sets the "tv_search" field.
|
||||
func (ic *IndexersCreate) SetTvSearch(b bool) *IndexersCreate {
|
||||
ic.mutation.SetTvSearch(b)
|
||||
return ic
|
||||
}
|
||||
|
||||
// SetNillableTvSearch sets the "tv_search" field if the given value is not nil.
|
||||
func (ic *IndexersCreate) SetNillableTvSearch(b *bool) *IndexersCreate {
|
||||
if b != nil {
|
||||
ic.SetTvSearch(*b)
|
||||
}
|
||||
return ic
|
||||
}
|
||||
|
||||
// SetMovieSearch sets the "movie_search" field.
|
||||
func (ic *IndexersCreate) SetMovieSearch(b bool) *IndexersCreate {
|
||||
ic.mutation.SetMovieSearch(b)
|
||||
return ic
|
||||
}
|
||||
|
||||
// SetNillableMovieSearch sets the "movie_search" field if the given value is not nil.
|
||||
func (ic *IndexersCreate) SetNillableMovieSearch(b *bool) *IndexersCreate {
|
||||
if b != nil {
|
||||
ic.SetMovieSearch(*b)
|
||||
}
|
||||
return ic
|
||||
}
|
||||
|
||||
// SetAPIKey sets the "api_key" field.
|
||||
func (ic *IndexersCreate) SetAPIKey(s string) *IndexersCreate {
|
||||
ic.mutation.SetAPIKey(s)
|
||||
return ic
|
||||
}
|
||||
|
||||
// SetNillableAPIKey sets the "api_key" field if the given value is not nil.
|
||||
func (ic *IndexersCreate) SetNillableAPIKey(s *string) *IndexersCreate {
|
||||
if s != nil {
|
||||
ic.SetAPIKey(*s)
|
||||
}
|
||||
return ic
|
||||
}
|
||||
|
||||
// SetURL sets the "url" field.
|
||||
func (ic *IndexersCreate) SetURL(s string) *IndexersCreate {
|
||||
ic.mutation.SetURL(s)
|
||||
return ic
|
||||
}
|
||||
|
||||
// SetNillableURL sets the "url" field if the given value is not nil.
|
||||
func (ic *IndexersCreate) SetNillableURL(s *string) *IndexersCreate {
|
||||
if s != nil {
|
||||
ic.SetURL(*s)
|
||||
}
|
||||
return ic
|
||||
}
|
||||
|
||||
// SetSynced sets the "synced" field.
|
||||
func (ic *IndexersCreate) SetSynced(b bool) *IndexersCreate {
|
||||
ic.mutation.SetSynced(b)
|
||||
return ic
|
||||
}
|
||||
|
||||
// SetNillableSynced sets the "synced" field if the given value is not nil.
|
||||
func (ic *IndexersCreate) SetNillableSynced(b *bool) *IndexersCreate {
|
||||
if b != nil {
|
||||
ic.SetSynced(*b)
|
||||
}
|
||||
return ic
|
||||
}
|
||||
|
||||
// Mutation returns the IndexersMutation object of the builder.
|
||||
func (ic *IndexersCreate) Mutation() *IndexersMutation {
|
||||
return ic.mutation
|
||||
@@ -128,6 +206,10 @@ func (ic *IndexersCreate) ExecX(ctx context.Context) {
|
||||
|
||||
// defaults sets the default values of the builder before save.
|
||||
func (ic *IndexersCreate) defaults() {
|
||||
if _, ok := ic.mutation.Settings(); !ok {
|
||||
v := indexers.DefaultSettings
|
||||
ic.mutation.SetSettings(v)
|
||||
}
|
||||
if _, ok := ic.mutation.EnableRss(); !ok {
|
||||
v := indexers.DefaultEnableRss
|
||||
ic.mutation.SetEnableRss(v)
|
||||
@@ -144,6 +226,18 @@ func (ic *IndexersCreate) defaults() {
|
||||
v := indexers.DefaultDisabled
|
||||
ic.mutation.SetDisabled(v)
|
||||
}
|
||||
if _, ok := ic.mutation.TvSearch(); !ok {
|
||||
v := indexers.DefaultTvSearch
|
||||
ic.mutation.SetTvSearch(v)
|
||||
}
|
||||
if _, ok := ic.mutation.MovieSearch(); !ok {
|
||||
v := indexers.DefaultMovieSearch
|
||||
ic.mutation.SetMovieSearch(v)
|
||||
}
|
||||
if _, ok := ic.mutation.Synced(); !ok {
|
||||
v := indexers.DefaultSynced
|
||||
ic.mutation.SetSynced(v)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
@@ -154,9 +248,6 @@ func (ic *IndexersCreate) check() error {
|
||||
if _, ok := ic.mutation.Implementation(); !ok {
|
||||
return &ValidationError{Name: "implementation", err: errors.New(`ent: missing required field "Indexers.implementation"`)}
|
||||
}
|
||||
if _, ok := ic.mutation.Settings(); !ok {
|
||||
return &ValidationError{Name: "settings", err: errors.New(`ent: missing required field "Indexers.settings"`)}
|
||||
}
|
||||
if _, ok := ic.mutation.EnableRss(); !ok {
|
||||
return &ValidationError{Name: "enable_rss", err: errors.New(`ent: missing required field "Indexers.enable_rss"`)}
|
||||
}
|
||||
@@ -217,6 +308,26 @@ func (ic *IndexersCreate) createSpec() (*Indexers, *sqlgraph.CreateSpec) {
|
||||
_spec.SetField(indexers.FieldDisabled, field.TypeBool, value)
|
||||
_node.Disabled = value
|
||||
}
|
||||
if value, ok := ic.mutation.TvSearch(); ok {
|
||||
_spec.SetField(indexers.FieldTvSearch, field.TypeBool, value)
|
||||
_node.TvSearch = value
|
||||
}
|
||||
if value, ok := ic.mutation.MovieSearch(); ok {
|
||||
_spec.SetField(indexers.FieldMovieSearch, field.TypeBool, value)
|
||||
_node.MovieSearch = value
|
||||
}
|
||||
if value, ok := ic.mutation.APIKey(); ok {
|
||||
_spec.SetField(indexers.FieldAPIKey, field.TypeString, value)
|
||||
_node.APIKey = value
|
||||
}
|
||||
if value, ok := ic.mutation.URL(); ok {
|
||||
_spec.SetField(indexers.FieldURL, field.TypeString, value)
|
||||
_node.URL = value
|
||||
}
|
||||
if value, ok := ic.mutation.Synced(); ok {
|
||||
_spec.SetField(indexers.FieldSynced, field.TypeBool, value)
|
||||
_node.Synced = value
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
|
||||
@@ -69,6 +69,12 @@ func (iu *IndexersUpdate) SetNillableSettings(s *string) *IndexersUpdate {
|
||||
return iu
|
||||
}
|
||||
|
||||
// ClearSettings clears the value of the "settings" field.
|
||||
func (iu *IndexersUpdate) ClearSettings() *IndexersUpdate {
|
||||
iu.mutation.ClearSettings()
|
||||
return iu
|
||||
}
|
||||
|
||||
// SetEnableRss sets the "enable_rss" field.
|
||||
func (iu *IndexersUpdate) SetEnableRss(b bool) *IndexersUpdate {
|
||||
iu.mutation.SetEnableRss(b)
|
||||
@@ -151,6 +157,106 @@ func (iu *IndexersUpdate) ClearDisabled() *IndexersUpdate {
|
||||
return iu
|
||||
}
|
||||
|
||||
// SetTvSearch sets the "tv_search" field.
|
||||
func (iu *IndexersUpdate) SetTvSearch(b bool) *IndexersUpdate {
|
||||
iu.mutation.SetTvSearch(b)
|
||||
return iu
|
||||
}
|
||||
|
||||
// SetNillableTvSearch sets the "tv_search" field if the given value is not nil.
|
||||
func (iu *IndexersUpdate) SetNillableTvSearch(b *bool) *IndexersUpdate {
|
||||
if b != nil {
|
||||
iu.SetTvSearch(*b)
|
||||
}
|
||||
return iu
|
||||
}
|
||||
|
||||
// ClearTvSearch clears the value of the "tv_search" field.
|
||||
func (iu *IndexersUpdate) ClearTvSearch() *IndexersUpdate {
|
||||
iu.mutation.ClearTvSearch()
|
||||
return iu
|
||||
}
|
||||
|
||||
// SetMovieSearch sets the "movie_search" field.
|
||||
func (iu *IndexersUpdate) SetMovieSearch(b bool) *IndexersUpdate {
|
||||
iu.mutation.SetMovieSearch(b)
|
||||
return iu
|
||||
}
|
||||
|
||||
// SetNillableMovieSearch sets the "movie_search" field if the given value is not nil.
|
||||
func (iu *IndexersUpdate) SetNillableMovieSearch(b *bool) *IndexersUpdate {
|
||||
if b != nil {
|
||||
iu.SetMovieSearch(*b)
|
||||
}
|
||||
return iu
|
||||
}
|
||||
|
||||
// ClearMovieSearch clears the value of the "movie_search" field.
|
||||
func (iu *IndexersUpdate) ClearMovieSearch() *IndexersUpdate {
|
||||
iu.mutation.ClearMovieSearch()
|
||||
return iu
|
||||
}
|
||||
|
||||
// SetAPIKey sets the "api_key" field.
|
||||
func (iu *IndexersUpdate) SetAPIKey(s string) *IndexersUpdate {
|
||||
iu.mutation.SetAPIKey(s)
|
||||
return iu
|
||||
}
|
||||
|
||||
// SetNillableAPIKey sets the "api_key" field if the given value is not nil.
|
||||
func (iu *IndexersUpdate) SetNillableAPIKey(s *string) *IndexersUpdate {
|
||||
if s != nil {
|
||||
iu.SetAPIKey(*s)
|
||||
}
|
||||
return iu
|
||||
}
|
||||
|
||||
// ClearAPIKey clears the value of the "api_key" field.
|
||||
func (iu *IndexersUpdate) ClearAPIKey() *IndexersUpdate {
|
||||
iu.mutation.ClearAPIKey()
|
||||
return iu
|
||||
}
|
||||
|
||||
// SetURL sets the "url" field.
|
||||
func (iu *IndexersUpdate) SetURL(s string) *IndexersUpdate {
|
||||
iu.mutation.SetURL(s)
|
||||
return iu
|
||||
}
|
||||
|
||||
// SetNillableURL sets the "url" field if the given value is not nil.
|
||||
func (iu *IndexersUpdate) SetNillableURL(s *string) *IndexersUpdate {
|
||||
if s != nil {
|
||||
iu.SetURL(*s)
|
||||
}
|
||||
return iu
|
||||
}
|
||||
|
||||
// ClearURL clears the value of the "url" field.
|
||||
func (iu *IndexersUpdate) ClearURL() *IndexersUpdate {
|
||||
iu.mutation.ClearURL()
|
||||
return iu
|
||||
}
|
||||
|
||||
// SetSynced sets the "synced" field.
|
||||
func (iu *IndexersUpdate) SetSynced(b bool) *IndexersUpdate {
|
||||
iu.mutation.SetSynced(b)
|
||||
return iu
|
||||
}
|
||||
|
||||
// SetNillableSynced sets the "synced" field if the given value is not nil.
|
||||
func (iu *IndexersUpdate) SetNillableSynced(b *bool) *IndexersUpdate {
|
||||
if b != nil {
|
||||
iu.SetSynced(*b)
|
||||
}
|
||||
return iu
|
||||
}
|
||||
|
||||
// ClearSynced clears the value of the "synced" field.
|
||||
func (iu *IndexersUpdate) ClearSynced() *IndexersUpdate {
|
||||
iu.mutation.ClearSynced()
|
||||
return iu
|
||||
}
|
||||
|
||||
// Mutation returns the IndexersMutation object of the builder.
|
||||
func (iu *IndexersUpdate) Mutation() *IndexersMutation {
|
||||
return iu.mutation
|
||||
@@ -201,6 +307,9 @@ func (iu *IndexersUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
if value, ok := iu.mutation.Settings(); ok {
|
||||
_spec.SetField(indexers.FieldSettings, field.TypeString, value)
|
||||
}
|
||||
if iu.mutation.SettingsCleared() {
|
||||
_spec.ClearField(indexers.FieldSettings, field.TypeString)
|
||||
}
|
||||
if value, ok := iu.mutation.EnableRss(); ok {
|
||||
_spec.SetField(indexers.FieldEnableRss, field.TypeBool, value)
|
||||
}
|
||||
@@ -225,6 +334,36 @@ func (iu *IndexersUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
if iu.mutation.DisabledCleared() {
|
||||
_spec.ClearField(indexers.FieldDisabled, field.TypeBool)
|
||||
}
|
||||
if value, ok := iu.mutation.TvSearch(); ok {
|
||||
_spec.SetField(indexers.FieldTvSearch, field.TypeBool, value)
|
||||
}
|
||||
if iu.mutation.TvSearchCleared() {
|
||||
_spec.ClearField(indexers.FieldTvSearch, field.TypeBool)
|
||||
}
|
||||
if value, ok := iu.mutation.MovieSearch(); ok {
|
||||
_spec.SetField(indexers.FieldMovieSearch, field.TypeBool, value)
|
||||
}
|
||||
if iu.mutation.MovieSearchCleared() {
|
||||
_spec.ClearField(indexers.FieldMovieSearch, field.TypeBool)
|
||||
}
|
||||
if value, ok := iu.mutation.APIKey(); ok {
|
||||
_spec.SetField(indexers.FieldAPIKey, field.TypeString, value)
|
||||
}
|
||||
if iu.mutation.APIKeyCleared() {
|
||||
_spec.ClearField(indexers.FieldAPIKey, field.TypeString)
|
||||
}
|
||||
if value, ok := iu.mutation.URL(); ok {
|
||||
_spec.SetField(indexers.FieldURL, field.TypeString, value)
|
||||
}
|
||||
if iu.mutation.URLCleared() {
|
||||
_spec.ClearField(indexers.FieldURL, field.TypeString)
|
||||
}
|
||||
if value, ok := iu.mutation.Synced(); ok {
|
||||
_spec.SetField(indexers.FieldSynced, field.TypeBool, value)
|
||||
}
|
||||
if iu.mutation.SyncedCleared() {
|
||||
_spec.ClearField(indexers.FieldSynced, field.TypeBool)
|
||||
}
|
||||
if n, err = sqlgraph.UpdateNodes(ctx, iu.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{indexers.Label}
|
||||
@@ -287,6 +426,12 @@ func (iuo *IndexersUpdateOne) SetNillableSettings(s *string) *IndexersUpdateOne
|
||||
return iuo
|
||||
}
|
||||
|
||||
// ClearSettings clears the value of the "settings" field.
|
||||
func (iuo *IndexersUpdateOne) ClearSettings() *IndexersUpdateOne {
|
||||
iuo.mutation.ClearSettings()
|
||||
return iuo
|
||||
}
|
||||
|
||||
// SetEnableRss sets the "enable_rss" field.
|
||||
func (iuo *IndexersUpdateOne) SetEnableRss(b bool) *IndexersUpdateOne {
|
||||
iuo.mutation.SetEnableRss(b)
|
||||
@@ -369,6 +514,106 @@ func (iuo *IndexersUpdateOne) ClearDisabled() *IndexersUpdateOne {
|
||||
return iuo
|
||||
}
|
||||
|
||||
// SetTvSearch sets the "tv_search" field.
|
||||
func (iuo *IndexersUpdateOne) SetTvSearch(b bool) *IndexersUpdateOne {
|
||||
iuo.mutation.SetTvSearch(b)
|
||||
return iuo
|
||||
}
|
||||
|
||||
// SetNillableTvSearch sets the "tv_search" field if the given value is not nil.
|
||||
func (iuo *IndexersUpdateOne) SetNillableTvSearch(b *bool) *IndexersUpdateOne {
|
||||
if b != nil {
|
||||
iuo.SetTvSearch(*b)
|
||||
}
|
||||
return iuo
|
||||
}
|
||||
|
||||
// ClearTvSearch clears the value of the "tv_search" field.
|
||||
func (iuo *IndexersUpdateOne) ClearTvSearch() *IndexersUpdateOne {
|
||||
iuo.mutation.ClearTvSearch()
|
||||
return iuo
|
||||
}
|
||||
|
||||
// SetMovieSearch sets the "movie_search" field.
|
||||
func (iuo *IndexersUpdateOne) SetMovieSearch(b bool) *IndexersUpdateOne {
|
||||
iuo.mutation.SetMovieSearch(b)
|
||||
return iuo
|
||||
}
|
||||
|
||||
// SetNillableMovieSearch sets the "movie_search" field if the given value is not nil.
|
||||
func (iuo *IndexersUpdateOne) SetNillableMovieSearch(b *bool) *IndexersUpdateOne {
|
||||
if b != nil {
|
||||
iuo.SetMovieSearch(*b)
|
||||
}
|
||||
return iuo
|
||||
}
|
||||
|
||||
// ClearMovieSearch clears the value of the "movie_search" field.
|
||||
func (iuo *IndexersUpdateOne) ClearMovieSearch() *IndexersUpdateOne {
|
||||
iuo.mutation.ClearMovieSearch()
|
||||
return iuo
|
||||
}
|
||||
|
||||
// SetAPIKey sets the "api_key" field.
|
||||
func (iuo *IndexersUpdateOne) SetAPIKey(s string) *IndexersUpdateOne {
|
||||
iuo.mutation.SetAPIKey(s)
|
||||
return iuo
|
||||
}
|
||||
|
||||
// SetNillableAPIKey sets the "api_key" field if the given value is not nil.
|
||||
func (iuo *IndexersUpdateOne) SetNillableAPIKey(s *string) *IndexersUpdateOne {
|
||||
if s != nil {
|
||||
iuo.SetAPIKey(*s)
|
||||
}
|
||||
return iuo
|
||||
}
|
||||
|
||||
// ClearAPIKey clears the value of the "api_key" field.
|
||||
func (iuo *IndexersUpdateOne) ClearAPIKey() *IndexersUpdateOne {
|
||||
iuo.mutation.ClearAPIKey()
|
||||
return iuo
|
||||
}
|
||||
|
||||
// SetURL sets the "url" field.
|
||||
func (iuo *IndexersUpdateOne) SetURL(s string) *IndexersUpdateOne {
|
||||
iuo.mutation.SetURL(s)
|
||||
return iuo
|
||||
}
|
||||
|
||||
// SetNillableURL sets the "url" field if the given value is not nil.
|
||||
func (iuo *IndexersUpdateOne) SetNillableURL(s *string) *IndexersUpdateOne {
|
||||
if s != nil {
|
||||
iuo.SetURL(*s)
|
||||
}
|
||||
return iuo
|
||||
}
|
||||
|
||||
// ClearURL clears the value of the "url" field.
|
||||
func (iuo *IndexersUpdateOne) ClearURL() *IndexersUpdateOne {
|
||||
iuo.mutation.ClearURL()
|
||||
return iuo
|
||||
}
|
||||
|
||||
// SetSynced sets the "synced" field.
|
||||
func (iuo *IndexersUpdateOne) SetSynced(b bool) *IndexersUpdateOne {
|
||||
iuo.mutation.SetSynced(b)
|
||||
return iuo
|
||||
}
|
||||
|
||||
// SetNillableSynced sets the "synced" field if the given value is not nil.
|
||||
func (iuo *IndexersUpdateOne) SetNillableSynced(b *bool) *IndexersUpdateOne {
|
||||
if b != nil {
|
||||
iuo.SetSynced(*b)
|
||||
}
|
||||
return iuo
|
||||
}
|
||||
|
||||
// ClearSynced clears the value of the "synced" field.
|
||||
func (iuo *IndexersUpdateOne) ClearSynced() *IndexersUpdateOne {
|
||||
iuo.mutation.ClearSynced()
|
||||
return iuo
|
||||
}
|
||||
|
||||
// Mutation returns the IndexersMutation object of the builder.
|
||||
func (iuo *IndexersUpdateOne) Mutation() *IndexersMutation {
|
||||
return iuo.mutation
|
||||
@@ -449,6 +694,9 @@ func (iuo *IndexersUpdateOne) sqlSave(ctx context.Context) (_node *Indexers, err
|
||||
if value, ok := iuo.mutation.Settings(); ok {
|
||||
_spec.SetField(indexers.FieldSettings, field.TypeString, value)
|
||||
}
|
||||
if iuo.mutation.SettingsCleared() {
|
||||
_spec.ClearField(indexers.FieldSettings, field.TypeString)
|
||||
}
|
||||
if value, ok := iuo.mutation.EnableRss(); ok {
|
||||
_spec.SetField(indexers.FieldEnableRss, field.TypeBool, value)
|
||||
}
|
||||
@@ -473,6 +721,36 @@ func (iuo *IndexersUpdateOne) sqlSave(ctx context.Context) (_node *Indexers, err
|
||||
if iuo.mutation.DisabledCleared() {
|
||||
_spec.ClearField(indexers.FieldDisabled, field.TypeBool)
|
||||
}
|
||||
if value, ok := iuo.mutation.TvSearch(); ok {
|
||||
_spec.SetField(indexers.FieldTvSearch, field.TypeBool, value)
|
||||
}
|
||||
if iuo.mutation.TvSearchCleared() {
|
||||
_spec.ClearField(indexers.FieldTvSearch, field.TypeBool)
|
||||
}
|
||||
if value, ok := iuo.mutation.MovieSearch(); ok {
|
||||
_spec.SetField(indexers.FieldMovieSearch, field.TypeBool, value)
|
||||
}
|
||||
if iuo.mutation.MovieSearchCleared() {
|
||||
_spec.ClearField(indexers.FieldMovieSearch, field.TypeBool)
|
||||
}
|
||||
if value, ok := iuo.mutation.APIKey(); ok {
|
||||
_spec.SetField(indexers.FieldAPIKey, field.TypeString, value)
|
||||
}
|
||||
if iuo.mutation.APIKeyCleared() {
|
||||
_spec.ClearField(indexers.FieldAPIKey, field.TypeString)
|
||||
}
|
||||
if value, ok := iuo.mutation.URL(); ok {
|
||||
_spec.SetField(indexers.FieldURL, field.TypeString, value)
|
||||
}
|
||||
if iuo.mutation.URLCleared() {
|
||||
_spec.ClearField(indexers.FieldURL, field.TypeString)
|
||||
}
|
||||
if value, ok := iuo.mutation.Synced(); ok {
|
||||
_spec.SetField(indexers.FieldSynced, field.TypeBool, value)
|
||||
}
|
||||
if iuo.mutation.SyncedCleared() {
|
||||
_spec.ClearField(indexers.FieldSynced, field.TypeBool)
|
||||
}
|
||||
_node = &Indexers{config: iuo.config}
|
||||
_spec.Assign = _node.assignValues
|
||||
_spec.ScanValues = _node.scanValues
|
||||
|
||||
@@ -113,11 +113,16 @@ var (
|
||||
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||
{Name: "name", Type: field.TypeString},
|
||||
{Name: "implementation", Type: field.TypeString},
|
||||
{Name: "settings", Type: field.TypeString},
|
||||
{Name: "settings", Type: field.TypeString, Nullable: true, Default: ""},
|
||||
{Name: "enable_rss", Type: field.TypeBool, Default: true},
|
||||
{Name: "priority", Type: field.TypeInt, Default: 50},
|
||||
{Name: "seed_ratio", Type: field.TypeFloat32, Nullable: true, Default: 0},
|
||||
{Name: "disabled", Type: field.TypeBool, Nullable: true, Default: false},
|
||||
{Name: "tv_search", Type: field.TypeBool, Nullable: true, Default: true},
|
||||
{Name: "movie_search", Type: field.TypeBool, Nullable: true, Default: true},
|
||||
{Name: "api_key", Type: field.TypeString, Nullable: true},
|
||||
{Name: "url", Type: field.TypeString, Nullable: true},
|
||||
{Name: "synced", Type: field.TypeBool, Nullable: true, Default: false},
|
||||
}
|
||||
// IndexersTable holds the schema information for the "indexers" table.
|
||||
IndexersTable = &schema.Table{
|
||||
|
||||
386
ent/mutation.go
386
ent/mutation.go
@@ -4346,6 +4346,11 @@ type IndexersMutation struct {
|
||||
seed_ratio *float32
|
||||
addseed_ratio *float32
|
||||
disabled *bool
|
||||
tv_search *bool
|
||||
movie_search *bool
|
||||
api_key *string
|
||||
url *string
|
||||
synced *bool
|
||||
clearedFields map[string]struct{}
|
||||
done bool
|
||||
oldValue func(context.Context) (*Indexers, error)
|
||||
@@ -4553,9 +4558,22 @@ func (m *IndexersMutation) OldSettings(ctx context.Context) (v string, err error
|
||||
return oldValue.Settings, nil
|
||||
}
|
||||
|
||||
// ClearSettings clears the value of the "settings" field.
|
||||
func (m *IndexersMutation) ClearSettings() {
|
||||
m.settings = nil
|
||||
m.clearedFields[indexers.FieldSettings] = struct{}{}
|
||||
}
|
||||
|
||||
// SettingsCleared returns if the "settings" field was cleared in this mutation.
|
||||
func (m *IndexersMutation) SettingsCleared() bool {
|
||||
_, ok := m.clearedFields[indexers.FieldSettings]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ResetSettings resets all changes to the "settings" field.
|
||||
func (m *IndexersMutation) ResetSettings() {
|
||||
m.settings = nil
|
||||
delete(m.clearedFields, indexers.FieldSettings)
|
||||
}
|
||||
|
||||
// SetEnableRss sets the "enable_rss" field.
|
||||
@@ -4769,6 +4787,251 @@ func (m *IndexersMutation) ResetDisabled() {
|
||||
delete(m.clearedFields, indexers.FieldDisabled)
|
||||
}
|
||||
|
||||
// SetTvSearch sets the "tv_search" field.
|
||||
func (m *IndexersMutation) SetTvSearch(b bool) {
|
||||
m.tv_search = &b
|
||||
}
|
||||
|
||||
// TvSearch returns the value of the "tv_search" field in the mutation.
|
||||
func (m *IndexersMutation) TvSearch() (r bool, exists bool) {
|
||||
v := m.tv_search
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// OldTvSearch returns the old "tv_search" field's value of the Indexers entity.
|
||||
// If the Indexers 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 *IndexersMutation) OldTvSearch(ctx context.Context) (v bool, err error) {
|
||||
if !m.op.Is(OpUpdateOne) {
|
||||
return v, errors.New("OldTvSearch is only allowed on UpdateOne operations")
|
||||
}
|
||||
if m.id == nil || m.oldValue == nil {
|
||||
return v, errors.New("OldTvSearch requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldTvSearch: %w", err)
|
||||
}
|
||||
return oldValue.TvSearch, nil
|
||||
}
|
||||
|
||||
// ClearTvSearch clears the value of the "tv_search" field.
|
||||
func (m *IndexersMutation) ClearTvSearch() {
|
||||
m.tv_search = nil
|
||||
m.clearedFields[indexers.FieldTvSearch] = struct{}{}
|
||||
}
|
||||
|
||||
// TvSearchCleared returns if the "tv_search" field was cleared in this mutation.
|
||||
func (m *IndexersMutation) TvSearchCleared() bool {
|
||||
_, ok := m.clearedFields[indexers.FieldTvSearch]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ResetTvSearch resets all changes to the "tv_search" field.
|
||||
func (m *IndexersMutation) ResetTvSearch() {
|
||||
m.tv_search = nil
|
||||
delete(m.clearedFields, indexers.FieldTvSearch)
|
||||
}
|
||||
|
||||
// SetMovieSearch sets the "movie_search" field.
|
||||
func (m *IndexersMutation) SetMovieSearch(b bool) {
|
||||
m.movie_search = &b
|
||||
}
|
||||
|
||||
// MovieSearch returns the value of the "movie_search" field in the mutation.
|
||||
func (m *IndexersMutation) MovieSearch() (r bool, exists bool) {
|
||||
v := m.movie_search
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// OldMovieSearch returns the old "movie_search" field's value of the Indexers entity.
|
||||
// If the Indexers 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 *IndexersMutation) OldMovieSearch(ctx context.Context) (v bool, err error) {
|
||||
if !m.op.Is(OpUpdateOne) {
|
||||
return v, errors.New("OldMovieSearch is only allowed on UpdateOne operations")
|
||||
}
|
||||
if m.id == nil || m.oldValue == nil {
|
||||
return v, errors.New("OldMovieSearch requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldMovieSearch: %w", err)
|
||||
}
|
||||
return oldValue.MovieSearch, nil
|
||||
}
|
||||
|
||||
// ClearMovieSearch clears the value of the "movie_search" field.
|
||||
func (m *IndexersMutation) ClearMovieSearch() {
|
||||
m.movie_search = nil
|
||||
m.clearedFields[indexers.FieldMovieSearch] = struct{}{}
|
||||
}
|
||||
|
||||
// MovieSearchCleared returns if the "movie_search" field was cleared in this mutation.
|
||||
func (m *IndexersMutation) MovieSearchCleared() bool {
|
||||
_, ok := m.clearedFields[indexers.FieldMovieSearch]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ResetMovieSearch resets all changes to the "movie_search" field.
|
||||
func (m *IndexersMutation) ResetMovieSearch() {
|
||||
m.movie_search = nil
|
||||
delete(m.clearedFields, indexers.FieldMovieSearch)
|
||||
}
|
||||
|
||||
// SetAPIKey sets the "api_key" field.
|
||||
func (m *IndexersMutation) SetAPIKey(s string) {
|
||||
m.api_key = &s
|
||||
}
|
||||
|
||||
// APIKey returns the value of the "api_key" field in the mutation.
|
||||
func (m *IndexersMutation) APIKey() (r string, exists bool) {
|
||||
v := m.api_key
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// OldAPIKey returns the old "api_key" field's value of the Indexers entity.
|
||||
// If the Indexers 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 *IndexersMutation) OldAPIKey(ctx context.Context) (v string, err error) {
|
||||
if !m.op.Is(OpUpdateOne) {
|
||||
return v, errors.New("OldAPIKey is only allowed on UpdateOne operations")
|
||||
}
|
||||
if m.id == nil || m.oldValue == nil {
|
||||
return v, errors.New("OldAPIKey requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldAPIKey: %w", err)
|
||||
}
|
||||
return oldValue.APIKey, nil
|
||||
}
|
||||
|
||||
// ClearAPIKey clears the value of the "api_key" field.
|
||||
func (m *IndexersMutation) ClearAPIKey() {
|
||||
m.api_key = nil
|
||||
m.clearedFields[indexers.FieldAPIKey] = struct{}{}
|
||||
}
|
||||
|
||||
// APIKeyCleared returns if the "api_key" field was cleared in this mutation.
|
||||
func (m *IndexersMutation) APIKeyCleared() bool {
|
||||
_, ok := m.clearedFields[indexers.FieldAPIKey]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ResetAPIKey resets all changes to the "api_key" field.
|
||||
func (m *IndexersMutation) ResetAPIKey() {
|
||||
m.api_key = nil
|
||||
delete(m.clearedFields, indexers.FieldAPIKey)
|
||||
}
|
||||
|
||||
// SetURL sets the "url" field.
|
||||
func (m *IndexersMutation) SetURL(s string) {
|
||||
m.url = &s
|
||||
}
|
||||
|
||||
// URL returns the value of the "url" field in the mutation.
|
||||
func (m *IndexersMutation) URL() (r string, exists bool) {
|
||||
v := m.url
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// OldURL returns the old "url" field's value of the Indexers entity.
|
||||
// If the Indexers 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 *IndexersMutation) OldURL(ctx context.Context) (v string, err error) {
|
||||
if !m.op.Is(OpUpdateOne) {
|
||||
return v, errors.New("OldURL is only allowed on UpdateOne operations")
|
||||
}
|
||||
if m.id == nil || m.oldValue == nil {
|
||||
return v, errors.New("OldURL requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldURL: %w", err)
|
||||
}
|
||||
return oldValue.URL, nil
|
||||
}
|
||||
|
||||
// ClearURL clears the value of the "url" field.
|
||||
func (m *IndexersMutation) ClearURL() {
|
||||
m.url = nil
|
||||
m.clearedFields[indexers.FieldURL] = struct{}{}
|
||||
}
|
||||
|
||||
// URLCleared returns if the "url" field was cleared in this mutation.
|
||||
func (m *IndexersMutation) URLCleared() bool {
|
||||
_, ok := m.clearedFields[indexers.FieldURL]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ResetURL resets all changes to the "url" field.
|
||||
func (m *IndexersMutation) ResetURL() {
|
||||
m.url = nil
|
||||
delete(m.clearedFields, indexers.FieldURL)
|
||||
}
|
||||
|
||||
// SetSynced sets the "synced" field.
|
||||
func (m *IndexersMutation) SetSynced(b bool) {
|
||||
m.synced = &b
|
||||
}
|
||||
|
||||
// Synced returns the value of the "synced" field in the mutation.
|
||||
func (m *IndexersMutation) Synced() (r bool, exists bool) {
|
||||
v := m.synced
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// OldSynced returns the old "synced" field's value of the Indexers entity.
|
||||
// If the Indexers 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 *IndexersMutation) OldSynced(ctx context.Context) (v bool, err error) {
|
||||
if !m.op.Is(OpUpdateOne) {
|
||||
return v, errors.New("OldSynced is only allowed on UpdateOne operations")
|
||||
}
|
||||
if m.id == nil || m.oldValue == nil {
|
||||
return v, errors.New("OldSynced requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldSynced: %w", err)
|
||||
}
|
||||
return oldValue.Synced, nil
|
||||
}
|
||||
|
||||
// ClearSynced clears the value of the "synced" field.
|
||||
func (m *IndexersMutation) ClearSynced() {
|
||||
m.synced = nil
|
||||
m.clearedFields[indexers.FieldSynced] = struct{}{}
|
||||
}
|
||||
|
||||
// SyncedCleared returns if the "synced" field was cleared in this mutation.
|
||||
func (m *IndexersMutation) SyncedCleared() bool {
|
||||
_, ok := m.clearedFields[indexers.FieldSynced]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ResetSynced resets all changes to the "synced" field.
|
||||
func (m *IndexersMutation) ResetSynced() {
|
||||
m.synced = nil
|
||||
delete(m.clearedFields, indexers.FieldSynced)
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the IndexersMutation builder.
|
||||
func (m *IndexersMutation) Where(ps ...predicate.Indexers) {
|
||||
m.predicates = append(m.predicates, ps...)
|
||||
@@ -4803,7 +5066,7 @@ func (m *IndexersMutation) Type() string {
|
||||
// order to get all numeric fields that were incremented/decremented, call
|
||||
// AddedFields().
|
||||
func (m *IndexersMutation) Fields() []string {
|
||||
fields := make([]string, 0, 7)
|
||||
fields := make([]string, 0, 12)
|
||||
if m.name != nil {
|
||||
fields = append(fields, indexers.FieldName)
|
||||
}
|
||||
@@ -4825,6 +5088,21 @@ func (m *IndexersMutation) Fields() []string {
|
||||
if m.disabled != nil {
|
||||
fields = append(fields, indexers.FieldDisabled)
|
||||
}
|
||||
if m.tv_search != nil {
|
||||
fields = append(fields, indexers.FieldTvSearch)
|
||||
}
|
||||
if m.movie_search != nil {
|
||||
fields = append(fields, indexers.FieldMovieSearch)
|
||||
}
|
||||
if m.api_key != nil {
|
||||
fields = append(fields, indexers.FieldAPIKey)
|
||||
}
|
||||
if m.url != nil {
|
||||
fields = append(fields, indexers.FieldURL)
|
||||
}
|
||||
if m.synced != nil {
|
||||
fields = append(fields, indexers.FieldSynced)
|
||||
}
|
||||
return fields
|
||||
}
|
||||
|
||||
@@ -4847,6 +5125,16 @@ func (m *IndexersMutation) Field(name string) (ent.Value, bool) {
|
||||
return m.SeedRatio()
|
||||
case indexers.FieldDisabled:
|
||||
return m.Disabled()
|
||||
case indexers.FieldTvSearch:
|
||||
return m.TvSearch()
|
||||
case indexers.FieldMovieSearch:
|
||||
return m.MovieSearch()
|
||||
case indexers.FieldAPIKey:
|
||||
return m.APIKey()
|
||||
case indexers.FieldURL:
|
||||
return m.URL()
|
||||
case indexers.FieldSynced:
|
||||
return m.Synced()
|
||||
}
|
||||
return nil, false
|
||||
}
|
||||
@@ -4870,6 +5158,16 @@ func (m *IndexersMutation) OldField(ctx context.Context, name string) (ent.Value
|
||||
return m.OldSeedRatio(ctx)
|
||||
case indexers.FieldDisabled:
|
||||
return m.OldDisabled(ctx)
|
||||
case indexers.FieldTvSearch:
|
||||
return m.OldTvSearch(ctx)
|
||||
case indexers.FieldMovieSearch:
|
||||
return m.OldMovieSearch(ctx)
|
||||
case indexers.FieldAPIKey:
|
||||
return m.OldAPIKey(ctx)
|
||||
case indexers.FieldURL:
|
||||
return m.OldURL(ctx)
|
||||
case indexers.FieldSynced:
|
||||
return m.OldSynced(ctx)
|
||||
}
|
||||
return nil, fmt.Errorf("unknown Indexers field %s", name)
|
||||
}
|
||||
@@ -4928,6 +5226,41 @@ func (m *IndexersMutation) SetField(name string, value ent.Value) error {
|
||||
}
|
||||
m.SetDisabled(v)
|
||||
return nil
|
||||
case indexers.FieldTvSearch:
|
||||
v, ok := value.(bool)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetTvSearch(v)
|
||||
return nil
|
||||
case indexers.FieldMovieSearch:
|
||||
v, ok := value.(bool)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetMovieSearch(v)
|
||||
return nil
|
||||
case indexers.FieldAPIKey:
|
||||
v, ok := value.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetAPIKey(v)
|
||||
return nil
|
||||
case indexers.FieldURL:
|
||||
v, ok := value.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetURL(v)
|
||||
return nil
|
||||
case indexers.FieldSynced:
|
||||
v, ok := value.(bool)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetSynced(v)
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Indexers field %s", name)
|
||||
}
|
||||
@@ -4985,12 +5318,30 @@ func (m *IndexersMutation) AddField(name string, value ent.Value) error {
|
||||
// mutation.
|
||||
func (m *IndexersMutation) ClearedFields() []string {
|
||||
var fields []string
|
||||
if m.FieldCleared(indexers.FieldSettings) {
|
||||
fields = append(fields, indexers.FieldSettings)
|
||||
}
|
||||
if m.FieldCleared(indexers.FieldSeedRatio) {
|
||||
fields = append(fields, indexers.FieldSeedRatio)
|
||||
}
|
||||
if m.FieldCleared(indexers.FieldDisabled) {
|
||||
fields = append(fields, indexers.FieldDisabled)
|
||||
}
|
||||
if m.FieldCleared(indexers.FieldTvSearch) {
|
||||
fields = append(fields, indexers.FieldTvSearch)
|
||||
}
|
||||
if m.FieldCleared(indexers.FieldMovieSearch) {
|
||||
fields = append(fields, indexers.FieldMovieSearch)
|
||||
}
|
||||
if m.FieldCleared(indexers.FieldAPIKey) {
|
||||
fields = append(fields, indexers.FieldAPIKey)
|
||||
}
|
||||
if m.FieldCleared(indexers.FieldURL) {
|
||||
fields = append(fields, indexers.FieldURL)
|
||||
}
|
||||
if m.FieldCleared(indexers.FieldSynced) {
|
||||
fields = append(fields, indexers.FieldSynced)
|
||||
}
|
||||
return fields
|
||||
}
|
||||
|
||||
@@ -5005,12 +5356,30 @@ func (m *IndexersMutation) FieldCleared(name string) bool {
|
||||
// error if the field is not defined in the schema.
|
||||
func (m *IndexersMutation) ClearField(name string) error {
|
||||
switch name {
|
||||
case indexers.FieldSettings:
|
||||
m.ClearSettings()
|
||||
return nil
|
||||
case indexers.FieldSeedRatio:
|
||||
m.ClearSeedRatio()
|
||||
return nil
|
||||
case indexers.FieldDisabled:
|
||||
m.ClearDisabled()
|
||||
return nil
|
||||
case indexers.FieldTvSearch:
|
||||
m.ClearTvSearch()
|
||||
return nil
|
||||
case indexers.FieldMovieSearch:
|
||||
m.ClearMovieSearch()
|
||||
return nil
|
||||
case indexers.FieldAPIKey:
|
||||
m.ClearAPIKey()
|
||||
return nil
|
||||
case indexers.FieldURL:
|
||||
m.ClearURL()
|
||||
return nil
|
||||
case indexers.FieldSynced:
|
||||
m.ClearSynced()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Indexers nullable field %s", name)
|
||||
}
|
||||
@@ -5040,6 +5409,21 @@ func (m *IndexersMutation) ResetField(name string) error {
|
||||
case indexers.FieldDisabled:
|
||||
m.ResetDisabled()
|
||||
return nil
|
||||
case indexers.FieldTvSearch:
|
||||
m.ResetTvSearch()
|
||||
return nil
|
||||
case indexers.FieldMovieSearch:
|
||||
m.ResetMovieSearch()
|
||||
return nil
|
||||
case indexers.FieldAPIKey:
|
||||
m.ResetAPIKey()
|
||||
return nil
|
||||
case indexers.FieldURL:
|
||||
m.ResetURL()
|
||||
return nil
|
||||
case indexers.FieldSynced:
|
||||
m.ResetSynced()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Indexers field %s", name)
|
||||
}
|
||||
|
||||
@@ -71,6 +71,10 @@ func init() {
|
||||
history.DefaultSize = historyDescSize.Default.(int)
|
||||
indexersFields := schema.Indexers{}.Fields()
|
||||
_ = indexersFields
|
||||
// indexersDescSettings is the schema descriptor for settings field.
|
||||
indexersDescSettings := indexersFields[2].Descriptor()
|
||||
// indexers.DefaultSettings holds the default value on creation for the settings field.
|
||||
indexers.DefaultSettings = indexersDescSettings.Default.(string)
|
||||
// indexersDescEnableRss is the schema descriptor for enable_rss field.
|
||||
indexersDescEnableRss := indexersFields[3].Descriptor()
|
||||
// indexers.DefaultEnableRss holds the default value on creation for the enable_rss field.
|
||||
@@ -87,6 +91,18 @@ func init() {
|
||||
indexersDescDisabled := indexersFields[6].Descriptor()
|
||||
// indexers.DefaultDisabled holds the default value on creation for the disabled field.
|
||||
indexers.DefaultDisabled = indexersDescDisabled.Default.(bool)
|
||||
// indexersDescTvSearch is the schema descriptor for tv_search field.
|
||||
indexersDescTvSearch := indexersFields[7].Descriptor()
|
||||
// indexers.DefaultTvSearch holds the default value on creation for the tv_search field.
|
||||
indexers.DefaultTvSearch = indexersDescTvSearch.Default.(bool)
|
||||
// indexersDescMovieSearch is the schema descriptor for movie_search field.
|
||||
indexersDescMovieSearch := indexersFields[8].Descriptor()
|
||||
// indexers.DefaultMovieSearch holds the default value on creation for the movie_search field.
|
||||
indexers.DefaultMovieSearch = indexersDescMovieSearch.Default.(bool)
|
||||
// indexersDescSynced is the schema descriptor for synced field.
|
||||
indexersDescSynced := indexersFields[11].Descriptor()
|
||||
// indexers.DefaultSynced holds the default value on creation for the synced field.
|
||||
indexers.DefaultSynced = indexersDescSynced.Default.(bool)
|
||||
mediaFields := schema.Media{}.Fields()
|
||||
_ = mediaFields
|
||||
// mediaDescCreatedAt is the schema descriptor for created_at field.
|
||||
|
||||
@@ -15,11 +15,16 @@ func (Indexers) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.String("name"),
|
||||
field.String("implementation"),
|
||||
field.String("settings"),
|
||||
field.String("settings").Optional().Default("").Comment("deprecated, use api_key and url"),
|
||||
field.Bool("enable_rss").Default(true),
|
||||
field.Int("priority").Default(50),
|
||||
field.Float32("seed_ratio").Optional().Default(0).Comment("minimal seed ratio requied, before removing torrent"),
|
||||
field.Bool("disabled").Optional().Default(false),
|
||||
field.Bool("tv_search").Optional().Default(true),
|
||||
field.Bool("movie_search").Optional().Default(true),
|
||||
field.String("api_key").Optional(),
|
||||
field.String("url").Optional(),
|
||||
field.Bool("synced").Optional().Default(false).Comment("synced from prowlarr"),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,26 +31,28 @@ func New(apiKey, url string) *Client {
|
||||
return &Client{p: p, apiKey: apiKey, url: url}
|
||||
}
|
||||
|
||||
func (c *Client) GetIndexers(t ProwlarrSupportType) ([]*db.TorznabInfo, error) {
|
||||
func (c *Client) GetIndexers() ([]*ent.Indexers, error) {
|
||||
ins, err := c.p.GetIndexers()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var indexers []*db.TorznabInfo
|
||||
var indexers []*ent.Indexers
|
||||
for _, in := range ins {
|
||||
if !in.Enable {
|
||||
continue
|
||||
|
||||
tvSearch := true
|
||||
movieSearch := true
|
||||
if len(in.Capabilities.TvSearchParams) == 0 { //no tv resource in this indexer
|
||||
tvSearch = false
|
||||
}
|
||||
if t == "tv" && len(in.Capabilities.TvSearchParams) == 0 { //no tv resource in this indexer
|
||||
continue
|
||||
} else if t == "movie" && len(in.Capabilities.MovieSearchParams) == 0 { //no movie resource in this indexer
|
||||
continue
|
||||
if len(in.Capabilities.MovieSearchParams) == 0 { //no movie resource in this indexer
|
||||
movieSearch = false
|
||||
}
|
||||
seedRatio := 0.0
|
||||
for _, f := range in.Fields {
|
||||
if f.Name == "torrentBaseSettings.seedRatio" && f.Value != nil {
|
||||
if r, ok := f.Value.(float64); ok {
|
||||
seedRatio = r
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -61,17 +63,18 @@ func (c *Client) GetIndexers(t ProwlarrSupportType) ([]*db.TorznabInfo, error) {
|
||||
data, _ := json.Marshal(&setting)
|
||||
|
||||
entIndexer := ent.Indexers{
|
||||
Disabled: !in.Enable,
|
||||
Name: in.Name,
|
||||
Implementation: "torznab",
|
||||
Priority: 128 - int(in.Priority),
|
||||
SeedRatio: float32(seedRatio),
|
||||
Settings: string(data),
|
||||
TvSearch: tvSearch,
|
||||
MovieSearch: movieSearch,
|
||||
APIKey: c.apiKey,
|
||||
URL: fmt.Sprintf("%s/%d/api", strings.TrimSuffix(c.url, "/"), in.ID),
|
||||
}
|
||||
|
||||
indexers = append(indexers, &db.TorznabInfo{
|
||||
Indexers: &entIndexer,
|
||||
TorznabSetting: setting,
|
||||
})
|
||||
indexers = append(indexers, &entIndexer)
|
||||
}
|
||||
return indexers, nil
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
|
||||
func Test111(t *testing.T) {
|
||||
c := New("", "http://10.0.0.8:9696/")
|
||||
apis , err := c.GetIndexers("tv")
|
||||
apis , err := c.GetIndexers()
|
||||
log.Infof("errors: %v", err)
|
||||
log.Infof("indexers: %+v", apis[0])
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"polaris/db"
|
||||
"polaris/ent"
|
||||
"polaris/log"
|
||||
"slices"
|
||||
"strconv"
|
||||
@@ -74,7 +74,7 @@ func (i *Item) GetAttr(key string) string {
|
||||
}
|
||||
return ""
|
||||
}
|
||||
func (r *Response) ToResults(indexer *db.TorznabInfo) []Result {
|
||||
func (r *Response) ToResults(indexer *ent.Indexers) []Result {
|
||||
var res []Result
|
||||
for _, item := range r.Channel.Item {
|
||||
if slices.Contains(item.Category, "3000") { //exclude audio files
|
||||
@@ -130,7 +130,7 @@ func tryParseFloat(s string) float32 {
|
||||
return float32(r)
|
||||
}
|
||||
|
||||
func Search(indexer *db.TorznabInfo, keyWord string) ([]Result, error) {
|
||||
func Search(indexer *ent.Indexers, keyWord string) ([]Result, error) {
|
||||
ctx, cancel := context.WithTimeout(context.TODO(), 30*time.Second)
|
||||
defer cancel()
|
||||
|
||||
@@ -139,7 +139,7 @@ func Search(indexer *db.TorznabInfo, keyWord string) ([]Result, error) {
|
||||
return nil, errors.Wrap(err, "new request")
|
||||
}
|
||||
var q = url.Values{}
|
||||
q.Add("apikey", indexer.ApiKey)
|
||||
q.Add("apikey", indexer.APIKey)
|
||||
q.Add("t", "search")
|
||||
q.Add("q", keyWord)
|
||||
req.URL.RawQuery = q.Encode()
|
||||
|
||||
80
server/core/indexer.go
Normal file
80
server/core/indexer.go
Normal file
@@ -0,0 +1,80 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"polaris/ent"
|
||||
"polaris/log"
|
||||
"polaris/pkg/prowlarr"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
const prowlarrPrefix = "Prowlarr_"
|
||||
|
||||
func (c *Client) SyncProwlarrIndexers(apiKey, url string) error {
|
||||
client := prowlarr.New(apiKey, url)
|
||||
if ins, err := client.GetIndexers(); err != nil {
|
||||
return errors.Wrap(err, "connect to prowlarr error")
|
||||
} else {
|
||||
var prowlarrNames = make(map[string]bool, len(ins))
|
||||
for _, in := range ins {
|
||||
prowlarrNames[in.Name] = true
|
||||
}
|
||||
all := c.db.GetAllIndexers()
|
||||
for _, index := range all {
|
||||
|
||||
if index.Synced {
|
||||
if !prowlarrNames[strings.TrimPrefix(index.Name, prowlarrPrefix)] {
|
||||
c.db.DeleteIndexer(index.ID) //remove deleted indexers
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for _, indexer := range ins {
|
||||
if err := c.db.SaveIndexer(&ent.Indexers{
|
||||
Disabled: indexer.Disabled,
|
||||
Name: prowlarrPrefix + indexer.Name,
|
||||
Priority: indexer.Priority,
|
||||
SeedRatio: indexer.SeedRatio,
|
||||
//Settings: indexer.Settings,
|
||||
Implementation: "torznab",
|
||||
APIKey: indexer.APIKey,
|
||||
URL: indexer.URL,
|
||||
TvSearch: indexer.TvSearch,
|
||||
MovieSearch: indexer.MovieSearch,
|
||||
Synced: true,
|
||||
}); err != nil {
|
||||
return errors.Wrap(err, "save prowlarr indexers")
|
||||
}
|
||||
log.Debugf("synced prowlarr indexer to db: %v", indexer.Name)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Client) syncProwlarr() error {
|
||||
p, err := c.db.GetProwlarrSetting()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "db")
|
||||
}
|
||||
if p.Disabled {
|
||||
return nil
|
||||
}
|
||||
if err := c.SyncProwlarrIndexers(p.ApiKey, p.URL); err != nil {
|
||||
return errors.Wrap(err, "sync prowlarr indexers")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
func (c *Client) DeleteAllProwlarrIndexers() error {
|
||||
all := c.db.GetAllIndexers()
|
||||
for _, index := range all {
|
||||
if index.Synced {
|
||||
c.db.DeleteIndexer(index.ID)
|
||||
log.Debugf("success delete prowlarr indexer: %s", index.Name)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -25,6 +25,9 @@ func (c *Client) addSysCron() {
|
||||
if v == "true" {
|
||||
return nil
|
||||
}
|
||||
if err := c.syncProwlarr(); err != nil {
|
||||
log.Warnf("sync prowlarr error: %v", err)
|
||||
}
|
||||
c.downloadAllTvSeries()
|
||||
c.downloadAllMovies()
|
||||
return nil
|
||||
@@ -224,7 +227,7 @@ func (c *Client) moveCompletedTask(id int) (err1 error) {
|
||||
}
|
||||
c.sendMsg(fmt.Sprintf(message.ProcessingComplete, torrentName))
|
||||
|
||||
//判断是否需要删除本地文件
|
||||
//判断是否需要删除本地文件, TODO prowlarr has no indexer id
|
||||
r1, ok := c.isSeedRatioLimitReached(r.IndexerID, torrent)
|
||||
if downloadclient.RemoveCompletedDownloads && ok {
|
||||
log.Debugf("download complete,remove torrent and files related, torrent: %v, seed ratio: %v", torrentName, r1)
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"polaris/ent/media"
|
||||
"polaris/log"
|
||||
"polaris/pkg/metadata"
|
||||
"polaris/pkg/prowlarr"
|
||||
"polaris/pkg/torznab"
|
||||
"slices"
|
||||
"sort"
|
||||
@@ -86,7 +85,7 @@ func SearchTvSeries(db1 *db.Client, param *SearchParam) ([]torznab.Result, error
|
||||
|
||||
names := names2Query(series.Media)
|
||||
|
||||
res := searchWithTorznab(db1, prowlarr.TV, names...)
|
||||
res := searchWithTorznab(db1, SearchTypeTv, names...)
|
||||
|
||||
var filtered []torznab.Result
|
||||
lo:
|
||||
@@ -248,9 +247,9 @@ func SearchMovie(db1 *db.Client, param *SearchParam) ([]torznab.Result, error) {
|
||||
}
|
||||
names := names2Query(movieDetail.Media)
|
||||
|
||||
res := searchWithTorznab(db1, prowlarr.Movie, names...)
|
||||
res := searchWithTorznab(db1, SearchTypeMovie, names...)
|
||||
if movieDetail.Extras.IsJav() {
|
||||
res1 := searchWithTorznab(db1, prowlarr.Movie, movieDetail.Extras.JavId)
|
||||
res1 := searchWithTorznab(db1, SearchTypeMovie, movieDetail.Extras.JavId)
|
||||
res = append(res, res1...)
|
||||
}
|
||||
|
||||
@@ -304,21 +303,18 @@ func SearchMovie(db1 *db.Client, param *SearchParam) ([]torznab.Result, error) {
|
||||
|
||||
}
|
||||
|
||||
func searchWithTorznab(db *db.Client, t prowlarr.ProwlarrSupportType, queries ...string) []torznab.Result {
|
||||
type SearchType int
|
||||
|
||||
const (
|
||||
SearchTypeTv SearchType = 1
|
||||
SearchTypeMovie SearchType = 2
|
||||
)
|
||||
|
||||
func searchWithTorznab(db *db.Client, t SearchType, queries ...string) []torznab.Result {
|
||||
|
||||
var res []torznab.Result
|
||||
allTorznab := db.GetAllTorznabInfo()
|
||||
allTorznab := db.GetAllIndexers()
|
||||
|
||||
p, err := db.GetProwlarrSetting()
|
||||
if err == nil && !p.Disabled { //prowlarr exists
|
||||
c := prowlarr.New(p.ApiKey, p.URL)
|
||||
all, err := c.GetIndexers(t)
|
||||
if err != nil {
|
||||
log.Warnf("get prowlarr all indexer error: %v", err)
|
||||
} else {
|
||||
allTorznab = append(allTorznab, all...)
|
||||
}
|
||||
}
|
||||
resChan := make(chan []torznab.Result)
|
||||
var wg sync.WaitGroup
|
||||
|
||||
@@ -326,6 +322,13 @@ func searchWithTorznab(db *db.Client, t prowlarr.ProwlarrSupportType, queries ..
|
||||
if tor.Disabled {
|
||||
continue
|
||||
}
|
||||
if t == SearchTypeTv && !tor.TvSearch {
|
||||
continue
|
||||
}
|
||||
if t == SearchTypeMovie && !tor.MovieSearch {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, q := range queries {
|
||||
wg.Add(1)
|
||||
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"polaris/db"
|
||||
"polaris/ent"
|
||||
"polaris/ent/downloadclients"
|
||||
"polaris/log"
|
||||
"polaris/pkg/prowlarr"
|
||||
"polaris/pkg/qbittorrent"
|
||||
"polaris/pkg/torznab"
|
||||
"polaris/pkg/transmission"
|
||||
@@ -146,29 +144,25 @@ func (s *Server) AddTorznabInfo(c *gin.Context) (interface{}, error) {
|
||||
utils.TrimFields(&in)
|
||||
|
||||
log.Infof("add indexer settings: %+v", in)
|
||||
setting := db.TorznabSetting{
|
||||
URL: in.URL,
|
||||
ApiKey: in.ApiKey,
|
||||
}
|
||||
|
||||
data, err := json.Marshal(setting)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "marshal json")
|
||||
}
|
||||
if in.Priority > 128 {
|
||||
in.Priority = 128
|
||||
}
|
||||
if in.Priority < 1 {
|
||||
in.Priority = 1
|
||||
}
|
||||
|
||||
indexer := ent.Indexers{
|
||||
ID: in.ID,
|
||||
Name: in.Name,
|
||||
Implementation: "torznab",
|
||||
Settings: string(data),
|
||||
Priority: in.Priority,
|
||||
Disabled: in.Disabled,
|
||||
SeedRatio: in.SeedRatio,
|
||||
APIKey: in.ApiKey,
|
||||
URL: in.URL,
|
||||
}
|
||||
err = s.db.SaveIndexer(&indexer)
|
||||
err := s.db.SaveIndexer(&indexer)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "add ")
|
||||
}
|
||||
@@ -183,12 +177,12 @@ func (s *Server) DeleteTorznabInfo(c *gin.Context) (interface{}, error) {
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("id is not correct: %v", ids)
|
||||
}
|
||||
s.db.DeleteTorznab(id)
|
||||
s.db.DeleteIndexer(id)
|
||||
return "success", nil
|
||||
}
|
||||
|
||||
func (s *Server) GetAllIndexers(c *gin.Context) (interface{}, error) {
|
||||
indexers := s.db.GetAllTorznabInfo()
|
||||
indexers := s.db.GetAllIndexers()
|
||||
if len(indexers) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
@@ -316,11 +310,16 @@ func (s *Server) SaveProwlarrSetting(c *gin.Context) (interface{}, error) {
|
||||
if err := c.ShouldBindJSON(&in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !in.Disabled {
|
||||
client := prowlarr.New(in.ApiKey, in.URL)
|
||||
if _, err := client.GetIndexers(prowlarr.TV); err != nil {
|
||||
return nil, errors.Wrap(err, "connect to prowlarr error")
|
||||
|
||||
if in.Disabled {
|
||||
if err := s.core.DeleteAllProwlarrIndexers(); err != nil {
|
||||
return nil, errors.Wrap(err, "delete prowlarr indexers")
|
||||
}
|
||||
} else {
|
||||
if err := s.core.SyncProwlarrIndexers(in.ApiKey, in.URL); err != nil {
|
||||
return nil, errors.Wrap(err, "verify prowlarr")
|
||||
}
|
||||
|
||||
}
|
||||
err := s.db.SaveProwlarrSetting(&in)
|
||||
if err != nil {
|
||||
|
||||
@@ -161,6 +161,7 @@ class Indexer {
|
||||
int? priority;
|
||||
double? seedRatio;
|
||||
bool? disabled;
|
||||
bool? synced;
|
||||
|
||||
Indexer(
|
||||
{this.name,
|
||||
@@ -169,7 +170,8 @@ class Indexer {
|
||||
this.id,
|
||||
this.priority = 50,
|
||||
this.seedRatio = 0,
|
||||
this.disabled});
|
||||
this.disabled,
|
||||
this.synced});
|
||||
|
||||
Indexer.fromJson(Map<String, dynamic> json) {
|
||||
name = json['name'];
|
||||
@@ -179,6 +181,7 @@ class Indexer {
|
||||
priority = json["priority"];
|
||||
seedRatio = json["seed_ratio"] ?? 0;
|
||||
disabled = json["disabled"] ?? false;
|
||||
synced = json["synced"] ?? false;
|
||||
}
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> data = <String, dynamic>{};
|
||||
|
||||
@@ -5,6 +5,7 @@ import 'package:form_builder_validators/form_builder_validators.dart';
|
||||
import 'package:ui/providers/settings.dart';
|
||||
import 'package:ui/settings/dialog.dart';
|
||||
import 'package:ui/widgets/progress_indicator.dart';
|
||||
import 'package:ui/widgets/utils.dart';
|
||||
import 'package:ui/widgets/widgets.dart';
|
||||
|
||||
class IndexerSettings extends ConsumerStatefulWidget {
|
||||
@@ -16,11 +17,30 @@ class IndexerSettings extends ConsumerStatefulWidget {
|
||||
}
|
||||
|
||||
class _IndexerState extends ConsumerState<IndexerSettings> {
|
||||
final _formKey = GlobalKey<FormBuilderState>();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var indexers = ref.watch(indexersProvider);
|
||||
return indexers.when(
|
||||
data: (value) => Wrap(
|
||||
data: (value) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Padding(
|
||||
padding: EdgeInsets.only(top: 10, bottom: 10, left: 10),
|
||||
child: Text("Prowlarr 设置", style: TextStyle(fontSize: 18)),
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsets.only(left: 20), child: prowlarrSetting()),
|
||||
Divider(),
|
||||
Padding(
|
||||
padding: EdgeInsets.only(top: 10, bottom: 10, left: 10),
|
||||
child: Text("索引器列表", style: TextStyle(fontSize: 18)),
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsets.only(left: 20),
|
||||
child: Wrap(
|
||||
children: List.generate(value.length + 1, (i) {
|
||||
if (i < value.length) {
|
||||
var indexer = value[i];
|
||||
@@ -32,6 +52,77 @@ class _IndexerState extends ConsumerState<IndexerSettings> {
|
||||
onTap: () => showIndexerDetails(Indexer()),
|
||||
child: const Icon(Icons.add));
|
||||
}),
|
||||
)),
|
||||
],
|
||||
);
|
||||
},
|
||||
error: (err, trace) => PoNetworkError(err: err),
|
||||
loading: () => const MyProgressIndicator());
|
||||
}
|
||||
|
||||
Widget prowlarrSetting() {
|
||||
var ps = ref.watch(prowlarrSettingDataProvider);
|
||||
return ps.when(
|
||||
data: (v) => FormBuilder(
|
||||
key: _formKey, //设置globalKey,用于后面获取FormState
|
||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||
initialValue: {
|
||||
"api_key": v.apiKey,
|
||||
"url": v.url,
|
||||
"disabled": v.disabled
|
||||
},
|
||||
child: Column(
|
||||
children: [
|
||||
FormBuilderTextField(
|
||||
name: "url",
|
||||
decoration: const InputDecoration(
|
||||
labelText: "Prowlarr URL",
|
||||
icon: Icon(Icons.web),
|
||||
hintText: "http://10.0.0.8:9696"),
|
||||
validator: FormBuilderValidators.required(),
|
||||
),
|
||||
FormBuilderTextField(
|
||||
name: "api_key",
|
||||
decoration: const InputDecoration(
|
||||
labelText: "API Key",
|
||||
icon: Icon(Icons.key),
|
||||
helperText: "Prowlarr 设置 -> 通用 -> API 密钥"),
|
||||
validator: FormBuilderValidators.required(),
|
||||
),
|
||||
FormBuilderSwitch(
|
||||
name: "disabled",
|
||||
title: const Text("禁用 Prowlarr"),
|
||||
decoration:
|
||||
InputDecoration(icon: Icon(Icons.do_not_disturb)),
|
||||
),
|
||||
Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(10),
|
||||
child: ElevatedButton(
|
||||
onPressed: () {
|
||||
if (_formKey.currentState!.saveAndValidate()) {
|
||||
var values = _formKey.currentState!.value;
|
||||
var f = ref
|
||||
.read(prowlarrSettingDataProvider.notifier)
|
||||
.save(ProwlarrSetting(
|
||||
apiKey: values["api_key"],
|
||||
url: values["url"],
|
||||
disabled: values["disabled"]))
|
||||
.then((v) {
|
||||
showSnakeBar("更新成功");
|
||||
ref.invalidate(indexersProvider);
|
||||
});
|
||||
showLoadingWithFuture(f);
|
||||
}
|
||||
},
|
||||
child: const Padding(
|
||||
padding: EdgeInsets.all(10),
|
||||
child: Text("保存"),
|
||||
)),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
error: (err, trace) => PoNetworkError(err: err),
|
||||
loading: () => const MyProgressIndicator());
|
||||
@@ -54,6 +145,7 @@ class _IndexerState extends ConsumerState<IndexerSettings> {
|
||||
child: Column(
|
||||
children: [
|
||||
FormBuilderDropdown(
|
||||
enabled: indexer.synced != true,
|
||||
name: "impl",
|
||||
decoration: const InputDecoration(labelText: "类型"),
|
||||
items: const [
|
||||
@@ -61,24 +153,28 @@ class _IndexerState extends ConsumerState<IndexerSettings> {
|
||||
],
|
||||
),
|
||||
FormBuilderTextField(
|
||||
enabled: indexer.synced != true,
|
||||
name: "name",
|
||||
decoration: Commons.requiredTextFieldStyle(text: "名称"),
|
||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||
validator: FormBuilderValidators.required(),
|
||||
),
|
||||
FormBuilderTextField(
|
||||
enabled: indexer.synced != true,
|
||||
name: "url",
|
||||
decoration: Commons.requiredTextFieldStyle(text: "地址"),
|
||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||
validator: FormBuilderValidators.required(),
|
||||
),
|
||||
FormBuilderTextField(
|
||||
enabled: indexer.synced != true,
|
||||
name: "api_key",
|
||||
decoration: Commons.requiredTextFieldStyle(text: "API Key"),
|
||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||
validator: FormBuilderValidators.required(),
|
||||
),
|
||||
FormBuilderTextField(
|
||||
enabled: indexer.synced != true,
|
||||
name: "priority",
|
||||
decoration: const InputDecoration(
|
||||
labelText: "索引优先级",
|
||||
@@ -88,6 +184,7 @@ class _IndexerState extends ConsumerState<IndexerSettings> {
|
||||
validator: FormBuilderValidators.positiveNumber(),
|
||||
),
|
||||
FormBuilderTextField(
|
||||
enabled: indexer.synced != true,
|
||||
name: "seed_ratio",
|
||||
decoration: const InputDecoration(
|
||||
labelText: "做种率",
|
||||
@@ -97,7 +194,10 @@ class _IndexerState extends ConsumerState<IndexerSettings> {
|
||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||
validator: FormBuilderValidators.numeric(),
|
||||
),
|
||||
FormBuilderSwitch(name: "disabled", title: const Text("禁用此索引器"))
|
||||
FormBuilderSwitch(
|
||||
enabled: indexer.synced != true,
|
||||
name: "disabled",
|
||||
title: const Text("禁用此索引器"))
|
||||
],
|
||||
),
|
||||
);
|
||||
@@ -122,6 +222,11 @@ class _IndexerState extends ConsumerState<IndexerSettings> {
|
||||
}
|
||||
|
||||
return showSettingDialog(
|
||||
context, "索引器", indexer.id != null, body, onSubmit, onDelete);
|
||||
context,
|
||||
indexer.synced != true?"索引器":"Prowlarr 索引器",
|
||||
(indexer.id != null) && (indexer.synced != true),
|
||||
body,
|
||||
onSubmit,
|
||||
onDelete);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ import 'package:ui/settings/general.dart';
|
||||
import 'package:ui/settings/importlist.dart';
|
||||
import 'package:ui/settings/indexer.dart';
|
||||
import 'package:ui/settings/notifier.dart';
|
||||
import 'package:ui/settings/prowlarr.dart';
|
||||
import 'package:ui/settings/storage.dart';
|
||||
|
||||
class SystemSettingsPage extends ConsumerStatefulWidget {
|
||||
@@ -27,7 +26,6 @@ class _SystemSettingsPageState extends ConsumerState<SystemSettingsPage> {
|
||||
children: [
|
||||
getExpansionTile("常规", const GeneralSettings()),
|
||||
getExpansionTile("索引器", const IndexerSettings()),
|
||||
getExpansionTile("Prowlarr 设置", const ProwlarrSettingPage()),
|
||||
getExpansionTile("下载器", const DownloaderSettings()),
|
||||
getExpansionTile("存储", const StorageSettings()),
|
||||
getExpansionTile("通知客户端", const NotifierSettings()),
|
||||
|
||||
Reference in New Issue
Block a user