feat: blacklist api

This commit is contained in:
Simon Ding
2025-04-22 18:18:32 +08:00
parent 1a3807acc9
commit fdcf7f487c
16 changed files with 965 additions and 124 deletions

View File

@@ -6,6 +6,7 @@ import (
"fmt" "fmt"
"os" "os"
"polaris/ent" "polaris/ent"
"polaris/ent/blacklist"
"polaris/ent/downloadclients" "polaris/ent/downloadclients"
"polaris/ent/episode" "polaris/ent/episode"
"polaris/ent/history" "polaris/ent/history"
@@ -742,3 +743,17 @@ func (c *client) GetTmdbApiKey() string {
} }
return k return k
} }
func (c *client) AddTorrent2Blacklist(hash, name string, mediaId int) error {
count := c.ent.Blacklist.Query().Where(blacklist.TorrentHash(hash), blacklist.MediaID(mediaId)).CountX(context.TODO())
if count > 0 { //already exist
log.Infof("torrent %s already in blacklist", hash)
return nil
}
return c.ent.Blacklist.Create().SetType(blacklist.TypeTorrent).SetTorrentHash(hash).SetTorrentName(name).SetMediaID(mediaId).Exec(context.Background())
}
func (c *client) GetTorrentBlacklist() (ent.Blacklists, error) {
return c.ent.Blacklist.Query().Where(blacklist.TypeEQ(blacklist.TypeTorrent)).All(context.Background())
}

View File

