feat: deprecate history episodeID and fix related code

This commit is contained in:
Simon Ding
2025-02-02 12:49:59 +08:00
parent 1d9eddf050
commit 88492b3922
13 changed files with 38 additions and 605 deletions

View File

@@ -20,8 +20,6 @@ type History struct {
ID int `json:"id,omitempty"`
// MediaID holds the value of the "media_id" field.
MediaID int `json:"media_id,omitempty"`
// deprecated
EpisodeID int `json:"episode_id,omitempty"`
// EpisodeNums holds the value of the "episode_nums" field.
EpisodeNums []int `json:"episode_nums,omitempty"`
// SeasonNum holds the value of the "season_num" field.
@@ -43,9 +41,7 @@ type History struct {
// torrent hash
Hash string `json:"hash,omitempty"`
// Status holds the value of the "status" field.
Status history.Status `json:"status,omitempty"`
// deprecated
Saved string `json:"saved,omitempty"`
Status history.Status `json:"status,omitempty"`
selectValues sql.SelectValues
}
@@ -56,9 +52,9 @@ func (*History) scanValues(columns []string) ([]any, error) {
switch columns[i] {
case history.FieldEpisodeNums:
values[i] = new([]byte)
case history.FieldID, history.FieldMediaID, history.FieldEpisodeID, history.FieldSeasonNum, history.FieldSize, history.FieldDownloadClientID, history.FieldIndexerID:
case history.FieldID, history.FieldMediaID, history.FieldSeasonNum, history.FieldSize, history.FieldDownloadClientID, history.FieldIndexerID:
values[i] = new(sql.NullInt64)
case history.FieldSourceTitle, history.FieldTargetDir, history.FieldLink, history.FieldHash, history.FieldStatus, history.FieldSaved:
case history.FieldSourceTitle, history.FieldTargetDir, history.FieldLink, history.FieldHash, history.FieldStatus:
values[i] = new(sql.NullString)
case history.FieldDate:
values[i] = new(sql.NullTime)
@@ -89,12 +85,6 @@ func (h *History) assignValues(columns []string, values []any) error {
} else if value.Valid {
h.MediaID = int(value.Int64)
}
case history.FieldEpisodeID:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field episode_id", values[i])
} else if value.Valid {
h.EpisodeID = int(value.Int64)
}
case history.FieldEpisodeNums:
if value, ok := values[i].(*[]byte); !ok {
return fmt.Errorf("unexpected type %T for field episode_nums", values[i])
@@ -163,12 +153,6 @@ func (h *History) assignValues(columns []string, values []any) error {
} else if value.Valid {
h.Status = history.Status(value.String)
}
case history.FieldSaved:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field saved", values[i])
} else if value.Valid {
h.Saved = value.String
}
default:
h.selectValues.Set(columns[i], values[i])
}
@@ -208,9 +192,6 @@ func (h *History) String() string {
builder.WriteString("media_id=")
builder.WriteString(fmt.Sprintf("%v", h.MediaID))
builder.WriteString(", ")
builder.WriteString("episode_id=")
builder.WriteString(fmt.Sprintf("%v", h.EpisodeID))
builder.WriteString(", ")
builder.WriteString("episode_nums=")
builder.WriteString(fmt.Sprintf("%v", h.EpisodeNums))
builder.WriteString(", ")
@@ -243,9 +224,6 @@ func (h *History) String() string {
builder.WriteString(", ")
builder.WriteString("status=")
builder.WriteString(fmt.Sprintf("%v", h.Status))
builder.WriteString(", ")
builder.WriteString("saved=")
builder.WriteString(h.Saved)
builder.WriteByte(')')
return builder.String()
}

View File

@@ -15,8 +15,6 @@ const (
FieldID = "id"
// FieldMediaID holds the string denoting the media_id field in the database.
FieldMediaID = "media_id"
// FieldEpisodeID holds the string denoting the episode_id field in the database.
FieldEpisodeID = "episode_id"
// FieldEpisodeNums holds the string denoting the episode_nums field in the database.
FieldEpisodeNums = "episode_nums"
// FieldSeasonNum holds the string denoting the season_num field in the database.
@@ -39,8 +37,6 @@ const (
FieldHash = "hash"
// FieldStatus holds the string denoting the status field in the database.
FieldStatus = "status"
// FieldSaved holds the string denoting the saved field in the database.
FieldSaved = "saved"
// Table holds the table name of the history in the database.
Table = "histories"
)
@@ -49,7 +45,6 @@ const (
var Columns = []string{
FieldID,
FieldMediaID,
FieldEpisodeID,
FieldEpisodeNums,
FieldSeasonNum,
FieldSourceTitle,
@@ -61,7 +56,6 @@ var Columns = []string{
FieldLink,
FieldHash,
FieldStatus,
FieldSaved,
}
// ValidColumn reports if the column name is valid (part of the table columns).
@@ -118,11 +112,6 @@ func ByMediaID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldMediaID, opts...).ToFunc()
}
// ByEpisodeID orders the results by the episode_id field.
func ByEpisodeID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldEpisodeID, opts...).ToFunc()
}
// BySeasonNum orders the results by the season_num field.
func BySeasonNum(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldSeasonNum, opts...).ToFunc()
@@ -172,8 +161,3 @@ func ByHash(opts ...sql.OrderTermOption) OrderOption {
func ByStatus(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldStatus, opts...).ToFunc()
}
// BySaved orders the results by the saved field.
func BySaved(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldSaved, opts...).ToFunc()
}

