mirror of
https://github.com/simon-ding/polaris.git
synced 2026-02-06 15:10:49 +08:00
feat: save torrent link to history
This commit is contained in:
@@ -33,6 +33,8 @@ type History struct {
|
||||
DownloadClientID int `json:"download_client_id,omitempty"`
|
||||
// IndexerID holds the value of the "indexer_id" field.
|
||||
IndexerID int `json:"indexer_id,omitempty"`
|
||||
// Link holds the value of the "link" field.
|
||||
Link string `json:"link,omitempty"`
|
||||
// Status holds the value of the "status" field.
|
||||
Status history.Status `json:"status,omitempty"`
|
||||
// Saved holds the value of the "saved" field.
|
||||
@@ -47,7 +49,7 @@ func (*History) scanValues(columns []string) ([]any, error) {
|
||||
switch columns[i] {
|
||||
case history.FieldID, history.FieldMediaID, history.FieldEpisodeID, history.FieldSize, history.FieldDownloadClientID, history.FieldIndexerID:
|
||||
values[i] = new(sql.NullInt64)
|
||||
case history.FieldSourceTitle, history.FieldTargetDir, history.FieldStatus, history.FieldSaved:
|
||||
case history.FieldSourceTitle, history.FieldTargetDir, history.FieldLink, history.FieldStatus, history.FieldSaved:
|
||||
values[i] = new(sql.NullString)
|
||||
case history.FieldDate:
|
||||
values[i] = new(sql.NullTime)
|
||||
@@ -120,6 +122,12 @@ func (h *History) assignValues(columns []string, values []any) error {
|
||||
} else if value.Valid {
|
||||
h.IndexerID = int(value.Int64)
|
||||
}
|
||||
case history.FieldLink:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field link", values[i])
|
||||
} else if value.Valid {
|
||||
h.Link = value.String
|
||||
}
|
||||
case history.FieldStatus:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field status", values[i])
|
||||
@@ -192,6 +200,9 @@ func (h *History) String() string {
|
||||
builder.WriteString("indexer_id=")
|
||||
builder.WriteString(fmt.Sprintf("%v", h.IndexerID))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("link=")
|
||||
builder.WriteString(h.Link)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("status=")
|
||||
builder.WriteString(fmt.Sprintf("%v", h.Status))
|
||||
builder.WriteString(", ")
|
||||
|
||||
@@ -29,6 +29,8 @@ const (
|
||||
FieldDownloadClientID = "download_client_id"
|
||||
// FieldIndexerID holds the string denoting the indexer_id field in the database.
|
||||
FieldIndexerID = "indexer_id"
|
||||
// FieldLink holds the string denoting the link field in the database.
|
||||
FieldLink = "link"
|
||||
// FieldStatus holds the string denoting the status field in the database.
|
||||
FieldStatus = "status"
|
||||
// FieldSaved holds the string denoting the saved field in the database.
|
||||
@@ -48,6 +50,7 @@ var Columns = []string{
|
||||
FieldSize,
|
||||
FieldDownloadClientID,
|
||||
FieldIndexerID,
|
||||
FieldLink,
|
||||
FieldStatus,
|
||||
FieldSaved,
|
||||
}
|
||||
@@ -141,6 +144,11 @@ func ByIndexerID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldIndexerID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByLink orders the results by the link field.
|
||||
func ByLink(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldLink, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByStatus orders the results by the status field.
|
||||
func ByStatus(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldStatus, opts...).ToFunc()
|
||||
|
||||
@@ -94,6 +94,11 @@ func IndexerID(v int) predicate.History {
|
||||
return predicate.History(sql.FieldEQ(FieldIndexerID, v))
|
||||
}
|
||||
|
||||
// Link applies equality check predicate on the "link" field. It's identical to LinkEQ.
|
||||
func Link(v string) predicate.History {
|
||||
return predicate.History(sql.FieldEQ(FieldLink, v))
|
||||
}
|
||||
|
||||
// Saved applies equality check predicate on the "saved" field. It's identical to SavedEQ.
|
||||
func Saved(v string) predicate.History {
|
||||
return predicate.History(sql.FieldEQ(FieldSaved, v))
|
||||
@@ -499,6 +504,81 @@ func IndexerIDNotNil() predicate.History {
|
||||
return predicate.History(sql.FieldNotNull(FieldIndexerID))
|
||||
}
|
||||
|
||||
// LinkEQ applies the EQ predicate on the "link" field.
|
||||
func LinkEQ(v string) predicate.History {
|
||||
return predicate.History(sql.FieldEQ(FieldLink, v))
|
||||
}
|
||||
|
||||
// LinkNEQ applies the NEQ predicate on the "link" field.
|
||||
func LinkNEQ(v string) predicate.History {
|
||||
return predicate.History(sql.FieldNEQ(FieldLink, v))
|
||||
}
|
||||
|
||||
// LinkIn applies the In predicate on the "link" field.
|
||||
func LinkIn(vs ...string) predicate.History {
|
||||
return predicate.History(sql.FieldIn(FieldLink, vs...))
|
||||
}
|
||||
|
||||
// LinkNotIn applies the NotIn predicate on the "link" field.
|
||||
func LinkNotIn(vs ...string) predicate.History {
|
||||
return predicate.History(sql.FieldNotIn(FieldLink, vs...))
|
||||
}
|
||||
|
||||
// LinkGT applies the GT predicate on the "link" field.
|
||||
func LinkGT(v string) predicate.History {
|
||||
return predicate.History(sql.FieldGT(FieldLink, v))
|
||||
}
|
||||
|
||||
// LinkGTE applies the GTE predicate on the "link" field.
|
||||
func LinkGTE(v string) predicate.History {
|
||||
return predicate.History(sql.FieldGTE(FieldLink, v))
|
||||
}
|
||||
|
||||
// LinkLT applies the LT predicate on the "link" field.
|
||||
func LinkLT(v string) predicate.History {
|
||||
return predicate.History(sql.FieldLT(FieldLink, v))
|
||||
}
|
||||
|
||||
// LinkLTE applies the LTE predicate on the "link" field.
|
||||
func LinkLTE(v string) predicate.History {
|
||||
return predicate.History(sql.FieldLTE(FieldLink, v))
|
||||
}
|
||||
|
||||
// LinkContains applies the Contains predicate on the "link" field.
|
||||
func LinkContains(v string) predicate.History {
|
||||
return predicate.History(sql.FieldContains(FieldLink, v))
|
||||
}
|
||||
|
||||
// LinkHasPrefix applies the HasPrefix predicate on the "link" field.
|
||||
func LinkHasPrefix(v string) predicate.History {
|
||||
return predicate.History(sql.FieldHasPrefix(FieldLink, v))
|
||||
}
|
||||
|
||||
// LinkHasSuffix applies the HasSuffix predicate on the "link" field.
|
||||
func LinkHasSuffix(v string) predicate.History {
|
||||
return predicate.History(sql.FieldHasSuffix(FieldLink, v))
|
||||
}
|
||||
|
||||
// LinkIsNil applies the IsNil predicate on the "link" field.
|
||||
func LinkIsNil() predicate.History {
|
||||
return predicate.History(sql.FieldIsNull(FieldLink))
|
||||
}
|
||||
|
||||
// LinkNotNil applies the NotNil predicate on the "link" field.
|
||||
func LinkNotNil() predicate.History {
|
||||
return predicate.History(sql.FieldNotNull(FieldLink))
|
||||
}
|
||||
|
||||
// LinkEqualFold applies the EqualFold predicate on the "link" field.
|
||||
func LinkEqualFold(v string) predicate.History {
|
||||
return predicate.History(sql.FieldEqualFold(FieldLink, v))
|
||||
}
|
||||
|
||||
// LinkContainsFold applies the ContainsFold predicate on the "link" field.
|
||||
func LinkContainsFold(v string) predicate.History {
|
||||
return predicate.History(sql.FieldContainsFold(FieldLink, v))
|
||||
}
|
||||
|
||||
// StatusEQ applies the EQ predicate on the "status" field.
|
||||
func StatusEQ(v Status) predicate.History {
|
||||
return predicate.History(sql.FieldEQ(FieldStatus, v))
|
||||
|
||||
@@ -100,6 +100,20 @@ func (hc *HistoryCreate) SetNillableIndexerID(i *int) *HistoryCreate {
|
||||
return hc
|
||||
}
|
||||
|
||||
// SetLink sets the "link" field.
|
||||
func (hc *HistoryCreate) SetLink(s string) *HistoryCreate {
|
||||
hc.mutation.SetLink(s)
|
||||
return hc
|
||||
}
|
||||
|
||||
// SetNillableLink sets the "link" field if the given value is not nil.
|
||||
func (hc *HistoryCreate) SetNillableLink(s *string) *HistoryCreate {
|
||||
if s != nil {
|
||||
hc.SetLink(*s)
|
||||
}
|
||||
return hc
|
||||
}
|
||||
|
||||
// SetStatus sets the "status" field.
|
||||
func (hc *HistoryCreate) SetStatus(h history.Status) *HistoryCreate {
|
||||
hc.mutation.SetStatus(h)
|
||||
@@ -244,6 +258,10 @@ func (hc *HistoryCreate) createSpec() (*History, *sqlgraph.CreateSpec) {
|
||||
_spec.SetField(history.FieldIndexerID, field.TypeInt, value)
|
||||
_node.IndexerID = value
|
||||
}
|
||||
if value, ok := hc.mutation.Link(); ok {
|
||||
_spec.SetField(history.FieldLink, field.TypeString, value)
|
||||
_node.Link = value
|
||||
}
|
||||
if value, ok := hc.mutation.Status(); ok {
|
||||
_spec.SetField(history.FieldStatus, field.TypeEnum, value)
|
||||
_node.Status = value
|
||||
|
||||
@@ -193,6 +193,26 @@ func (hu *HistoryUpdate) ClearIndexerID() *HistoryUpdate {
|
||||
return hu
|
||||
}
|
||||
|
||||
// SetLink sets the "link" field.
|
||||
func (hu *HistoryUpdate) SetLink(s string) *HistoryUpdate {
|
||||
hu.mutation.SetLink(s)
|
||||
return hu
|
||||
}
|
||||
|
||||
// SetNillableLink sets the "link" field if the given value is not nil.
|
||||
func (hu *HistoryUpdate) SetNillableLink(s *string) *HistoryUpdate {
|
||||
if s != nil {
|
||||
hu.SetLink(*s)
|
||||
}
|
||||
return hu
|
||||
}
|
||||
|
||||
// ClearLink clears the value of the "link" field.
|
||||
func (hu *HistoryUpdate) ClearLink() *HistoryUpdate {
|
||||
hu.mutation.ClearLink()
|
||||
return hu
|
||||
}
|
||||
|
||||
// SetStatus sets the "status" field.
|
||||
func (hu *HistoryUpdate) SetStatus(h history.Status) *HistoryUpdate {
|
||||
hu.mutation.SetStatus(h)
|
||||
@@ -329,6 +349,12 @@ func (hu *HistoryUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
if hu.mutation.IndexerIDCleared() {
|
||||
_spec.ClearField(history.FieldIndexerID, field.TypeInt)
|
||||
}
|
||||
if value, ok := hu.mutation.Link(); ok {
|
||||
_spec.SetField(history.FieldLink, field.TypeString, value)
|
||||
}
|
||||
if hu.mutation.LinkCleared() {
|
||||
_spec.ClearField(history.FieldLink, field.TypeString)
|
||||
}
|
||||
if value, ok := hu.mutation.Status(); ok {
|
||||
_spec.SetField(history.FieldStatus, field.TypeEnum, value)
|
||||
}
|
||||
@@ -523,6 +549,26 @@ func (huo *HistoryUpdateOne) ClearIndexerID() *HistoryUpdateOne {
|
||||
return huo
|
||||
}
|
||||
|
||||
// SetLink sets the "link" field.
|
||||
func (huo *HistoryUpdateOne) SetLink(s string) *HistoryUpdateOne {
|
||||
huo.mutation.SetLink(s)
|
||||
return huo
|
||||
}
|
||||
|
||||
// SetNillableLink sets the "link" field if the given value is not nil.
|
||||
func (huo *HistoryUpdateOne) SetNillableLink(s *string) *HistoryUpdateOne {
|
||||
if s != nil {
|
||||
huo.SetLink(*s)
|
||||
}
|
||||
return huo
|
||||
}
|
||||
|
||||
// ClearLink clears the value of the "link" field.
|
||||
func (huo *HistoryUpdateOne) ClearLink() *HistoryUpdateOne {
|
||||
huo.mutation.ClearLink()
|
||||
return huo
|
||||
}
|
||||
|
||||
// SetStatus sets the "status" field.
|
||||
func (huo *HistoryUpdateOne) SetStatus(h history.Status) *HistoryUpdateOne {
|
||||
huo.mutation.SetStatus(h)
|
||||
@@ -689,6 +735,12 @@ func (huo *HistoryUpdateOne) sqlSave(ctx context.Context) (_node *History, err e
|
||||
if huo.mutation.IndexerIDCleared() {
|
||||
_spec.ClearField(history.FieldIndexerID, field.TypeInt)
|
||||
}
|
||||
if value, ok := huo.mutation.Link(); ok {
|
||||
_spec.SetField(history.FieldLink, field.TypeString, value)
|
||||
}
|
||||
if huo.mutation.LinkCleared() {
|
||||
_spec.ClearField(history.FieldLink, field.TypeString)
|
||||
}
|
||||
if value, ok := huo.mutation.Status(); ok {
|
||||
_spec.SetField(history.FieldStatus, field.TypeEnum, value)
|
||||
}
|
||||
|
||||
@@ -79,6 +79,7 @@ var (
|
||||
{Name: "size", Type: field.TypeInt, Default: 0},
|
||||
{Name: "download_client_id", Type: field.TypeInt, Nullable: true},
|
||||
{Name: "indexer_id", Type: field.TypeInt, Nullable: true},
|
||||
{Name: "link", Type: field.TypeString, Nullable: true},
|
||||
{Name: "status", Type: field.TypeEnum, Enums: []string{"running", "success", "fail", "uploading", "seeding"}},
|
||||
{Name: "saved", Type: field.TypeString, Nullable: true},
|
||||
}
|
||||
|
||||
@@ -2269,6 +2269,7 @@ type HistoryMutation struct {
|
||||
adddownload_client_id *int
|
||||
indexer_id *int
|
||||
addindexer_id *int
|
||||
link *string
|
||||
status *history.Status
|
||||
saved *string
|
||||
clearedFields map[string]struct{}
|
||||
@@ -2805,6 +2806,55 @@ func (m *HistoryMutation) ResetIndexerID() {
|
||||
delete(m.clearedFields, history.FieldIndexerID)
|
||||
}
|
||||
|
||||
// SetLink sets the "link" field.
|
||||
func (m *HistoryMutation) SetLink(s string) {
|
||||
m.link = &s
|
||||
}
|
||||
|
||||
// Link returns the value of the "link" field in the mutation.
|
||||
func (m *HistoryMutation) Link() (r string, exists bool) {
|
||||
v := m.link
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// OldLink returns the old "link" field's value of the History entity.
|
||||
// If the History 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 *HistoryMutation) OldLink(ctx context.Context) (v string, err error) {
|
||||
if !m.op.Is(OpUpdateOne) {
|
||||
return v, errors.New("OldLink is only allowed on UpdateOne operations")
|
||||
}
|
||||
if m.id == nil || m.oldValue == nil {
|
||||
return v, errors.New("OldLink requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldLink: %w", err)
|
||||
}
|
||||
return oldValue.Link, nil
|
||||
}
|
||||
|
||||
// ClearLink clears the value of the "link" field.
|
||||
func (m *HistoryMutation) ClearLink() {
|
||||
m.link = nil
|
||||
m.clearedFields[history.FieldLink] = struct{}{}
|
||||
}
|
||||
|
||||
// LinkCleared returns if the "link" field was cleared in this mutation.
|
||||
func (m *HistoryMutation) LinkCleared() bool {
|
||||
_, ok := m.clearedFields[history.FieldLink]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ResetLink resets all changes to the "link" field.
|
||||
func (m *HistoryMutation) ResetLink() {
|
||||
m.link = nil
|
||||
delete(m.clearedFields, history.FieldLink)
|
||||
}
|
||||
|
||||
// SetStatus sets the "status" field.
|
||||
func (m *HistoryMutation) SetStatus(h history.Status) {
|
||||
m.status = &h
|
||||
@@ -2924,7 +2974,7 @@ func (m *HistoryMutation) Type() string {
|
||||
// order to get all numeric fields that were incremented/decremented, call
|
||||
// AddedFields().
|
||||
func (m *HistoryMutation) Fields() []string {
|
||||
fields := make([]string, 0, 10)
|
||||
fields := make([]string, 0, 11)
|
||||
if m.media_id != nil {
|
||||
fields = append(fields, history.FieldMediaID)
|
||||
}
|
||||
@@ -2949,6 +2999,9 @@ func (m *HistoryMutation) Fields() []string {
|
||||
if m.indexer_id != nil {
|
||||
fields = append(fields, history.FieldIndexerID)
|
||||
}
|
||||
if m.link != nil {
|
||||
fields = append(fields, history.FieldLink)
|
||||
}
|
||||
if m.status != nil {
|
||||
fields = append(fields, history.FieldStatus)
|
||||
}
|
||||
@@ -2979,6 +3032,8 @@ func (m *HistoryMutation) Field(name string) (ent.Value, bool) {
|
||||
return m.DownloadClientID()
|
||||
case history.FieldIndexerID:
|
||||
return m.IndexerID()
|
||||
case history.FieldLink:
|
||||
return m.Link()
|
||||
case history.FieldStatus:
|
||||
return m.Status()
|
||||
case history.FieldSaved:
|
||||
@@ -3008,6 +3063,8 @@ func (m *HistoryMutation) OldField(ctx context.Context, name string) (ent.Value,
|
||||
return m.OldDownloadClientID(ctx)
|
||||
case history.FieldIndexerID:
|
||||
return m.OldIndexerID(ctx)
|
||||
case history.FieldLink:
|
||||
return m.OldLink(ctx)
|
||||
case history.FieldStatus:
|
||||
return m.OldStatus(ctx)
|
||||
case history.FieldSaved:
|
||||
@@ -3077,6 +3134,13 @@ func (m *HistoryMutation) SetField(name string, value ent.Value) error {
|
||||
}
|
||||
m.SetIndexerID(v)
|
||||
return nil
|
||||
case history.FieldLink:
|
||||
v, ok := value.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetLink(v)
|
||||
return nil
|
||||
case history.FieldStatus:
|
||||
v, ok := value.(history.Status)
|
||||
if !ok {
|
||||
@@ -3193,6 +3257,9 @@ func (m *HistoryMutation) ClearedFields() []string {
|
||||
if m.FieldCleared(history.FieldIndexerID) {
|
||||
fields = append(fields, history.FieldIndexerID)
|
||||
}
|
||||
if m.FieldCleared(history.FieldLink) {
|
||||
fields = append(fields, history.FieldLink)
|
||||
}
|
||||
if m.FieldCleared(history.FieldSaved) {
|
||||
fields = append(fields, history.FieldSaved)
|
||||
}
|
||||
@@ -3219,6 +3286,9 @@ func (m *HistoryMutation) ClearField(name string) error {
|
||||
case history.FieldIndexerID:
|
||||
m.ClearIndexerID()
|
||||
return nil
|
||||
case history.FieldLink:
|
||||
m.ClearLink()
|
||||
return nil
|
||||
case history.FieldSaved:
|
||||
m.ClearSaved()
|
||||
return nil
|
||||
@@ -3254,6 +3324,9 @@ func (m *HistoryMutation) ResetField(name string) error {
|
||||
case history.FieldIndexerID:
|
||||
m.ResetIndexerID()
|
||||
return nil
|
||||
case history.FieldLink:
|
||||
m.ResetLink()
|
||||
return nil
|
||||
case history.FieldStatus:
|
||||
m.ResetStatus()
|
||||
return nil
|
||||
|
||||
@@ -21,6 +21,7 @@ func (History) Fields() []ent.Field {
|
||||
field.Int("size").Default(0),
|
||||
field.Int("download_client_id").Optional(),
|
||||
field.Int("indexer_id").Optional(),
|
||||
field.String("link").Optional(),
|
||||
field.Enum("status").Values("running", "success", "fail", "uploading", "seeding"),
|
||||
field.String("saved").Optional(),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user