@@ -39,6 +39,9 @@ type Database interface {
AddNotificationClient(name, service string, setting string, enabled bool) error AddNotificationClient(name, service string, setting string, enabled bool) error
DeleteNotificationClient(id int) error DeleteNotificationClient(id int) error
GetNotificationClient(id int) (*NotificationClient, error) GetNotificationClient(id int) (*NotificationClient, error)
AddTorrent2Blacklist(hash, name string, mediaId int) error
GetTorrentBlacklist() (ent.Blacklists, error)
} }
type Settings interface { type Settings interface {

View File

@@ -51,6 +51,10 @@ func (c *Engine) Init() {
go c.checkW500PosterOnStartup() go c.checkW500PosterOnStartup()
} }
func (c *Engine) GetTask(id int) (*Task, bool) {
return c.tasks.Load(id)
}
func (c *Engine) reloadUsingBuildinDownloader(h *ent.History) error{ func (c *Engine) reloadUsingBuildinDownloader(h *ent.History) error{
cl, err := buildin.NewDownloader(c.db.GetDownloadDir()) cl, err := buildin.NewDownloader(c.db.GetDownloadDir())
if err != nil { if err != nil {

View File

@@ -3,11 +3,10 @@
package ent package ent
import ( import (
"encoding/json"
"fmt" "fmt"
"polaris/ent/blacklist" "polaris/ent/blacklist"
"polaris/ent/schema"
"strings" "strings"
"time"
"entgo.io/ent" "entgo.io/ent"
"entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql"
@@ -20,8 +19,14 @@ type Blacklist struct {
ID int `json:"id,omitempty"` ID int `json:"id,omitempty"`
// Type holds the value of the "type" field. // Type holds the value of the "type" field.
Type blacklist.Type `json:"type,omitempty"` Type blacklist.Type `json:"type,omitempty"`
// Value holds the value of the "value" field. // TorrentHash holds the value of the "torrent_hash" field.
Value schema.BlacklistValue `json:"value,omitempty"` TorrentHash string `json:"torrent_hash,omitempty"`
// TorrentName holds the value of the "torrent_name" field.
TorrentName string `json:"torrent_name,omitempty"`
// MediaID holds the value of the "media_id" field.
MediaID int `json:"media_id,omitempty"`
// CreateTime holds the value of the "create_time" field.
CreateTime time.Time `json:"create_time,omitempty"`
// Notes holds the value of the "notes" field. // Notes holds the value of the "notes" field.
Notes string `json:"notes,omitempty"` Notes string `json:"notes,omitempty"`
selectValues sql.SelectValues selectValues sql.SelectValues
@@ -32,12 +37,12 @@ func (*Blacklist) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns)) values := make([]any, len(columns))
for i := range columns { for i := range columns {
switch columns[i] { switch columns[i] {
case blacklist.FieldValue: case blacklist.FieldID, blacklist.FieldMediaID:
values[i] = new([]byte)
case blacklist.FieldID:
values[i] = new(sql.NullInt64) values[i] = new(sql.NullInt64)
case blacklist.FieldType, blacklist.FieldNotes: case blacklist.FieldType, blacklist.FieldTorrentHash, blacklist.FieldTorrentName, blacklist.FieldNotes:
values[i] = new(sql.NullString) values[i] = new(sql.NullString)
case blacklist.FieldCreateTime:
values[i] = new(sql.NullTime)
default: default:
values[i] = new(sql.UnknownType) values[i] = new(sql.UnknownType)
} }
@@ -65,13 +70,29 @@ func (b *Blacklist) assignValues(columns []string, values []any) error {
} else if value.Valid { } else if value.Valid {
b.Type = blacklist.Type(value.String) b.Type = blacklist.Type(value.String)
} }
case blacklist.FieldValue: case blacklist.FieldTorrentHash:
if value, ok := values[i].(*[]byte); !ok { if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field value", values[i]) return fmt.Errorf("unexpected type %T for field torrent_hash", values[i])
} else if value != nil && len(*value) > 0 { } else if value.Valid {
if err := json.Unmarshal(*value, &b.Value); err != nil { b.TorrentHash = value.String
return fmt.Errorf("unmarshal field value: %w", err) }
} case blacklist.FieldTorrentName:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field torrent_name", values[i])
} else if value.Valid {
b.TorrentName = value.String
}
case blacklist.FieldMediaID:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field media_id", values[i])
} else if value.Valid {
b.MediaID = int(value.Int64)
}
case blacklist.FieldCreateTime:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field create_time", values[i])
} else if value.Valid {
b.CreateTime = value.Time
} }
case blacklist.FieldNotes: case blacklist.FieldNotes:
if value, ok := values[i].(*sql.NullString); !ok { if value, ok := values[i].(*sql.NullString); !ok {
@@ -86,9 +107,9 @@ func (b *Blacklist) assignValues(columns []string, values []any) error {
return nil return nil
} }
// GetValue returns the ent.Value that was dynamically selected and assigned to the Blacklist. // Value returns the ent.Value that was dynamically selected and assigned to the Blacklist.
// This includes values selected through modifiers, order, etc. // This includes values selected through modifiers, order, etc.
func (b *Blacklist) GetValue(name string) (ent.Value, error) { func (b *Blacklist) Value(name string) (ent.Value, error) {
return b.selectValues.Get(name) return b.selectValues.Get(name)
} }
@@ -118,8 +139,17 @@ func (b *Blacklist) String() string {
builder.WriteString("type=") builder.WriteString("type=")
builder.WriteString(fmt.Sprintf("%v", b.Type)) builder.WriteString(fmt.Sprintf("%v", b.Type))
builder.WriteString(", ") builder.WriteString(", ")
builder.WriteString("value=") builder.WriteString("torrent_hash=")
builder.WriteString(fmt.Sprintf("%v", b.Value)) builder.WriteString(b.TorrentHash)
builder.WriteString(", ")
builder.WriteString("torrent_name=")
builder.WriteString(b.TorrentName)
builder.WriteString(", ")
builder.WriteString("media_id=")
builder.WriteString(fmt.Sprintf("%v", b.MediaID))
builder.WriteString(", ")
builder.WriteString("create_time=")
builder.WriteString(b.CreateTime.Format(time.ANSIC))
builder.WriteString(", ") builder.WriteString(", ")
builder.WriteString("notes=") builder.WriteString("notes=")
builder.WriteString(b.Notes) builder.WriteString(b.Notes)

View File

@@ -4,7 +4,7 @@ package blacklist
import ( import (
"fmt" "fmt"
"polaris/ent/schema" "time"
"entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql"
) )
@@ -16,8 +16,14 @@ const (
FieldID = "id" FieldID = "id"
// FieldType holds the string denoting the type field in the database. // FieldType holds the string denoting the type field in the database.
FieldType = "type" FieldType = "type"
// FieldValue holds the string denoting the value field in the database. // FieldTorrentHash holds the string denoting the torrent_hash field in the database.
FieldValue = "value" FieldTorrentHash = "torrent_hash"
// FieldTorrentName holds the string denoting the torrent_name field in the database.
FieldTorrentName = "torrent_name"
// FieldMediaID holds the string denoting the media_id field in the database.
FieldMediaID = "media_id"
// FieldCreateTime holds the string denoting the create_time field in the database.
FieldCreateTime = "create_time"
// FieldNotes holds the string denoting the notes field in the database. // FieldNotes holds the string denoting the notes field in the database.
FieldNotes = "notes" FieldNotes = "notes"
// Table holds the table name of the blacklist in the database. // Table holds the table name of the blacklist in the database.
@@ -28,7 +34,10 @@ const (
var Columns = []string{ var Columns = []string{
FieldID, FieldID,
FieldType, FieldType,
FieldValue, FieldTorrentHash,
FieldTorrentName,
FieldMediaID,
FieldCreateTime,
FieldNotes, FieldNotes,
} }
@@ -43,13 +52,16 @@ func ValidColumn(column string) bool {
} }
var ( var (
// DefaultValue holds the default value on creation for the "value" field. // DefaultCreateTime holds the default value on creation for the "create_time" field.
DefaultValue schema.BlacklistValue DefaultCreateTime func() time.Time
) )
// Type defines the type for the "type" enum field. // Type defines the type for the "type" enum field.
type Type string type Type string
// TypeTorrent is the default value of the Type enum.
const DefaultType = TypeTorrent
// Type values. // Type values.
const ( const (
TypeMedia Type = "media" TypeMedia Type = "media"
@@ -83,6 +95,26 @@ func ByType(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldType, opts...).ToFunc() return sql.OrderByField(FieldType, opts...).ToFunc()
} }
// ByTorrentHash orders the results by the torrent_hash field.
func ByTorrentHash(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldTorrentHash, opts...).ToFunc()
}
// ByTorrentName orders the results by the torrent_name field.
func ByTorrentName(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldTorrentName, opts...).ToFunc()
}
// ByMediaID orders the results by the media_id field.
func ByMediaID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldMediaID, opts...).ToFunc()
}
// ByCreateTime orders the results by the create_time field.
func ByCreateTime(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldCreateTime, opts...).ToFunc()
}
// ByNotes orders the results by the notes field. // ByNotes orders the results by the notes field.
func ByNotes(opts ...sql.OrderTermOption) OrderOption { func ByNotes(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldNotes, opts...).ToFunc() return sql.OrderByField(FieldNotes, opts...).ToFunc()

View File

@@ -4,6 +4,7 @@ package blacklist
import ( import (
"polaris/ent/predicate" "polaris/ent/predicate"
"time"
"entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql"
) )
@@ -53,6 +54,26 @@ func IDLTE(id int) predicate.Blacklist {
return predicate.Blacklist(sql.FieldLTE(FieldID, id)) return predicate.Blacklist(sql.FieldLTE(FieldID, id))
} }
// TorrentHash applies equality check predicate on the "torrent_hash" field. It's identical to TorrentHashEQ.
func TorrentHash(v string) predicate.Blacklist {
return predicate.Blacklist(sql.FieldEQ(FieldTorrentHash, v))
}
// TorrentName applies equality check predicate on the "torrent_name" field. It's identical to TorrentNameEQ.
func TorrentName(v string) predicate.Blacklist {
return predicate.Blacklist(sql.FieldEQ(FieldTorrentName, v))
}
// MediaID applies equality check predicate on the "media_id" field. It's identical to MediaIDEQ.
func MediaID(v int) predicate.Blacklist {
return predicate.Blacklist(sql.FieldEQ(FieldMediaID, v))
}
// CreateTime applies equality check predicate on the "create_time" field. It's identical to CreateTimeEQ.
func CreateTime(v time.Time) predicate.Blacklist {
return predicate.Blacklist(sql.FieldEQ(FieldCreateTime, v))
}
// Notes applies equality check predicate on the "notes" field. It's identical to NotesEQ. // Notes applies equality check predicate on the "notes" field. It's identical to NotesEQ.
func Notes(v string) predicate.Blacklist { func Notes(v string) predicate.Blacklist {
return predicate.Blacklist(sql.FieldEQ(FieldNotes, v)) return predicate.Blacklist(sql.FieldEQ(FieldNotes, v))
@@ -78,6 +99,256 @@ func TypeNotIn(vs ...Type) predicate.Blacklist {
return predicate.Blacklist(sql.FieldNotIn(FieldType, vs...)) return predicate.Blacklist(sql.FieldNotIn(FieldType, vs...))
} }
// TorrentHashEQ applies the EQ predicate on the "torrent_hash" field.
func TorrentHashEQ(v string) predicate.Blacklist {
return predicate.Blacklist(sql.FieldEQ(FieldTorrentHash, v))
}
// TorrentHashNEQ applies the NEQ predicate on the "torrent_hash" field.
func TorrentHashNEQ(v string) predicate.Blacklist {
return predicate.Blacklist(sql.FieldNEQ(FieldTorrentHash, v))
}
// TorrentHashIn applies the In predicate on the "torrent_hash" field.
func TorrentHashIn(vs ...string) predicate.Blacklist {
return predicate.Blacklist(sql.FieldIn(FieldTorrentHash, vs...))
}
// TorrentHashNotIn applies the NotIn predicate on the "torrent_hash" field.
func TorrentHashNotIn(vs ...string) predicate.Blacklist {
return predicate.Blacklist(sql.FieldNotIn(FieldTorrentHash, vs...))
}
// TorrentHashGT applies the GT predicate on the "torrent_hash" field.
func TorrentHashGT(v string) predicate.Blacklist {
return predicate.Blacklist(sql.FieldGT(FieldTorrentHash, v))
}
// TorrentHashGTE applies the GTE predicate on the "torrent_hash" field.
func TorrentHashGTE(v string) predicate.Blacklist {
return predicate.Blacklist(sql.FieldGTE(FieldTorrentHash, v))
}
// TorrentHashLT applies the LT predicate on the "torrent_hash" field.
func TorrentHashLT(v string) predicate.Blacklist {
return predicate.Blacklist(sql.FieldLT(FieldTorrentHash, v))
}
// TorrentHashLTE applies the LTE predicate on the "torrent_hash" field.
func TorrentHashLTE(v string) predicate.Blacklist {
return predicate.Blacklist(sql.FieldLTE(FieldTorrentHash, v))
}
// TorrentHashContains applies the Contains predicate on the "torrent_hash" field.
func TorrentHashContains(v string) predicate.Blacklist {
return predicate.Blacklist(sql.FieldContains(FieldTorrentHash, v))
}
// TorrentHashHasPrefix applies the HasPrefix predicate on the "torrent_hash" field.
func TorrentHashHasPrefix(v string) predicate.Blacklist {
return predicate.Blacklist(sql.FieldHasPrefix(FieldTorrentHash, v))
}
// TorrentHashHasSuffix applies the HasSuffix predicate on the "torrent_hash" field.
func TorrentHashHasSuffix(v string) predicate.Blacklist {
return predicate.Blacklist(sql.FieldHasSuffix(FieldTorrentHash, v))
}
// TorrentHashIsNil applies the IsNil predicate on the "torrent_hash" field.
func TorrentHashIsNil() predicate.Blacklist {
return predicate.Blacklist(sql.FieldIsNull(FieldTorrentHash))
}
// TorrentHashNotNil applies the NotNil predicate on the "torrent_hash" field.
func TorrentHashNotNil() predicate.Blacklist {
return predicate.Blacklist(sql.FieldNotNull(FieldTorrentHash))
}
// TorrentHashEqualFold applies the EqualFold predicate on the "torrent_hash" field.
func TorrentHashEqualFold(v string) predicate.Blacklist {
return predicate.Blacklist(sql.FieldEqualFold(FieldTorrentHash, v))
}
// TorrentHashContainsFold applies the ContainsFold predicate on the "torrent_hash" field.
func TorrentHashContainsFold(v string) predicate.Blacklist {
return predicate.Blacklist(sql.FieldContainsFold(FieldTorrentHash, v))
}
// TorrentNameEQ applies the EQ predicate on the "torrent_name" field.
func TorrentNameEQ(v string) predicate.Blacklist {
return predicate.Blacklist(sql.FieldEQ(FieldTorrentName, v))
}
// TorrentNameNEQ applies the NEQ predicate on the "torrent_name" field.
func TorrentNameNEQ(v string) predicate.Blacklist {
return predicate.Blacklist(sql.FieldNEQ(FieldTorrentName, v))
}
// TorrentNameIn applies the In predicate on the "torrent_name" field.
func TorrentNameIn(vs ...string) predicate.Blacklist {
return predicate.Blacklist(sql.FieldIn(FieldTorrentName, vs...))
}
// TorrentNameNotIn applies the NotIn predicate on the "torrent_name" field.
func TorrentNameNotIn(vs ...string) predicate.Blacklist {
return predicate.Blacklist(sql.FieldNotIn(FieldTorrentName, vs...))
}
// TorrentNameGT applies the GT predicate on the "torrent_name" field.
func TorrentNameGT(v string) predicate.Blacklist {
return predicate.Blacklist(sql.FieldGT(FieldTorrentName, v))
}
// TorrentNameGTE applies the GTE predicate on the "torrent_name" field.
func TorrentNameGTE(v string) predicate.Blacklist {
return predicate.Blacklist(sql.FieldGTE(FieldTorrentName, v))
}
// TorrentNameLT applies the LT predicate on the "torrent_name" field.
func TorrentNameLT(v string) predicate.Blacklist {
return predicate.Blacklist(sql.FieldLT(FieldTorrentName, v))
}
// TorrentNameLTE applies the LTE predicate on the "torrent_name" field.
func TorrentNameLTE(v string) predicate.Blacklist {
return predicate.Blacklist(sql.FieldLTE(FieldTorrentName, v))
}
// TorrentNameContains applies the Contains predicate on the "torrent_name" field.
func TorrentNameContains(v string) predicate.Blacklist {
return predicate.Blacklist(sql.FieldContains(FieldTorrentName, v))
}
// TorrentNameHasPrefix applies the HasPrefix predicate on the "torrent_name" field.
func TorrentNameHasPrefix(v string) predicate.Blacklist {
return predicate.Blacklist(sql.FieldHasPrefix(FieldTorrentName, v))
}
// TorrentNameHasSuffix applies the HasSuffix predicate on the "torrent_name" field.
func TorrentNameHasSuffix(v string) predicate.Blacklist {
return predicate.Blacklist(sql.FieldHasSuffix(FieldTorrentName, v))
}
// TorrentNameIsNil applies the IsNil predicate on the "torrent_name" field.
func TorrentNameIsNil() predicate.Blacklist {
return predicate.Blacklist(sql.FieldIsNull(FieldTorrentName))
}
// TorrentNameNotNil applies the NotNil predicate on the "torrent_name" field.
func TorrentNameNotNil() predicate.Blacklist {
return predicate.Blacklist(sql.FieldNotNull(FieldTorrentName))
}
// TorrentNameEqualFold applies the EqualFold predicate on the "torrent_name" field.
func TorrentNameEqualFold(v string) predicate.Blacklist {
return predicate.Blacklist(sql.FieldEqualFold(FieldTorrentName, v))
}
// TorrentNameContainsFold applies the ContainsFold predicate on the "torrent_name" field.
func TorrentNameContainsFold(v string) predicate.Blacklist {
return predicate.Blacklist(sql.FieldContainsFold(FieldTorrentName, v))
}
// MediaIDEQ applies the EQ predicate on the "media_id" field.
func MediaIDEQ(v int) predicate.Blacklist {
return predicate.Blacklist(sql.FieldEQ(FieldMediaID, v))
}
// MediaIDNEQ applies the NEQ predicate on the "media_id" field.
func MediaIDNEQ(v int) predicate.Blacklist {
return predicate.Blacklist(sql.FieldNEQ(FieldMediaID, v))
}
// MediaIDIn applies the In predicate on the "media_id" field.
func MediaIDIn(vs ...int) predicate.Blacklist {
return predicate.Blacklist(sql.FieldIn(FieldMediaID, vs...))
}
// MediaIDNotIn applies the NotIn predicate on the "media_id" field.
func MediaIDNotIn(vs ...int) predicate.Blacklist {
return predicate.Blacklist(sql.FieldNotIn(FieldMediaID, vs...))
}
// MediaIDGT applies the GT predicate on the "media_id" field.
func MediaIDGT(v int) predicate.Blacklist {
return predicate.Blacklist(sql.FieldGT(FieldMediaID, v))
}
// MediaIDGTE applies the GTE predicate on the "media_id" field.
func MediaIDGTE(v int) predicate.Blacklist {
return predicate.Blacklist(sql.FieldGTE(FieldMediaID, v))
}
// MediaIDLT applies the LT predicate on the "media_id" field.
func MediaIDLT(v int) predicate.Blacklist {
return predicate.Blacklist(sql.FieldLT(FieldMediaID, v))
}
// MediaIDLTE applies the LTE predicate on the "media_id" field.
func MediaIDLTE(v int) predicate.Blacklist {
return predicate.Blacklist(sql.FieldLTE(FieldMediaID, v))
}
// MediaIDIsNil applies the IsNil predicate on the "media_id" field.
func MediaIDIsNil() predicate.Blacklist {
return predicate.Blacklist(sql.FieldIsNull(FieldMediaID))
}
// MediaIDNotNil applies the NotNil predicate on the "media_id" field.
func MediaIDNotNil() predicate.Blacklist {
return predicate.Blacklist(sql.FieldNotNull(FieldMediaID))
}
// CreateTimeEQ applies the EQ predicate on the "create_time" field.
func CreateTimeEQ(v time.Time) predicate.Blacklist {
return predicate.Blacklist(sql.FieldEQ(FieldCreateTime, v))
}
// CreateTimeNEQ applies the NEQ predicate on the "create_time" field.
func CreateTimeNEQ(v time.Time) predicate.Blacklist {
return predicate.Blacklist(sql.FieldNEQ(FieldCreateTime, v))
}
// CreateTimeIn applies the In predicate on the "create_time" field.
func CreateTimeIn(vs ...time.Time) predicate.Blacklist {
return predicate.Blacklist(sql.FieldIn(FieldCreateTime, vs...))
}
// CreateTimeNotIn applies the NotIn predicate on the "create_time" field.
func CreateTimeNotIn(vs ...time.Time) predicate.Blacklist {
return predicate.Blacklist(sql.FieldNotIn(FieldCreateTime, vs...))
}
// CreateTimeGT applies the GT predicate on the "create_time" field.
func CreateTimeGT(v time.Time) predicate.Blacklist {
return predicate.Blacklist(sql.FieldGT(FieldCreateTime, v))
}
// CreateTimeGTE applies the GTE predicate on the "create_time" field.
func CreateTimeGTE(v time.Time) predicate.Blacklist {
return predicate.Blacklist(sql.FieldGTE(FieldCreateTime, v))
}
// CreateTimeLT applies the LT predicate on the "create_time" field.
func CreateTimeLT(v time.Time) predicate.Blacklist {
return predicate.Blacklist(sql.FieldLT(FieldCreateTime, v))
}
// CreateTimeLTE applies the LTE predicate on the "create_time" field.
func CreateTimeLTE(v time.Time) predicate.Blacklist {
return predicate.Blacklist(sql.FieldLTE(FieldCreateTime, v))
}
// CreateTimeIsNil applies the IsNil predicate on the "create_time" field.
func CreateTimeIsNil() predicate.Blacklist {
return predicate.Blacklist(sql.FieldIsNull(FieldCreateTime))
}
// CreateTimeNotNil applies the NotNil predicate on the "create_time" field.
func CreateTimeNotNil() predicate.Blacklist {
return predicate.Blacklist(sql.FieldNotNull(FieldCreateTime))
}
// NotesEQ applies the EQ predicate on the "notes" field. // NotesEQ applies the EQ predicate on the "notes" field.
func NotesEQ(v string) predicate.Blacklist { func NotesEQ(v string) predicate.Blacklist {
return predicate.Blacklist(sql.FieldEQ(FieldNotes, v)) return predicate.Blacklist(sql.FieldEQ(FieldNotes, v))

View File

@@ -7,7 +7,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"polaris/ent/blacklist" "polaris/ent/blacklist"
"polaris/ent/schema" "time"
"entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field" "entgo.io/ent/schema/field"
@@ -26,16 +26,66 @@ func (bc *BlacklistCreate) SetType(b blacklist.Type) *BlacklistCreate {
return bc return bc
} }
// SetValue sets the "value" field. // SetNillableType sets the "type" field if the given value is not nil.
func (bc *BlacklistCreate) SetValue(sv schema.BlacklistValue) *BlacklistCreate { func (bc *BlacklistCreate) SetNillableType(b *blacklist.Type) *BlacklistCreate {
bc.mutation.SetValue(sv) if b != nil {
bc.SetType(*b)
}
return bc return bc
} }
// SetNillableValue sets the "value" field if the given value is not nil. // SetTorrentHash sets the "torrent_hash" field.
func (bc *BlacklistCreate) SetNillableValue(sv *schema.BlacklistValue) *BlacklistCreate { func (bc *BlacklistCreate) SetTorrentHash(s string) *BlacklistCreate {
if sv != nil { bc.mutation.SetTorrentHash(s)
bc.SetValue(*sv) return bc
}
// SetNillableTorrentHash sets the "torrent_hash" field if the given value is not nil.
func (bc *BlacklistCreate) SetNillableTorrentHash(s *string) *BlacklistCreate {
if s != nil {
bc.SetTorrentHash(*s)
}
return bc
}
// SetTorrentName sets the "torrent_name" field.
func (bc *BlacklistCreate) SetTorrentName(s string) *BlacklistCreate {
bc.mutation.SetTorrentName(s)
return bc
}
// SetNillableTorrentName sets the "torrent_name" field if the given value is not nil.
func (bc *BlacklistCreate) SetNillableTorrentName(s *string) *BlacklistCreate {
if s != nil {
bc.SetTorrentName(*s)
}
return bc
}
// SetMediaID sets the "media_id" field.
func (bc *BlacklistCreate) SetMediaID(i int) *BlacklistCreate {
bc.mutation.SetMediaID(i)
return bc
}
// SetNillableMediaID sets the "media_id" field if the given value is not nil.
func (bc *BlacklistCreate) SetNillableMediaID(i *int) *BlacklistCreate {
if i != nil {
bc.SetMediaID(*i)
}
return bc
}
// SetCreateTime sets the "create_time" field.
func (bc *BlacklistCreate) SetCreateTime(t time.Time) *BlacklistCreate {
bc.mutation.SetCreateTime(t)
return bc
}
// SetNillableCreateTime sets the "create_time" field if the given value is not nil.
func (bc *BlacklistCreate) SetNillableCreateTime(t *time.Time) *BlacklistCreate {
if t != nil {
bc.SetCreateTime(*t)
} }
return bc return bc
} }
@@ -89,9 +139,13 @@ func (bc *BlacklistCreate) ExecX(ctx context.Context) {
// defaults sets the default values of the builder before save. // defaults sets the default values of the builder before save.
func (bc *BlacklistCreate) defaults() { func (bc *BlacklistCreate) defaults() {
if _, ok := bc.mutation.Value(); !ok { if _, ok := bc.mutation.GetType(); !ok {
v := blacklist.DefaultValue v := blacklist.DefaultType
bc.mutation.SetValue(v) bc.mutation.SetType(v)
}
if _, ok := bc.mutation.CreateTime(); !ok {
v := blacklist.DefaultCreateTime()
bc.mutation.SetCreateTime(v)
} }
} }
@@ -105,9 +159,6 @@ func (bc *BlacklistCreate) check() error {
return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "Blacklist.type": %w`, err)} return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "Blacklist.type": %w`, err)}
} }
} }
if _, ok := bc.mutation.Value(); !ok {
return &ValidationError{Name: "value", err: errors.New(`ent: missing required field "Blacklist.value"`)}
}
return nil return nil
} }
@@ -138,9 +189,21 @@ func (bc *BlacklistCreate) createSpec() (*Blacklist, *sqlgraph.CreateSpec) {
_spec.SetField(blacklist.FieldType, field.TypeEnum, value) _spec.SetField(blacklist.FieldType, field.TypeEnum, value)
_node.Type = value _node.Type = value
} }
if value, ok := bc.mutation.Value(); ok { if value, ok := bc.mutation.TorrentHash(); ok {
_spec.SetField(blacklist.FieldValue, field.TypeJSON, value) _spec.SetField(blacklist.FieldTorrentHash, field.TypeString, value)
_node.Value = value _node.TorrentHash = value
}
if value, ok := bc.mutation.TorrentName(); ok {
_spec.SetField(blacklist.FieldTorrentName, field.TypeString, value)
_node.TorrentName = value
}
if value, ok := bc.mutation.MediaID(); ok {
_spec.SetField(blacklist.FieldMediaID, field.TypeInt, value)
_node.MediaID = value
}
if value, ok := bc.mutation.CreateTime(); ok {
_spec.SetField(blacklist.FieldCreateTime, field.TypeTime, value)
_node.CreateTime = value
} }
if value, ok := bc.mutation.Notes(); ok { if value, ok := bc.mutation.Notes(); ok {
_spec.SetField(blacklist.FieldNotes, field.TypeString, value) _spec.SetField(blacklist.FieldNotes, field.TypeString, value)

View File

@@ -8,7 +8,6 @@ import (
"fmt" "fmt"
"polaris/ent/blacklist" "polaris/ent/blacklist"
"polaris/ent/predicate" "polaris/ent/predicate"
"polaris/ent/schema"
"entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/dialect/sql/sqlgraph"
@@ -42,20 +41,73 @@ func (bu *BlacklistUpdate) SetNillableType(b *blacklist.Type) *BlacklistUpdate {
return bu return bu
} }
// SetValue sets the "value" field. // SetTorrentHash sets the "torrent_hash" field.
func (bu *BlacklistUpdate) SetValue(sv schema.BlacklistValue) *BlacklistUpdate { func (bu *BlacklistUpdate) SetTorrentHash(s string) *BlacklistUpdate {
bu.mutation.SetValue(sv) bu.mutation.SetTorrentHash(s)
return bu return bu
} }
// SetNillableValue sets the "value" field if the given value is not nil. // SetNillableTorrentHash sets the "torrent_hash" field if the given value is not nil.
func (bu *BlacklistUpdate) SetNillableValue(sv *schema.BlacklistValue) *BlacklistUpdate { func (bu *BlacklistUpdate) SetNillableTorrentHash(s *string) *BlacklistUpdate {
if sv != nil { if s != nil {
bu.SetValue(*sv) bu.SetTorrentHash(*s)
} }
return bu return bu
} }
// ClearTorrentHash clears the value of the "torrent_hash" field.
func (bu *BlacklistUpdate) ClearTorrentHash() *BlacklistUpdate {
bu.mutation.ClearTorrentHash()
return bu
}
// SetTorrentName sets the "torrent_name" field.
func (bu *BlacklistUpdate) SetTorrentName(s string) *BlacklistUpdate {
bu.mutation.SetTorrentName(s)
return bu
}
// SetNillableTorrentName sets the "torrent_name" field if the given value is not nil.
func (bu *BlacklistUpdate) SetNillableTorrentName(s *string) *BlacklistUpdate {
if s != nil {
bu.SetTorrentName(*s)
}
return bu
}
// ClearTorrentName clears the value of the "torrent_name" field.
func (bu *BlacklistUpdate) ClearTorrentName() *BlacklistUpdate {
bu.mutation.ClearTorrentName()
return bu
}
// SetMediaID sets the "media_id" field.
func (bu *BlacklistUpdate) SetMediaID(i int) *BlacklistUpdate {
bu.mutation.ResetMediaID()
bu.mutation.SetMediaID(i)
return bu
}
// SetNillableMediaID sets the "media_id" field if the given value is not nil.
func (bu *BlacklistUpdate) SetNillableMediaID(i *int) *BlacklistUpdate {
if i != nil {
bu.SetMediaID(*i)
}
return bu
}
// AddMediaID adds i to the "media_id" field.
func (bu *BlacklistUpdate) AddMediaID(i int) *BlacklistUpdate {
bu.mutation.AddMediaID(i)
return bu
}
// ClearMediaID clears the value of the "media_id" field.
func (bu *BlacklistUpdate) ClearMediaID() *BlacklistUpdate {
bu.mutation.ClearMediaID()
return bu
}
// SetNotes sets the "notes" field. // SetNotes sets the "notes" field.
func (bu *BlacklistUpdate) SetNotes(s string) *BlacklistUpdate { func (bu *BlacklistUpdate) SetNotes(s string) *BlacklistUpdate {
bu.mutation.SetNotes(s) bu.mutation.SetNotes(s)
@@ -133,8 +185,29 @@ func (bu *BlacklistUpdate) sqlSave(ctx context.Context) (n int, err error) {
if value, ok := bu.mutation.GetType(); ok { if value, ok := bu.mutation.GetType(); ok {
_spec.SetField(blacklist.FieldType, field.TypeEnum, value) _spec.SetField(blacklist.FieldType, field.TypeEnum, value)
} }
if value, ok := bu.mutation.Value(); ok { if value, ok := bu.mutation.TorrentHash(); ok {
_spec.SetField(blacklist.FieldValue, field.TypeJSON, value) _spec.SetField(blacklist.FieldTorrentHash, field.TypeString, value)
}
if bu.mutation.TorrentHashCleared() {
_spec.ClearField(blacklist.FieldTorrentHash, field.TypeString)
}
if value, ok := bu.mutation.TorrentName(); ok {
_spec.SetField(blacklist.FieldTorrentName, field.TypeString, value)
}
if bu.mutation.TorrentNameCleared() {
_spec.ClearField(blacklist.FieldTorrentName, field.TypeString)
}
if value, ok := bu.mutation.MediaID(); ok {
_spec.SetField(blacklist.FieldMediaID, field.TypeInt, value)
}
if value, ok := bu.mutation.AddedMediaID(); ok {
_spec.AddField(blacklist.FieldMediaID, field.TypeInt, value)
}
if bu.mutation.MediaIDCleared() {
_spec.ClearField(blacklist.FieldMediaID, field.TypeInt)
}
if bu.mutation.CreateTimeCleared() {
_spec.ClearField(blacklist.FieldCreateTime, field.TypeTime)
} }
if value, ok := bu.mutation.Notes(); ok { if value, ok := bu.mutation.Notes(); ok {
_spec.SetField(blacklist.FieldNotes, field.TypeString, value) _spec.SetField(blacklist.FieldNotes, field.TypeString, value)
@@ -176,20 +249,73 @@ func (buo *BlacklistUpdateOne) SetNillableType(b *blacklist.Type) *BlacklistUpda
return buo return buo
} }
// SetValue sets the "value" field. // SetTorrentHash sets the "torrent_hash" field.
func (buo *BlacklistUpdateOne) SetValue(sv schema.BlacklistValue) *BlacklistUpdateOne { func (buo *BlacklistUpdateOne) SetTorrentHash(s string) *BlacklistUpdateOne {
buo.mutation.SetValue(sv) buo.mutation.SetTorrentHash(s)
return buo return buo
} }
// SetNillableValue sets the "value" field if the given value is not nil. // SetNillableTorrentHash sets the "torrent_hash" field if the given value is not nil.
func (buo *BlacklistUpdateOne) SetNillableValue(sv *schema.BlacklistValue) *BlacklistUpdateOne { func (buo *BlacklistUpdateOne) SetNillableTorrentHash(s *string) *BlacklistUpdateOne {
if sv != nil { if s != nil {
buo.SetValue(*sv) buo.SetTorrentHash(*s)
} }
return buo return buo
} }
// ClearTorrentHash clears the value of the "torrent_hash" field.
func (buo *BlacklistUpdateOne) ClearTorrentHash() *BlacklistUpdateOne {
buo.mutation.ClearTorrentHash()
return buo
}
// SetTorrentName sets the "torrent_name" field.
func (buo *BlacklistUpdateOne) SetTorrentName(s string) *BlacklistUpdateOne {
buo.mutation.SetTorrentName(s)
return buo
}
// SetNillableTorrentName sets the "torrent_name" field if the given value is not nil.
func (buo *BlacklistUpdateOne) SetNillableTorrentName(s *string) *BlacklistUpdateOne {
if s != nil {
buo.SetTorrentName(*s)
}
return buo
}
// ClearTorrentName clears the value of the "torrent_name" field.
func (buo *BlacklistUpdateOne) ClearTorrentName() *BlacklistUpdateOne {
buo.mutation.ClearTorrentName()
return buo
}
// SetMediaID sets the "media_id" field.
func (buo *BlacklistUpdateOne) SetMediaID(i int) *BlacklistUpdateOne {
buo.mutation.ResetMediaID()
buo.mutation.SetMediaID(i)
return buo
}
// SetNillableMediaID sets the "media_id" field if the given value is not nil.
func (buo *BlacklistUpdateOne) SetNillableMediaID(i *int) *BlacklistUpdateOne {
if i != nil {
buo.SetMediaID(*i)
}
return buo
}
// AddMediaID adds i to the "media_id" field.
func (buo *BlacklistUpdateOne) AddMediaID(i int) *BlacklistUpdateOne {
buo.mutation.AddMediaID(i)
return buo
}
// ClearMediaID clears the value of the "media_id" field.
func (buo *BlacklistUpdateOne) ClearMediaID() *BlacklistUpdateOne {
buo.mutation.ClearMediaID()
return buo
}
// SetNotes sets the "notes" field. // SetNotes sets the "notes" field.
func (buo *BlacklistUpdateOne) SetNotes(s string) *BlacklistUpdateOne { func (buo *BlacklistUpdateOne) SetNotes(s string) *BlacklistUpdateOne {
buo.mutation.SetNotes(s) buo.mutation.SetNotes(s)
@@ -297,8 +423,29 @@ func (buo *BlacklistUpdateOne) sqlSave(ctx context.Context) (_node *Blacklist, e
if value, ok := buo.mutation.GetType(); ok { if value, ok := buo.mutation.GetType(); ok {
_spec.SetField(blacklist.FieldType, field.TypeEnum, value) _spec.SetField(blacklist.FieldType, field.TypeEnum, value)
} }
if value, ok := buo.mutation.Value(); ok { if value, ok := buo.mutation.TorrentHash(); ok {
_spec.SetField(blacklist.FieldValue, field.TypeJSON, value) _spec.SetField(blacklist.FieldTorrentHash, field.TypeString, value)
}
if buo.mutation.TorrentHashCleared() {
_spec.ClearField(blacklist.FieldTorrentHash, field.TypeString)
}
if value, ok := buo.mutation.TorrentName(); ok {
_spec.SetField(blacklist.FieldTorrentName, field.TypeString, value)
}
if buo.mutation.TorrentNameCleared() {
_spec.ClearField(blacklist.FieldTorrentName, field.TypeString)
}
if value, ok := buo.mutation.MediaID(); ok {
_spec.SetField(blacklist.FieldMediaID, field.TypeInt, value)
}
if value, ok := buo.mutation.AddedMediaID(); ok {
_spec.AddField(blacklist.FieldMediaID, field.TypeInt, value)
}
if buo.mutation.MediaIDCleared() {
_spec.ClearField(blacklist.FieldMediaID, field.TypeInt)
}
if buo.mutation.CreateTimeCleared() {
_spec.ClearField(blacklist.FieldCreateTime, field.TypeTime)
} }
if value, ok := buo.mutation.Notes(); ok { if value, ok := buo.mutation.Notes(); ok {
_spec.SetField(blacklist.FieldNotes, field.TypeString, value) _spec.SetField(blacklist.FieldNotes, field.TypeString, value)

View File

@@ -36,7 +36,7 @@ type History struct {
DownloadClientID int `json:"download_client_id,omitempty"` DownloadClientID int `json:"download_client_id,omitempty"`
// IndexerID holds the value of the "indexer_id" field. // IndexerID holds the value of the "indexer_id" field.
IndexerID int `json:"indexer_id,omitempty"` IndexerID int `json:"indexer_id,omitempty"`
// deprecated, use hash instead // torrent link
Link string `json:"link,omitempty"` Link string `json:"link,omitempty"`
// torrent hash // torrent hash
Hash string `json:"hash,omitempty"` Hash string `json:"hash,omitempty"`

View File

@@ -11,8 +11,11 @@ var (
// BlacklistsColumns holds the columns for the "blacklists" table. // BlacklistsColumns holds the columns for the "blacklists" table.
BlacklistsColumns = []*schema.Column{ BlacklistsColumns = []*schema.Column{
{Name: "id", Type: field.TypeInt, Increment: true}, {Name: "id", Type: field.TypeInt, Increment: true},
{Name: "type", Type: field.TypeEnum, Enums: []string{"media", "torrent"}}, {Name: "type", Type: field.TypeEnum, Enums: []string{"media", "torrent"}, Default: "torrent"},
{Name: "value", Type: field.TypeJSON}, {Name: "torrent_hash", Type: field.TypeString, Nullable: true},
{Name: "torrent_name", Type: field.TypeString, Nullable: true},
{Name: "media_id", Type: field.TypeInt, Nullable: true},
{Name: "create_time", Type: field.TypeTime, Nullable: true},
{Name: "notes", Type: field.TypeString, Nullable: true}, {Name: "notes", Type: field.TypeString, Nullable: true},
} }
// BlacklistsTable holds the schema information for the "blacklists" table. // BlacklistsTable holds the schema information for the "blacklists" table.

View File

@@ -53,7 +53,11 @@ type BlacklistMutation struct {
typ string typ string
id *int id *int
_type *blacklist.Type _type *blacklist.Type
value *schema.BlacklistValue torrent_hash *string
torrent_name *string
media_id *int
addmedia_id *int
create_time *time.Time
notes *string notes *string
clearedFields map[string]struct{} clearedFields map[string]struct{}
done bool done bool
@@ -195,40 +199,221 @@ func (m *BlacklistMutation) ResetType() {
m._type = nil m._type = nil
} }
// SetValue sets the "value" field. // SetTorrentHash sets the "torrent_hash" field.
func (m *BlacklistMutation) SetValue(sv schema.BlacklistValue) { func (m *BlacklistMutation) SetTorrentHash(s string) {
m.value = &sv m.torrent_hash = &s
} }
// Value returns the value of the "value" field in the mutation. // TorrentHash returns the value of the "torrent_hash" field in the mutation.
func (m *BlacklistMutation) Value() (r schema.BlacklistValue, exists bool) { func (m *BlacklistMutation) TorrentHash() (r string, exists bool) {
v := m.value v := m.torrent_hash
if v == nil { if v == nil {
return return
} }
return *v, true return *v, true
} }
// OldValue returns the old "value" field's value of the Blacklist entity. // OldTorrentHash returns the old "torrent_hash" field's value of the Blacklist entity.
// If the Blacklist object wasn't provided to the builder, the object is fetched from the database. // If the Blacklist 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 *BlacklistMutation) OldValue(ctx context.Context) (v schema.BlacklistValue, err error) { func (m *BlacklistMutation) OldTorrentHash(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) { if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldValue is only allowed on UpdateOne operations") return v, errors.New("OldTorrentHash is only allowed on UpdateOne operations")
} }
if m.id == nil || m.oldValue == nil { if m.id == nil || m.oldValue == nil {
return v, errors.New("OldValue requires an ID field in the mutation") return v, errors.New("OldTorrentHash 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 OldValue: %w", err) return v, fmt.Errorf("querying old value for OldTorrentHash: %w", err)
} }
return oldValue.Value, nil return oldValue.TorrentHash, nil
} }
// ResetValue resets all changes to the "value" field. // ClearTorrentHash clears the value of the "torrent_hash" field.
func (m *BlacklistMutation) ResetValue() { func (m *BlacklistMutation) ClearTorrentHash() {
m.value = nil m.torrent_hash = nil
m.clearedFields[blacklist.FieldTorrentHash] = struct{}{}
}
// TorrentHashCleared returns if the "torrent_hash" field was cleared in this mutation.
func (m *BlacklistMutation) TorrentHashCleared() bool {
_, ok := m.clearedFields[blacklist.FieldTorrentHash]
return ok
}
// ResetTorrentHash resets all changes to the "torrent_hash" field.
func (m *BlacklistMutation) ResetTorrentHash() {
m.torrent_hash = nil
delete(m.clearedFields, blacklist.FieldTorrentHash)
}
// SetTorrentName sets the "torrent_name" field.
func (m *BlacklistMutation) SetTorrentName(s string) {
m.torrent_name = &s
}
// TorrentName returns the value of the "torrent_name" field in the mutation.
func (m *BlacklistMutation) TorrentName() (r string, exists bool) {
v := m.torrent_name
if v == nil {
return
}
return *v, true
}
// OldTorrentName returns the old "torrent_name" field's value of the Blacklist entity.
// If the Blacklist 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 *BlacklistMutation) OldTorrentName(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldTorrentName is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldTorrentName requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldTorrentName: %w", err)
}
return oldValue.TorrentName, nil
}
// ClearTorrentName clears the value of the "torrent_name" field.
func (m *BlacklistMutation) ClearTorrentName() {
m.torrent_name = nil
m.clearedFields[blacklist.FieldTorrentName] = struct{}{}
}
// TorrentNameCleared returns if the "torrent_name" field was cleared in this mutation.
func (m *BlacklistMutation) TorrentNameCleared() bool {
_, ok := m.clearedFields[blacklist.FieldTorrentName]
return ok
}
// ResetTorrentName resets all changes to the "torrent_name" field.
func (m *BlacklistMutation) ResetTorrentName() {
m.torrent_name = nil
delete(m.clearedFields, blacklist.FieldTorrentName)
}
// SetMediaID sets the "media_id" field.
func (m *BlacklistMutation) SetMediaID(i int) {
m.media_id = &i
m.addmedia_id = nil
}
// MediaID returns the value of the "media_id" field in the mutation.
func (m *BlacklistMutation) MediaID() (r int, exists bool) {
v := m.media_id
if v == nil {
return
}
return *v, true
}
// OldMediaID returns the old "media_id" field's value of the Blacklist entity.
// If the Blacklist 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 *BlacklistMutation) OldMediaID(ctx context.Context) (v int, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldMediaID is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldMediaID requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldMediaID: %w", err)
}
return oldValue.MediaID, nil
}
// AddMediaID adds i to the "media_id" field.
func (m *BlacklistMutation) AddMediaID(i int) {
if m.addmedia_id != nil {
*m.addmedia_id += i
} else {
m.addmedia_id = &i
}
}
// AddedMediaID returns the value that was added to the "media_id" field in this mutation.
func (m *BlacklistMutation) AddedMediaID() (r int, exists bool) {
v := m.addmedia_id
if v == nil {
return
}
return *v, true
}
// ClearMediaID clears the value of the "media_id" field.
func (m *BlacklistMutation) ClearMediaID() {
m.media_id = nil
m.addmedia_id = nil
m.clearedFields[blacklist.FieldMediaID] = struct{}{}
}
// MediaIDCleared returns if the "media_id" field was cleared in this mutation.
func (m *BlacklistMutation) MediaIDCleared() bool {
_, ok := m.clearedFields[blacklist.FieldMediaID]
return ok
}
// ResetMediaID resets all changes to the "media_id" field.
func (m *BlacklistMutation) ResetMediaID() {
m.media_id = nil
m.addmedia_id = nil
delete(m.clearedFields, blacklist.FieldMediaID)
}
// SetCreateTime sets the "create_time" field.
func (m *BlacklistMutation) SetCreateTime(t time.Time) {
m.create_time = &t
}
// CreateTime returns the value of the "create_time" field in the mutation.
func (m *BlacklistMutation) CreateTime() (r time.Time, exists bool) {
v := m.create_time
if v == nil {
return
}
return *v, true
}
// OldCreateTime returns the old "create_time" field's value of the Blacklist entity.
// If the Blacklist 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 *BlacklistMutation) OldCreateTime(ctx context.Context) (v time.Time, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldCreateTime is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldCreateTime requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldCreateTime: %w", err)
}
return oldValue.CreateTime, nil
}
// ClearCreateTime clears the value of the "create_time" field.
func (m *BlacklistMutation) ClearCreateTime() {
m.create_time = nil
m.clearedFields[blacklist.FieldCreateTime] = struct{}{}
}
// CreateTimeCleared returns if the "create_time" field was cleared in this mutation.
func (m *BlacklistMutation) CreateTimeCleared() bool {
_, ok := m.clearedFields[blacklist.FieldCreateTime]
return ok
}
// ResetCreateTime resets all changes to the "create_time" field.
func (m *BlacklistMutation) ResetCreateTime() {
m.create_time = nil
delete(m.clearedFields, blacklist.FieldCreateTime)
} }
// SetNotes sets the "notes" field. // SetNotes sets the "notes" field.
@@ -314,12 +499,21 @@ func (m *BlacklistMutation) Type() string {
// order to get all numeric fields that were incremented/decremented, call // order to get all numeric fields that were incremented/decremented, call
// AddedFields(). // AddedFields().
func (m *BlacklistMutation) Fields() []string { func (m *BlacklistMutation) Fields() []string {
fields := make([]string, 0, 3) fields := make([]string, 0, 6)
if m._type != nil { if m._type != nil {
fields = append(fields, blacklist.FieldType) fields = append(fields, blacklist.FieldType)
} }
if m.value != nil { if m.torrent_hash != nil {
fields = append(fields, blacklist.FieldValue) fields = append(fields, blacklist.FieldTorrentHash)
}
if m.torrent_name != nil {
fields = append(fields, blacklist.FieldTorrentName)
}
if m.media_id != nil {
fields = append(fields, blacklist.FieldMediaID)
}
if m.create_time != nil {
fields = append(fields, blacklist.FieldCreateTime)
} }
if m.notes != nil { if m.notes != nil {
fields = append(fields, blacklist.FieldNotes) fields = append(fields, blacklist.FieldNotes)
@@ -334,8 +528,14 @@ func (m *BlacklistMutation) Field(name string) (ent.Value, bool) {
switch name { switch name {
case blacklist.FieldType: case blacklist.FieldType:
return m.GetType() return m.GetType()
case blacklist.FieldValue: case blacklist.FieldTorrentHash:
return m.Value() return m.TorrentHash()
case blacklist.FieldTorrentName:
return m.TorrentName()
case blacklist.FieldMediaID:
return m.MediaID()
case blacklist.FieldCreateTime:
return m.CreateTime()
case blacklist.FieldNotes: case blacklist.FieldNotes:
return m.Notes() return m.Notes()
} }
@@ -349,8 +549,14 @@ func (m *BlacklistMutation) OldField(ctx context.Context, name string) (ent.Valu
switch name { switch name {
case blacklist.FieldType: case blacklist.FieldType:
return m.OldType(ctx) return m.OldType(ctx)
case blacklist.FieldValue: case blacklist.FieldTorrentHash:
return m.OldValue(ctx) return m.OldTorrentHash(ctx)
case blacklist.FieldTorrentName:
return m.OldTorrentName(ctx)
case blacklist.FieldMediaID:
return m.OldMediaID(ctx)
case blacklist.FieldCreateTime:
return m.OldCreateTime(ctx)
case blacklist.FieldNotes: case blacklist.FieldNotes:
return m.OldNotes(ctx) return m.OldNotes(ctx)
} }
@@ -369,12 +575,33 @@ func (m *BlacklistMutation) SetField(name string, value ent.Value) error {
} }
m.SetType(v) m.SetType(v)
return nil return nil
case blacklist.FieldValue: case blacklist.FieldTorrentHash:
v, ok := value.(schema.BlacklistValue) v, ok := value.(string)
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.SetValue(v) m.SetTorrentHash(v)
return nil
case blacklist.FieldTorrentName:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetTorrentName(v)
return nil
case blacklist.FieldMediaID:
v, ok := value.(int)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetMediaID(v)
return nil
case blacklist.FieldCreateTime:
v, ok := value.(time.Time)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetCreateTime(v)
return nil return nil
case blacklist.FieldNotes: case blacklist.FieldNotes:
v, ok := value.(string) v, ok := value.(string)
@@ -390,13 +617,21 @@ func (m *BlacklistMutation) SetField(name string, value ent.Value) error {
// AddedFields returns all numeric fields that were incremented/decremented during // AddedFields returns all numeric fields that were incremented/decremented during
// this mutation. // this mutation.
func (m *BlacklistMutation) AddedFields() []string { func (m *BlacklistMutation) AddedFields() []string {
return nil var fields []string
if m.addmedia_id != nil {
fields = append(fields, blacklist.FieldMediaID)
}
return fields
} }
// AddedField returns the numeric value that was incremented/decremented on a field // AddedField returns the numeric value that was incremented/decremented on a field
// with the given name. The second boolean return value indicates that this field // with the given name. The second boolean return value indicates that this field
// was not set, or was not defined in the schema. // was not set, or was not defined in the schema.
func (m *BlacklistMutation) AddedField(name string) (ent.Value, bool) { func (m *BlacklistMutation) AddedField(name string) (ent.Value, bool) {
switch name {
case blacklist.FieldMediaID:
return m.AddedMediaID()
}
return nil, false return nil, false
} }
@@ -405,6 +640,13 @@ func (m *BlacklistMutation) AddedField(name string) (ent.Value, bool) {
// type. // type.
func (m *BlacklistMutation) AddField(name string, value ent.Value) error { func (m *BlacklistMutation) AddField(name string, value ent.Value) error {
switch name { switch name {
case blacklist.FieldMediaID:
v, ok := value.(int)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddMediaID(v)
return nil
} }
return fmt.Errorf("unknown Blacklist numeric field %s", name) return fmt.Errorf("unknown Blacklist numeric field %s", name)
} }
@@ -413,6 +655,18 @@ func (m *BlacklistMutation) AddField(name string, value ent.Value) error {
// mutation. // mutation.
func (m *BlacklistMutation) ClearedFields() []string { func (m *BlacklistMutation) ClearedFields() []string {
var fields []string var fields []string
if m.FieldCleared(blacklist.FieldTorrentHash) {
fields = append(fields, blacklist.FieldTorrentHash)
}
if m.FieldCleared(blacklist.FieldTorrentName) {
fields = append(fields, blacklist.FieldTorrentName)
}
if m.FieldCleared(blacklist.FieldMediaID) {
fields = append(fields, blacklist.FieldMediaID)
}
if m.FieldCleared(blacklist.FieldCreateTime) {
fields = append(fields, blacklist.FieldCreateTime)
}
if m.FieldCleared(blacklist.FieldNotes) { if m.FieldCleared(blacklist.FieldNotes) {
fields = append(fields, blacklist.FieldNotes) fields = append(fields, blacklist.FieldNotes)
} }
@@ -430,6 +684,18 @@ func (m *BlacklistMutation) FieldCleared(name string) bool {
// error if the field is not defined in the schema. // error if the field is not defined in the schema.
func (m *BlacklistMutation) ClearField(name string) error { func (m *BlacklistMutation) ClearField(name string) error {
switch name { switch name {
case blacklist.FieldTorrentHash:
m.ClearTorrentHash()
return nil
case blacklist.FieldTorrentName:
m.ClearTorrentName()
return nil
case blacklist.FieldMediaID:
m.ClearMediaID()
return nil
case blacklist.FieldCreateTime:
m.ClearCreateTime()
return nil
case blacklist.FieldNotes: case blacklist.FieldNotes:
m.ClearNotes() m.ClearNotes()
return nil return nil
@@ -444,8 +710,17 @@ func (m *BlacklistMutation) ResetField(name string) error {
case blacklist.FieldType: case blacklist.FieldType:
m.ResetType() m.ResetType()
return nil return nil
case blacklist.FieldValue: case blacklist.FieldTorrentHash:
m.ResetValue() m.ResetTorrentHash()
return nil
case blacklist.FieldTorrentName:
m.ResetTorrentName()
return nil
case blacklist.FieldMediaID:
m.ResetMediaID()
return nil
case blacklist.FieldCreateTime:
m.ResetCreateTime()
return nil return nil
case blacklist.FieldNotes: case blacklist.FieldNotes:
m.ResetNotes() m.ResetNotes()

View File

@@ -21,10 +21,10 @@ import (
func init() { func init() {
blacklistFields := schema.Blacklist{}.Fields() blacklistFields := schema.Blacklist{}.Fields()
_ = blacklistFields _ = blacklistFields
// blacklistDescValue is the schema descriptor for value field. // blacklistDescCreateTime is the schema descriptor for create_time field.
blacklistDescValue := blacklistFields[1].Descriptor() blacklistDescCreateTime := blacklistFields[4].Descriptor()
// blacklist.DefaultValue holds the default value on creation for the value field. // blacklist.DefaultCreateTime holds the default value on creation for the create_time field.
blacklist.DefaultValue = blacklistDescValue.Default.(schema.BlacklistValue) blacklist.DefaultCreateTime = blacklistDescCreateTime.Default.(func() time.Time)
downloadclientsFields := schema.DownloadClients{}.Fields() downloadclientsFields := schema.DownloadClients{}.Fields()
_ = downloadclientsFields _ = downloadclientsFields
// downloadclientsDescUser is the schema descriptor for user field. // downloadclientsDescUser is the schema descriptor for user field.

View File

@@ -1,6 +1,8 @@
package schema package schema
import ( import (
"time"
"entgo.io/ent" "entgo.io/ent"
"entgo.io/ent/schema/field" "entgo.io/ent/schema/field"
) )
@@ -13,8 +15,11 @@ type Blacklist struct {
// Fields of the Blacklist. // Fields of the Blacklist.
func (Blacklist) Fields() []ent.Field { func (Blacklist) Fields() []ent.Field {
return []ent.Field{ return []ent.Field{
field.Enum("type").Values("media", "torrent"), field.Enum("type").Values("media", "torrent").Default("torrent"),
field.JSON("value", BlacklistValue{}).Default(BlacklistValue{}), field.String("torrent_hash").Optional(),
field.String("torrent_name").Optional(),
field.Int("media_id").Optional(),
field.Time("create_time").Optional().Default(time.Now).Immutable(),
field.String("notes").Optional(), field.String("notes").Optional(),
} }
} }
@@ -23,8 +28,3 @@ func (Blacklist) Fields() []ent.Field {
func (Blacklist) Edges() []ent.Edge { func (Blacklist) Edges() []ent.Edge {
return nil return nil
} }
type BlacklistValue struct {
TmdbID int `json:"tmdb_id"`
TorrentHash string `json:"torrent_hash"`
}

View File

@@ -25,7 +25,7 @@ func (History) Fields() []ent.Field {
field.Int("size").Default(0), field.Int("size").Default(0),
field.Int("download_client_id").Optional(), field.Int("download_client_id").Optional(),
field.Int("indexer_id").Optional(), field.Int("indexer_id").Optional(),
field.String("link").Optional().Comment("deprecated, use hash instead"), //should be magnet link field.String("link").Optional().Comment("torrent link"), //should be magnet link
field.String("hash").Optional().Comment("torrent hash"), field.String("hash").Optional().Comment("torrent hash"),
field.Enum("status").Values("running", "success", "fail", "uploading", "seeding", "removed"), field.Enum("status").Values("running", "success", "fail", "uploading", "seeding", "removed"),
field.Time("create_time").Optional().Default(time.Now).Immutable(), field.Time("create_time").Optional().Default(time.Now).Immutable(),

View File

@@ -7,7 +7,6 @@ import (
"polaris/ent/episode" "polaris/ent/episode"
"polaris/ent/history" "polaris/ent/history"
"polaris/log" "polaris/log"
"polaris/pkg/utils"
"strconv" "strconv"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
@@ -89,7 +88,7 @@ func (s *Server) RemoveActivity(c *gin.Context) (interface{}, error) {
} }
if in.Add2Blacklist && his.Link != "" { if in.Add2Blacklist && his.Link != "" {
//should add to blacklist //should add to blacklist
if err := s.addTorrent2Blacklist(his.Link); err != nil { if err := s.addTorrent2Blacklist(his); err != nil {
return nil, errors.Errorf("add to blacklist: %v", err) return nil, errors.Errorf("add to blacklist: %v", err)
} else { } else {
log.Infof("success add magnet link to blacklist: %v", his.Link) log.Infof("success add magnet link to blacklist: %v", his.Link)
@@ -118,25 +117,23 @@ func (s *Server) RemoveActivity(c *gin.Context) (interface{}, error) {
return nil, nil return nil, nil
} }
func (s *Server) addTorrent2Blacklist(link string) error { func (s *Server) addTorrent2Blacklist(h *ent.History) error {
if link == "" { var name string
return nil
task, ok := s.core.GetTask(h.ID)
if ok {
name, _ = task.Name()
} }
if _, err := utils.MagnetHash(link); err != nil {
return err return s.db.AddTorrent2Blacklist(h.Hash, name, h.MediaID)
} else { }
// item := ent.Blacklist{
// Type: blacklist.TypeTorrent, func (s *Server) GetAllBlacklistItems(c *gin.Context) (interface{}, error) {
// Value: schema.BlacklistValue{ list, err := s.db.GetTorrentBlacklist()
// TorrentHash: hash, if err!= nil {
// }, return nil, errors.Wrap(err, "db")
// }
// err := s.db.AddBlacklistItem(&item)
// if err != nil {
// return errors.Wrap(err, "add to db")
// }
} }
return nil return list, nil
} }
func (s *Server) GetMediaDownloadHistory(c *gin.Context) (interface{}, error) { func (s *Server) GetMediaDownloadHistory(c *gin.Context) (interface{}, error) {

View File

@@ -86,6 +86,7 @@ func (s *Server) Serve() error {
activity.GET("/", HttpHandler(s.GetAllActivities)) activity.GET("/", HttpHandler(s.GetAllActivities))
activity.POST("/delete", HttpHandler(s.RemoveActivity)) activity.POST("/delete", HttpHandler(s.RemoveActivity))
activity.GET("/media/:id", HttpHandler(s.GetMediaDownloadHistory)) activity.GET("/media/:id", HttpHandler(s.GetMediaDownloadHistory))
activity.GET("/blacklist", HttpHandler(s.GetAllBlacklistItems))
//activity.GET("/torrents", HttpHandler(s.GetAllTorrents)) //activity.GET("/torrents", HttpHandler(s.GetAllTorrents))
} }