View File

@@ -59,11 +59,6 @@ func MediaID(v int) predicate.History {
return predicate.History(sql.FieldEQ(FieldMediaID, v))
}
// EpisodeID applies equality check predicate on the "episode_id" field. It's identical to EpisodeIDEQ.
func EpisodeID(v int) predicate.History {
return predicate.History(sql.FieldEQ(FieldEpisodeID, v))
}
// SeasonNum applies equality check predicate on the "season_num" field. It's identical to SeasonNumEQ.
func SeasonNum(v int) predicate.History {
return predicate.History(sql.FieldEQ(FieldSeasonNum, v))
@@ -109,11 +104,6 @@ func Hash(v string) predicate.History {
return predicate.History(sql.FieldEQ(FieldHash, 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))
}
// MediaIDEQ applies the EQ predicate on the "media_id" field.
func MediaIDEQ(v int) predicate.History {
return predicate.History(sql.FieldEQ(FieldMediaID, v))
@@ -154,56 +144,6 @@ func MediaIDLTE(v int) predicate.History {
return predicate.History(sql.FieldLTE(FieldMediaID, v))
}
// EpisodeIDEQ applies the EQ predicate on the "episode_id" field.
func EpisodeIDEQ(v int) predicate.History {
return predicate.History(sql.FieldEQ(FieldEpisodeID, v))
}
// EpisodeIDNEQ applies the NEQ predicate on the "episode_id" field.
func EpisodeIDNEQ(v int) predicate.History {
return predicate.History(sql.FieldNEQ(FieldEpisodeID, v))
}
// EpisodeIDIn applies the In predicate on the "episode_id" field.
func EpisodeIDIn(vs ...int) predicate.History {
return predicate.History(sql.FieldIn(FieldEpisodeID, vs...))
}
// EpisodeIDNotIn applies the NotIn predicate on the "episode_id" field.
func EpisodeIDNotIn(vs ...int) predicate.History {
return predicate.History(sql.FieldNotIn(FieldEpisodeID, vs...))
}
// EpisodeIDGT applies the GT predicate on the "episode_id" field.
func EpisodeIDGT(v int) predicate.History {
return predicate.History(sql.FieldGT(FieldEpisodeID, v))
}
// EpisodeIDGTE applies the GTE predicate on the "episode_id" field.
func EpisodeIDGTE(v int) predicate.History {
return predicate.History(sql.FieldGTE(FieldEpisodeID, v))
}
// EpisodeIDLT applies the LT predicate on the "episode_id" field.
func EpisodeIDLT(v int) predicate.History {
return predicate.History(sql.FieldLT(FieldEpisodeID, v))
}
// EpisodeIDLTE applies the LTE predicate on the "episode_id" field.
func EpisodeIDLTE(v int) predicate.History {
return predicate.History(sql.FieldLTE(FieldEpisodeID, v))
}
// EpisodeIDIsNil applies the IsNil predicate on the "episode_id" field.
func EpisodeIDIsNil() predicate.History {
return predicate.History(sql.FieldIsNull(FieldEpisodeID))
}
// EpisodeIDNotNil applies the NotNil predicate on the "episode_id" field.
func EpisodeIDNotNil() predicate.History {
return predicate.History(sql.FieldNotNull(FieldEpisodeID))
}
// EpisodeNumsIsNil applies the IsNil predicate on the "episode_nums" field.
func EpisodeNumsIsNil() predicate.History {
return predicate.History(sql.FieldIsNull(FieldEpisodeNums))
@@ -744,81 +684,6 @@ func StatusNotIn(vs ...Status) predicate.History {
return predicate.History(sql.FieldNotIn(FieldStatus, vs...))
}
// SavedEQ applies the EQ predicate on the "saved" field.
func SavedEQ(v string) predicate.History {
return predicate.History(sql.FieldEQ(FieldSaved, v))
}
// SavedNEQ applies the NEQ predicate on the "saved" field.
func SavedNEQ(v string) predicate.History {
return predicate.History(sql.FieldNEQ(FieldSaved, v))
}
// SavedIn applies the In predicate on the "saved" field.
func SavedIn(vs ...string) predicate.History {
return predicate.History(sql.FieldIn(FieldSaved, vs...))
}
// SavedNotIn applies the NotIn predicate on the "saved" field.
func SavedNotIn(vs ...string) predicate.History {
return predicate.History(sql.FieldNotIn(FieldSaved, vs...))
}
// SavedGT applies the GT predicate on the "saved" field.
func SavedGT(v string) predicate.History {
return predicate.History(sql.FieldGT(FieldSaved, v))
}
// SavedGTE applies the GTE predicate on the "saved" field.
func SavedGTE(v string) predicate.History {
return predicate.History(sql.FieldGTE(FieldSaved, v))
}
// SavedLT applies the LT predicate on the "saved" field.
func SavedLT(v string) predicate.History {
return predicate.History(sql.FieldLT(FieldSaved, v))
}
// SavedLTE applies the LTE predicate on the "saved" field.
func SavedLTE(v string) predicate.History {
return predicate.History(sql.FieldLTE(FieldSaved, v))
}
// SavedContains applies the Contains predicate on the "saved" field.
func SavedContains(v string) predicate.History {
return predicate.History(sql.FieldContains(FieldSaved, v))
}
// SavedHasPrefix applies the HasPrefix predicate on the "saved" field.
func SavedHasPrefix(v string) predicate.History {
return predicate.History(sql.FieldHasPrefix(FieldSaved, v))
}
// SavedHasSuffix applies the HasSuffix predicate on the "saved" field.
func SavedHasSuffix(v string) predicate.History {
return predicate.History(sql.FieldHasSuffix(FieldSaved, v))
}
// SavedIsNil applies the IsNil predicate on the "saved" field.
func SavedIsNil() predicate.History {
return predicate.History(sql.FieldIsNull(FieldSaved))
}
// SavedNotNil applies the NotNil predicate on the "saved" field.
func SavedNotNil() predicate.History {
return predicate.History(sql.FieldNotNull(FieldSaved))
}
// SavedEqualFold applies the EqualFold predicate on the "saved" field.
func SavedEqualFold(v string) predicate.History {
return predicate.History(sql.FieldEqualFold(FieldSaved, v))
}
// SavedContainsFold applies the ContainsFold predicate on the "saved" field.
func SavedContainsFold(v string) predicate.History {
return predicate.History(sql.FieldContainsFold(FieldSaved, v))
}
// And groups predicates with the AND operator between them.
func And(predicates ...predicate.History) predicate.History {
return predicate.History(sql.AndPredicates(predicates...))

View File

@@ -26,20 +26,6 @@ func (hc *HistoryCreate) SetMediaID(i int) *HistoryCreate {
return hc
}
// SetEpisodeID sets the "episode_id" field.
func (hc *HistoryCreate) SetEpisodeID(i int) *HistoryCreate {
hc.mutation.SetEpisodeID(i)
return hc
}
// SetNillableEpisodeID sets the "episode_id" field if the given value is not nil.
func (hc *HistoryCreate) SetNillableEpisodeID(i *int) *HistoryCreate {
if i != nil {
hc.SetEpisodeID(*i)
}
return hc
}
// SetEpisodeNums sets the "episode_nums" field.
func (hc *HistoryCreate) SetEpisodeNums(i []int) *HistoryCreate {
hc.mutation.SetEpisodeNums(i)
@@ -154,20 +140,6 @@ func (hc *HistoryCreate) SetStatus(h history.Status) *HistoryCreate {
return hc
}
// SetSaved sets the "saved" field.
func (hc *HistoryCreate) SetSaved(s string) *HistoryCreate {
hc.mutation.SetSaved(s)
return hc
}
// SetNillableSaved sets the "saved" field if the given value is not nil.
func (hc *HistoryCreate) SetNillableSaved(s *string) *HistoryCreate {
if s != nil {
hc.SetSaved(*s)
}
return hc
}
// Mutation returns the HistoryMutation object of the builder.
func (hc *HistoryCreate) Mutation() *HistoryMutation {
return hc.mutation
@@ -264,10 +236,6 @@ func (hc *HistoryCreate) createSpec() (*History, *sqlgraph.CreateSpec) {
_spec.SetField(history.FieldMediaID, field.TypeInt, value)
_node.MediaID = value
}
if value, ok := hc.mutation.EpisodeID(); ok {
_spec.SetField(history.FieldEpisodeID, field.TypeInt, value)
_node.EpisodeID = value
}
if value, ok := hc.mutation.EpisodeNums(); ok {
_spec.SetField(history.FieldEpisodeNums, field.TypeJSON, value)
_node.EpisodeNums = value
@@ -312,10 +280,6 @@ func (hc *HistoryCreate) createSpec() (*History, *sqlgraph.CreateSpec) {
_spec.SetField(history.FieldStatus, field.TypeEnum, value)
_node.Status = value
}
if value, ok := hc.mutation.Saved(); ok {
_spec.SetField(history.FieldSaved, field.TypeString, value)
_node.Saved = value
}
return _node, _spec
}

View File

@@ -50,33 +50,6 @@ func (hu *HistoryUpdate) AddMediaID(i int) *HistoryUpdate {
return hu
}
// SetEpisodeID sets the "episode_id" field.
func (hu *HistoryUpdate) SetEpisodeID(i int) *HistoryUpdate {
hu.mutation.ResetEpisodeID()
hu.mutation.SetEpisodeID(i)
return hu
}
// SetNillableEpisodeID sets the "episode_id" field if the given value is not nil.
func (hu *HistoryUpdate) SetNillableEpisodeID(i *int) *HistoryUpdate {
if i != nil {
hu.SetEpisodeID(*i)
}
return hu
}
// AddEpisodeID adds i to the "episode_id" field.
func (hu *HistoryUpdate) AddEpisodeID(i int) *HistoryUpdate {
hu.mutation.AddEpisodeID(i)
return hu
}
// ClearEpisodeID clears the value of the "episode_id" field.
func (hu *HistoryUpdate) ClearEpisodeID() *HistoryUpdate {
hu.mutation.ClearEpisodeID()
return hu
}
// SetEpisodeNums sets the "episode_nums" field.
func (hu *HistoryUpdate) SetEpisodeNums(i []int) *HistoryUpdate {
hu.mutation.SetEpisodeNums(i)
@@ -293,26 +266,6 @@ func (hu *HistoryUpdate) SetNillableStatus(h *history.Status) *HistoryUpdate {
return hu
}
// SetSaved sets the "saved" field.
func (hu *HistoryUpdate) SetSaved(s string) *HistoryUpdate {
hu.mutation.SetSaved(s)
return hu
}
// SetNillableSaved sets the "saved" field if the given value is not nil.
func (hu *HistoryUpdate) SetNillableSaved(s *string) *HistoryUpdate {
if s != nil {
hu.SetSaved(*s)
}
return hu
}
// ClearSaved clears the value of the "saved" field.
func (hu *HistoryUpdate) ClearSaved() *HistoryUpdate {
hu.mutation.ClearSaved()
return hu
}
// Mutation returns the HistoryMutation object of the builder.
func (hu *HistoryUpdate) Mutation() *HistoryMutation {
return hu.mutation
@@ -373,15 +326,6 @@ func (hu *HistoryUpdate) sqlSave(ctx context.Context) (n int, err error) {
if value, ok := hu.mutation.AddedMediaID(); ok {
_spec.AddField(history.FieldMediaID, field.TypeInt, value)
}
if value, ok := hu.mutation.EpisodeID(); ok {
_spec.SetField(history.FieldEpisodeID, field.TypeInt, value)
}
if value, ok := hu.mutation.AddedEpisodeID(); ok {
_spec.AddField(history.FieldEpisodeID, field.TypeInt, value)
}
if hu.mutation.EpisodeIDCleared() {
_spec.ClearField(history.FieldEpisodeID, field.TypeInt)
}
if value, ok := hu.mutation.EpisodeNums(); ok {
_spec.SetField(history.FieldEpisodeNums, field.TypeJSON, value)
}
@@ -450,12 +394,6 @@ func (hu *HistoryUpdate) sqlSave(ctx context.Context) (n int, err error) {
if value, ok := hu.mutation.Status(); ok {
_spec.SetField(history.FieldStatus, field.TypeEnum, value)
}
if value, ok := hu.mutation.Saved(); ok {
_spec.SetField(history.FieldSaved, field.TypeString, value)
}
if hu.mutation.SavedCleared() {
_spec.ClearField(history.FieldSaved, field.TypeString)
}
if n, err = sqlgraph.UpdateNodes(ctx, hu.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{history.Label}
@@ -497,33 +435,6 @@ func (huo *HistoryUpdateOne) AddMediaID(i int) *HistoryUpdateOne {
return huo
}
// SetEpisodeID sets the "episode_id" field.
func (huo *HistoryUpdateOne) SetEpisodeID(i int) *HistoryUpdateOne {
huo.mutation.ResetEpisodeID()
huo.mutation.SetEpisodeID(i)
return huo
}
// SetNillableEpisodeID sets the "episode_id" field if the given value is not nil.
func (huo *HistoryUpdateOne) SetNillableEpisodeID(i *int) *HistoryUpdateOne {
if i != nil {
huo.SetEpisodeID(*i)
}
return huo
}
// AddEpisodeID adds i to the "episode_id" field.
func (huo *HistoryUpdateOne) AddEpisodeID(i int) *HistoryUpdateOne {
huo.mutation.AddEpisodeID(i)
return huo
}
// ClearEpisodeID clears the value of the "episode_id" field.
func (huo *HistoryUpdateOne) ClearEpisodeID() *HistoryUpdateOne {
huo.mutation.ClearEpisodeID()
return huo
}
// SetEpisodeNums sets the "episode_nums" field.
func (huo *HistoryUpdateOne) SetEpisodeNums(i []int) *HistoryUpdateOne {
huo.mutation.SetEpisodeNums(i)
@@ -740,26 +651,6 @@ func (huo *HistoryUpdateOne) SetNillableStatus(h *history.Status) *HistoryUpdate
return huo
}
// SetSaved sets the "saved" field.
func (huo *HistoryUpdateOne) SetSaved(s string) *HistoryUpdateOne {
huo.mutation.SetSaved(s)
return huo
}
// SetNillableSaved sets the "saved" field if the given value is not nil.
func (huo *HistoryUpdateOne) SetNillableSaved(s *string) *HistoryUpdateOne {
if s != nil {
huo.SetSaved(*s)
}
return huo
}
// ClearSaved clears the value of the "saved" field.
func (huo *HistoryUpdateOne) ClearSaved() *HistoryUpdateOne {
huo.mutation.ClearSaved()
return huo
}
// Mutation returns the HistoryMutation object of the builder.
func (huo *HistoryUpdateOne) Mutation() *HistoryMutation {
return huo.mutation
@@ -850,15 +741,6 @@ func (huo *HistoryUpdateOne) sqlSave(ctx context.Context) (_node *History, err e
if value, ok := huo.mutation.AddedMediaID(); ok {
_spec.AddField(history.FieldMediaID, field.TypeInt, value)
}
if value, ok := huo.mutation.EpisodeID(); ok {
_spec.SetField(history.FieldEpisodeID, field.TypeInt, value)
}
if value, ok := huo.mutation.AddedEpisodeID(); ok {
_spec.AddField(history.FieldEpisodeID, field.TypeInt, value)
}
if huo.mutation.EpisodeIDCleared() {
_spec.ClearField(history.FieldEpisodeID, field.TypeInt)
}
if value, ok := huo.mutation.EpisodeNums(); ok {
_spec.SetField(history.FieldEpisodeNums, field.TypeJSON, value)
}
@@ -927,12 +809,6 @@ func (huo *HistoryUpdateOne) sqlSave(ctx context.Context) (_node *History, err e
if value, ok := huo.mutation.Status(); ok {
_spec.SetField(history.FieldStatus, field.TypeEnum, value)
}
if value, ok := huo.mutation.Saved(); ok {
_spec.SetField(history.FieldSaved, field.TypeString, value)
}
if huo.mutation.SavedCleared() {
_spec.ClearField(history.FieldSaved, field.TypeString)
}
_node = &History{config: huo.config}
_spec.Assign = _node.assignValues
_spec.ScanValues = _node.scanValues

View File

@@ -73,7 +73,6 @@ var (
HistoriesColumns = []*schema.Column{
{Name: "id", Type: field.TypeInt, Increment: true},
{Name: "media_id", Type: field.TypeInt},
{Name: "episode_id", Type: field.TypeInt, Nullable: true},
{Name: "episode_nums", Type: field.TypeJSON, Nullable: true},
{Name: "season_num", Type: field.TypeInt, Nullable: true},
{Name: "source_title", Type: field.TypeString},
@@ -85,7 +84,6 @@ var (
{Name: "link", Type: field.TypeString, Nullable: true},
{Name: "hash", Type: field.TypeString, Nullable: true},
{Name: "status", Type: field.TypeEnum, Enums: []string{"running", "success", "fail", "uploading", "seeding"}},
{Name: "saved", Type: field.TypeString, Nullable: true},
}
// HistoriesTable holds the schema information for the "histories" table.
HistoriesTable = &schema.Table{

View File

@@ -2334,8 +2334,6 @@ type HistoryMutation struct {
id *int
media_id *int
addmedia_id *int
episode_id *int
addepisode_id *int
episode_nums *[]int
appendepisode_nums []int
season_num *int
@@ -2352,7 +2350,6 @@ type HistoryMutation struct {
link *string
hash *string
status *history.Status
saved *string
clearedFields map[string]struct{}
done bool
oldValue func(context.Context) (*History, error)
@@ -2513,76 +2510,6 @@ func (m *HistoryMutation) ResetMediaID() {
m.addmedia_id = nil
}
// SetEpisodeID sets the "episode_id" field.
func (m *HistoryMutation) SetEpisodeID(i int) {
m.episode_id = &i
m.addepisode_id = nil
}
// EpisodeID returns the value of the "episode_id" field in the mutation.
func (m *HistoryMutation) EpisodeID() (r int, exists bool) {
v := m.episode_id
if v == nil {
return
}
return *v, true
}
// OldEpisodeID returns the old "episode_id" 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) OldEpisodeID(ctx context.Context) (v int, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldEpisodeID is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldEpisodeID requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldEpisodeID: %w", err)
}
return oldValue.EpisodeID, nil
}
// AddEpisodeID adds i to the "episode_id" field.
func (m *HistoryMutation) AddEpisodeID(i int) {
if m.addepisode_id != nil {
*m.addepisode_id += i
} else {
m.addepisode_id = &i
}
}
// AddedEpisodeID returns the value that was added to the "episode_id" field in this mutation.
func (m *HistoryMutation) AddedEpisodeID() (r int, exists bool) {
v := m.addepisode_id
if v == nil {
return
}
return *v, true
}
// ClearEpisodeID clears the value of the "episode_id" field.
func (m *HistoryMutation) ClearEpisodeID() {
m.episode_id = nil
m.addepisode_id = nil
m.clearedFields[history.FieldEpisodeID] = struct{}{}
}
// EpisodeIDCleared returns if the "episode_id" field was cleared in this mutation.
func (m *HistoryMutation) EpisodeIDCleared() bool {
_, ok := m.clearedFields[history.FieldEpisodeID]
return ok
}
// ResetEpisodeID resets all changes to the "episode_id" field.
func (m *HistoryMutation) ResetEpisodeID() {
m.episode_id = nil
m.addepisode_id = nil
delete(m.clearedFields, history.FieldEpisodeID)
}
// SetEpisodeNums sets the "episode_nums" field.
func (m *HistoryMutation) SetEpisodeNums(i []int) {
m.episode_nums = &i
@@ -3156,55 +3083,6 @@ func (m *HistoryMutation) ResetStatus() {
m.status = nil
}
// SetSaved sets the "saved" field.
func (m *HistoryMutation) SetSaved(s string) {
m.saved = &s
}
// Saved returns the value of the "saved" field in the mutation.
func (m *HistoryMutation) Saved() (r string, exists bool) {
v := m.saved
if v == nil {
return
}
return *v, true
}
// OldSaved returns the old "saved" 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) OldSaved(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldSaved is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldSaved requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldSaved: %w", err)
}
return oldValue.Saved, nil
}
// ClearSaved clears the value of the "saved" field.
func (m *HistoryMutation) ClearSaved() {
m.saved = nil
m.clearedFields[history.FieldSaved] = struct{}{}
}
// SavedCleared returns if the "saved" field was cleared in this mutation.
func (m *HistoryMutation) SavedCleared() bool {
_, ok := m.clearedFields[history.FieldSaved]
return ok
}
// ResetSaved resets all changes to the "saved" field.
func (m *HistoryMutation) ResetSaved() {
m.saved = nil
delete(m.clearedFields, history.FieldSaved)
}
// Where appends a list predicates to the HistoryMutation builder.
func (m *HistoryMutation) Where(ps ...predicate.History) {
m.predicates = append(m.predicates, ps...)
@@ -3239,13 +3117,10 @@ 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, 14)
fields := make([]string, 0, 12)
if m.media_id != nil {
fields = append(fields, history.FieldMediaID)
}
if m.episode_id != nil {
fields = append(fields, history.FieldEpisodeID)
}
if m.episode_nums != nil {
fields = append(fields, history.FieldEpisodeNums)
}
@@ -3279,9 +3154,6 @@ func (m *HistoryMutation) Fields() []string {
if m.status != nil {
fields = append(fields, history.FieldStatus)
}
if m.saved != nil {
fields = append(fields, history.FieldSaved)
}
return fields
}
@@ -3292,8 +3164,6 @@ func (m *HistoryMutation) Field(name string) (ent.Value, bool) {
switch name {
case history.FieldMediaID:
return m.MediaID()
case history.FieldEpisodeID:
return m.EpisodeID()
case history.FieldEpisodeNums:
return m.EpisodeNums()
case history.FieldSeasonNum:
@@ -3316,8 +3186,6 @@ func (m *HistoryMutation) Field(name string) (ent.Value, bool) {
return m.Hash()
case history.FieldStatus:
return m.Status()
case history.FieldSaved:
return m.Saved()
}
return nil, false
}
@@ -3329,8 +3197,6 @@ func (m *HistoryMutation) OldField(ctx context.Context, name string) (ent.Value,
switch name {
case history.FieldMediaID:
return m.OldMediaID(ctx)
case history.FieldEpisodeID:
return m.OldEpisodeID(ctx)
case history.FieldEpisodeNums:
return m.OldEpisodeNums(ctx)
case history.FieldSeasonNum:
@@ -3353,8 +3219,6 @@ func (m *HistoryMutation) OldField(ctx context.Context, name string) (ent.Value,
return m.OldHash(ctx)
case history.FieldStatus:
return m.OldStatus(ctx)
case history.FieldSaved:
return m.OldSaved(ctx)
}
return nil, fmt.Errorf("unknown History field %s", name)
}
@@ -3371,13 +3235,6 @@ func (m *HistoryMutation) SetField(name string, value ent.Value) error {
}
m.SetMediaID(v)
return nil
case history.FieldEpisodeID:
v, ok := value.(int)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetEpisodeID(v)
return nil
case history.FieldEpisodeNums:
v, ok := value.([]int)
if !ok {
@@ -3455,13 +3312,6 @@ func (m *HistoryMutation) SetField(name string, value ent.Value) error {
}
m.SetStatus(v)
return nil
case history.FieldSaved:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetSaved(v)
return nil
}
return fmt.Errorf("unknown History field %s", name)
}
@@ -3473,9 +3323,6 @@ func (m *HistoryMutation) AddedFields() []string {
if m.addmedia_id != nil {
fields = append(fields, history.FieldMediaID)
}
if m.addepisode_id != nil {
fields = append(fields, history.FieldEpisodeID)
}
if m.addseason_num != nil {
fields = append(fields, history.FieldSeasonNum)
}
@@ -3498,8 +3345,6 @@ func (m *HistoryMutation) AddedField(name string) (ent.Value, bool) {
switch name {
case history.FieldMediaID:
return m.AddedMediaID()
case history.FieldEpisodeID:
return m.AddedEpisodeID()
case history.FieldSeasonNum:
return m.AddedSeasonNum()
case history.FieldSize:
@@ -3524,13 +3369,6 @@ func (m *HistoryMutation) AddField(name string, value ent.Value) error {
}
m.AddMediaID(v)
return nil
case history.FieldEpisodeID:
v, ok := value.(int)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddEpisodeID(v)
return nil
case history.FieldSeasonNum:
v, ok := value.(int)
if !ok {
@@ -3567,9 +3405,6 @@ func (m *HistoryMutation) AddField(name string, value ent.Value) error {
// mutation.
func (m *HistoryMutation) ClearedFields() []string {
var fields []string
if m.FieldCleared(history.FieldEpisodeID) {
fields = append(fields, history.FieldEpisodeID)
}
if m.FieldCleared(history.FieldEpisodeNums) {
fields = append(fields, history.FieldEpisodeNums)
}
@@ -3588,9 +3423,6 @@ func (m *HistoryMutation) ClearedFields() []string {
if m.FieldCleared(history.FieldHash) {
fields = append(fields, history.FieldHash)
}
if m.FieldCleared(history.FieldSaved) {
fields = append(fields, history.FieldSaved)
}
return fields
}
@@ -3605,9 +3437,6 @@ func (m *HistoryMutation) FieldCleared(name string) bool {
// error if the field is not defined in the schema.
func (m *HistoryMutation) ClearField(name string) error {
switch name {
case history.FieldEpisodeID:
m.ClearEpisodeID()
return nil
case history.FieldEpisodeNums:
m.ClearEpisodeNums()
return nil
@@ -3626,9 +3455,6 @@ func (m *HistoryMutation) ClearField(name string) error {
case history.FieldHash:
m.ClearHash()
return nil
case history.FieldSaved:
m.ClearSaved()
return nil
}
return fmt.Errorf("unknown History nullable field %s", name)
}
@@ -3640,9 +3466,6 @@ func (m *HistoryMutation) ResetField(name string) error {
case history.FieldMediaID:
m.ResetMediaID()
return nil
case history.FieldEpisodeID:
m.ResetEpisodeID()
return nil
case history.FieldEpisodeNums:
m.ResetEpisodeNums()
return nil
@@ -3676,9 +3499,6 @@ func (m *HistoryMutation) ResetField(name string) error {
case history.FieldStatus:
m.ResetStatus()
return nil
case history.FieldSaved:
m.ResetSaved()
return nil
}
return fmt.Errorf("unknown History field %s", name)
}

View File

@@ -66,7 +66,7 @@ func init() {
historyFields := schema.History{}.Fields()
_ = historyFields
// historyDescSize is the schema descriptor for size field.
historyDescSize := historyFields[7].Descriptor()
historyDescSize := historyFields[6].Descriptor()
// history.DefaultSize holds the default value on creation for the size field.
history.DefaultSize = historyDescSize.Default.(int)
indexersFields := schema.Indexers{}.Fields()

View File

@@ -14,7 +14,7 @@ type History struct {
func (History) Fields() []ent.Field {
return []ent.Field{
field.Int("media_id"),
field.Int("episode_id").Optional().Comment("deprecated"),
//field.Int("episode_id").Optional().Comment("deprecated"),
field.Ints("episode_nums").Optional(),
field.Int("season_num").Optional(),
field.String("source_title"),
@@ -26,7 +26,7 @@ func (History) Fields() []ent.Field {
field.String("link").Optional().Comment("deprecated, use hash instead"), //should be magnet link
field.String("hash").Optional().Comment("torrent hash"),
field.Enum("status").Values("running", "success", "fail", "uploading", "seeding"),
field.String("saved").Optional().Comment("deprecated"), //deprecated
//field.String("saved").Optional().Comment("deprecated"), //deprecated
}
}

View File

@@ -6,7 +6,7 @@ import (
)
func TestLink2Magnet(t *testing.T) {
s, err := Link2Magnet("")
s, err := Link2Hash("https://api.m-team.io/api/rss/dlv2?useHttps=true&type=ipv6&sign=1a5174668feea2630acfd6a665f41e5c&t=1738468436&tid=901313&uid=346577")
log.Errorf("%v", err)
log.Infof("%v", s)
}

View File

@@ -108,7 +108,7 @@ func (s *Server) RemoveActivity(c *gin.Context) (interface{}, error) {
ep, _ := s.db.GetEpisode(his.MediaID, his.SeasonNum, id)
if !s.db.IsEpisodeDownloadingOrDownloaded(id) && ep.Status != episode.StatusDownloaded {
//没有正在下载中或者下载完成的任务并且episode状态不是已经下载完成
s.db.SetEpisodeStatus(his.EpisodeID, episode.StatusMissing)
s.db.SetEpisodeStatus(id, episode.StatusMissing)
}
}

View File

@@ -4,7 +4,7 @@ import (
"bytes"
"encoding/xml"
"fmt"
"os"
"io/fs"
"path/filepath"
"polaris/db"
"polaris/ent/media"
@@ -14,7 +14,6 @@ import (
"polaris/pkg/metadata"
"polaris/pkg/notifier"
"polaris/pkg/storage"
"polaris/pkg/utils"
"slices"
"strconv"
"strings"
@@ -150,41 +149,22 @@ func (c *Client) writePlexmatch(historyId int) error {
} else {
buff.Write(data)
}
episodesIds := c.GetEpisodeIds(his)
if his.EpisodeID > 0 {
//single episode download
ep, err := c.db.GetEpisodeByID(his.EpisodeID)
for _, id := range episodesIds {
ep, err := c.db.GetEpisodeByID(id)
if err != nil {
return errors.Wrap(err, "query episode")
log.Warnf("query episode: %v", err)
continue
}
if strings.Contains(buff.String(), ep.TargetFile) {
log.Debugf("already write plex episode line: %v", ep.TargetFile)
return nil
}
buff.WriteString(fmt.Sprintf("\nep: %d: %s\n", ep.EpisodeNumber, ep.TargetFile))
} else {
seasonNum, err := utils.SeasonId(his.TargetDir)
if err != nil {
return errors.Wrap(err, "no season id")
}
allEpisodes, err := c.db.GetSeasonEpisodes(his.MediaID, seasonNum)
if err != nil {
return errors.Wrap(err, "query season episode")
}
for _, ep := range allEpisodes {
if ep.TargetFile == "" {
log.Errorf("no episode file of episode %d, season %d", ep.EpisodeNumber, ep.SeasonNumber)
//TODO update db
continue
}
if strings.Contains(buff.String(), ep.TargetFile) {
log.Debugf("already write plex episode line: %v", ep.TargetFile)
continue
}
buff.WriteString(fmt.Sprintf("\nep: %d: %s\n", ep.EpisodeNumber, ep.TargetFile))
}
}
log.Infof("write season plexmatch file content: %s", buff.String())
return st.WriteFile(seasonPlex, buff.Bytes())
}
@@ -212,7 +192,6 @@ func (c *Client) GetStorage(storageId int, mediaType media.MediaType) (storage.S
log.Warnf("get accepted subtitle format error: %v", err)
}
switch st.Implementation {
case storage1.ImplementationLocal:
@@ -272,64 +251,33 @@ func (c *Client) sendMsg(msg string) {
func (c *Client) findEpisodeFilesPreMoving(historyId int) error {
his := c.db.GetHistory(historyId)
isSingleEpisode := his.EpisodeID > 0
downloadDir := c.db.GetDownloadDir()
episodeIds := c.GetEpisodeIds(his)
task := c.tasks[historyId]
name, err := task.Name()
ff, err := c.db.GetAcceptedVideoFormats()
if err != nil {
return err
}
target := filepath.Join(downloadDir, name)
fi, err := os.Stat(target)
if err != nil {
return errors.Wrapf(err, "read dir %v", target)
}
if isSingleEpisode {
if fi.IsDir() {
//download single episode in dir
//TODO
} else {
//is file
if err := c.db.UpdateEpisodeTargetFile(his.EpisodeID, fi.Name()); err != nil {
log.Errorf("writing downloaded file name to db error: %v", err)
for _, id := range episodeIds {
ep, _ := c.db.GetEpisode(his.MediaID, his.SeasonNum, id)
task.WalkFunc()(func(path string, info fs.FileInfo) error {
if info.IsDir() {
return nil
}
}
} else {
if !fi.IsDir() {
return fmt.Errorf("not season pack downloaded")
}
seasonNum, err := utils.SeasonId(his.TargetDir)
if err != nil {
return errors.Wrap(err, "no season id")
}
files, err := os.ReadDir(target)
if err != nil {
return err
}
for _, f := range files {
if f.IsDir() { //want media file
continue
ext := filepath.Ext(info.Name())
if slices.Contains(ff, ext) {
return nil
}
excludedExt := []string{".txt", ".srt", ".ass", ".sub"}
ext := filepath.Ext(f.Name())
if slices.Contains(excludedExt, strings.ToLower(ext)) {
continue
}
meta := metadata.ParseTv(f.Name())
if meta.StartEpisode > 0 {
//episode exists
ep, err := c.db.GetEpisode(his.MediaID, seasonNum, meta.StartEpisode)
if err != nil {
return err
}
if err := c.db.UpdateEpisodeTargetFile(ep.ID, f.Name()); err != nil {
return errors.Wrap(err, "update episode file")
meta := metadata.ParseTv(info.Name())
if meta.StartEpisode == meta.EndEpisode && meta.StartEpisode == ep.EpisodeNumber {
if err := c.db.UpdateEpisodeTargetFile(id, info.Name()); err != nil {
log.Errorf("writing downloaded file name to db error: %v", err)
}
}
}
return nil
})
}
return nil
}

View File

@@ -203,9 +203,9 @@ func (c *Client) GetEpisodeIds(r *ent.History) []int {
var episodeIds []int
seasonNum := getSeasonNum(r)
if r.EpisodeID > 0 {
episodeIds = append(episodeIds, r.EpisodeID)
}
// if r.EpisodeID > 0 {
// episodeIds = append(episodeIds, r.EpisodeID)
// }
series := c.db.GetMediaDetails(r.MediaID)
if len(r.EpisodeNums) > 0 {