mirror of
https://github.com/simon-ding/polaris.git
synced 2026-02-06 23:21:00 +08:00
feat: better jav search support
This commit is contained in:
15
ent/media.go
15
ent/media.go
@@ -47,6 +47,8 @@ type Media struct {
|
||||
DownloadHistoryEpisodes bool `json:"download_history_episodes,omitempty"`
|
||||
// Limiter holds the value of the "limiter" field.
|
||||
Limiter schema.MediaLimiter `json:"limiter,omitempty"`
|
||||
// Extras holds the value of the "extras" field.
|
||||
Extras schema.MediaExtras `json:"extras,omitempty"`
|
||||
// Edges holds the relations/edges for other nodes in the graph.
|
||||
// The values are being populated by the MediaQuery when eager-loading is set.
|
||||
Edges MediaEdges `json:"edges"`
|
||||
@@ -76,7 +78,7 @@ func (*Media) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case media.FieldLimiter:
|
||||
case media.FieldLimiter, media.FieldExtras:
|
||||
values[i] = new([]byte)
|
||||
case media.FieldDownloadHistoryEpisodes:
|
||||
values[i] = new(sql.NullBool)
|
||||
@@ -193,6 +195,14 @@ func (m *Media) assignValues(columns []string, values []any) error {
|
||||
return fmt.Errorf("unmarshal field limiter: %w", err)
|
||||
}
|
||||
}
|
||||
case media.FieldExtras:
|
||||
if value, ok := values[i].(*[]byte); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field extras", values[i])
|
||||
} else if value != nil && len(*value) > 0 {
|
||||
if err := json.Unmarshal(*value, &m.Extras); err != nil {
|
||||
return fmt.Errorf("unmarshal field extras: %w", err)
|
||||
}
|
||||
}
|
||||
default:
|
||||
m.selectValues.Set(columns[i], values[i])
|
||||
}
|
||||
@@ -275,6 +285,9 @@ func (m *Media) String() string {
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("limiter=")
|
||||
builder.WriteString(fmt.Sprintf("%v", m.Limiter))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("extras=")
|
||||
builder.WriteString(fmt.Sprintf("%v", m.Extras))
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
@@ -43,6 +43,8 @@ const (
|
||||
FieldDownloadHistoryEpisodes = "download_history_episodes"
|
||||
// FieldLimiter holds the string denoting the limiter field in the database.
|
||||
FieldLimiter = "limiter"
|
||||
// FieldExtras holds the string denoting the extras field in the database.
|
||||
FieldExtras = "extras"
|
||||
// EdgeEpisodes holds the string denoting the episodes edge name in mutations.
|
||||
EdgeEpisodes = "episodes"
|
||||
// Table holds the table name of the media in the database.
|
||||
@@ -73,6 +75,7 @@ var Columns = []string{
|
||||
FieldTargetDir,
|
||||
FieldDownloadHistoryEpisodes,
|
||||
FieldLimiter,
|
||||
FieldExtras,
|
||||
}
|
||||
|
||||
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||
|
||||
@@ -785,6 +785,16 @@ func LimiterNotNil() predicate.Media {
|
||||
return predicate.Media(sql.FieldNotNull(FieldLimiter))
|
||||
}
|
||||
|
||||
// ExtrasIsNil applies the IsNil predicate on the "extras" field.
|
||||
func ExtrasIsNil() predicate.Media {
|
||||
return predicate.Media(sql.FieldIsNull(FieldExtras))
|
||||
}
|
||||
|
||||
// ExtrasNotNil applies the NotNil predicate on the "extras" field.
|
||||
func ExtrasNotNil() predicate.Media {
|
||||
return predicate.Media(sql.FieldNotNull(FieldExtras))
|
||||
}
|
||||
|
||||
// HasEpisodes applies the HasEdge predicate on the "episodes" edge.
|
||||
func HasEpisodes() predicate.Media {
|
||||
return predicate.Media(func(s *sql.Selector) {
|
||||
|
||||
@@ -170,6 +170,20 @@ func (mc *MediaCreate) SetNillableLimiter(sl *schema.MediaLimiter) *MediaCreate
|
||||
return mc
|
||||
}
|
||||
|
||||
// SetExtras sets the "extras" field.
|
||||
func (mc *MediaCreate) SetExtras(se schema.MediaExtras) *MediaCreate {
|
||||
mc.mutation.SetExtras(se)
|
||||
return mc
|
||||
}
|
||||
|
||||
// SetNillableExtras sets the "extras" field if the given value is not nil.
|
||||
func (mc *MediaCreate) SetNillableExtras(se *schema.MediaExtras) *MediaCreate {
|
||||
if se != nil {
|
||||
mc.SetExtras(*se)
|
||||
}
|
||||
return mc
|
||||
}
|
||||
|
||||
// AddEpisodeIDs adds the "episodes" edge to the Episode entity by IDs.
|
||||
func (mc *MediaCreate) AddEpisodeIDs(ids ...int) *MediaCreate {
|
||||
mc.mutation.AddEpisodeIDs(ids...)
|
||||
@@ -359,6 +373,10 @@ func (mc *MediaCreate) createSpec() (*Media, *sqlgraph.CreateSpec) {
|
||||
_spec.SetField(media.FieldLimiter, field.TypeJSON, value)
|
||||
_node.Limiter = value
|
||||
}
|
||||
if value, ok := mc.mutation.Extras(); ok {
|
||||
_spec.SetField(media.FieldExtras, field.TypeJSON, value)
|
||||
_node.Extras = value
|
||||
}
|
||||
if nodes := mc.mutation.EpisodesIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
|
||||
@@ -270,6 +270,26 @@ func (mu *MediaUpdate) ClearLimiter() *MediaUpdate {
|
||||
return mu
|
||||
}
|
||||
|
||||
// SetExtras sets the "extras" field.
|
||||
func (mu *MediaUpdate) SetExtras(se schema.MediaExtras) *MediaUpdate {
|
||||
mu.mutation.SetExtras(se)
|
||||
return mu
|
||||
}
|
||||
|
||||
// SetNillableExtras sets the "extras" field if the given value is not nil.
|
||||
func (mu *MediaUpdate) SetNillableExtras(se *schema.MediaExtras) *MediaUpdate {
|
||||
if se != nil {
|
||||
mu.SetExtras(*se)
|
||||
}
|
||||
return mu
|
||||
}
|
||||
|
||||
// ClearExtras clears the value of the "extras" field.
|
||||
func (mu *MediaUpdate) ClearExtras() *MediaUpdate {
|
||||
mu.mutation.ClearExtras()
|
||||
return mu
|
||||
}
|
||||
|
||||
// AddEpisodeIDs adds the "episodes" edge to the Episode entity by IDs.
|
||||
func (mu *MediaUpdate) AddEpisodeIDs(ids ...int) *MediaUpdate {
|
||||
mu.mutation.AddEpisodeIDs(ids...)
|
||||
@@ -428,6 +448,12 @@ func (mu *MediaUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
if mu.mutation.LimiterCleared() {
|
||||
_spec.ClearField(media.FieldLimiter, field.TypeJSON)
|
||||
}
|
||||
if value, ok := mu.mutation.Extras(); ok {
|
||||
_spec.SetField(media.FieldExtras, field.TypeJSON, value)
|
||||
}
|
||||
if mu.mutation.ExtrasCleared() {
|
||||
_spec.ClearField(media.FieldExtras, field.TypeJSON)
|
||||
}
|
||||
if mu.mutation.EpisodesCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
@@ -733,6 +759,26 @@ func (muo *MediaUpdateOne) ClearLimiter() *MediaUpdateOne {
|
||||
return muo
|
||||
}
|
||||
|
||||
// SetExtras sets the "extras" field.
|
||||
func (muo *MediaUpdateOne) SetExtras(se schema.MediaExtras) *MediaUpdateOne {
|
||||
muo.mutation.SetExtras(se)
|
||||
return muo
|
||||
}
|
||||
|
||||
// SetNillableExtras sets the "extras" field if the given value is not nil.
|
||||
func (muo *MediaUpdateOne) SetNillableExtras(se *schema.MediaExtras) *MediaUpdateOne {
|
||||
if se != nil {
|
||||
muo.SetExtras(*se)
|
||||
}
|
||||
return muo
|
||||
}
|
||||
|
||||
// ClearExtras clears the value of the "extras" field.
|
||||
func (muo *MediaUpdateOne) ClearExtras() *MediaUpdateOne {
|
||||
muo.mutation.ClearExtras()
|
||||
return muo
|
||||
}
|
||||
|
||||
// AddEpisodeIDs adds the "episodes" edge to the Episode entity by IDs.
|
||||
func (muo *MediaUpdateOne) AddEpisodeIDs(ids ...int) *MediaUpdateOne {
|
||||
muo.mutation.AddEpisodeIDs(ids...)
|
||||
@@ -921,6 +967,12 @@ func (muo *MediaUpdateOne) sqlSave(ctx context.Context) (_node *Media, err error
|
||||
if muo.mutation.LimiterCleared() {
|
||||
_spec.ClearField(media.FieldLimiter, field.TypeJSON)
|
||||
}
|
||||
if value, ok := muo.mutation.Extras(); ok {
|
||||
_spec.SetField(media.FieldExtras, field.TypeJSON, value)
|
||||
}
|
||||
if muo.mutation.ExtrasCleared() {
|
||||
_spec.ClearField(media.FieldExtras, field.TypeJSON)
|
||||
}
|
||||
if muo.mutation.EpisodesCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
|
||||
@@ -110,6 +110,7 @@ var (
|
||||
{Name: "target_dir", Type: field.TypeString, Nullable: true},
|
||||
{Name: "download_history_episodes", Type: field.TypeBool, Nullable: true, Default: false},
|
||||
{Name: "limiter", Type: field.TypeJSON, Nullable: true},
|
||||
{Name: "extras", Type: field.TypeJSON, Nullable: true},
|
||||
}
|
||||
// MediaTable holds the schema information for the "media" table.
|
||||
MediaTable = &schema.Table{
|
||||
|
||||
@@ -3675,6 +3675,7 @@ type MediaMutation struct {
|
||||
target_dir *string
|
||||
download_history_episodes *bool
|
||||
limiter *schema.MediaLimiter
|
||||
extras *schema.MediaExtras
|
||||
clearedFields map[string]struct{}
|
||||
episodes map[int]struct{}
|
||||
removedepisodes map[int]struct{}
|
||||
@@ -4392,6 +4393,55 @@ func (m *MediaMutation) ResetLimiter() {
|
||||
delete(m.clearedFields, media.FieldLimiter)
|
||||
}
|
||||
|
||||
// SetExtras sets the "extras" field.
|
||||
func (m *MediaMutation) SetExtras(se schema.MediaExtras) {
|
||||
m.extras = &se
|
||||
}
|
||||
|
||||
// Extras returns the value of the "extras" field in the mutation.
|
||||
func (m *MediaMutation) Extras() (r schema.MediaExtras, exists bool) {
|
||||
v := m.extras
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// OldExtras returns the old "extras" field's value of the Media entity.
|
||||
// If the Media 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 *MediaMutation) OldExtras(ctx context.Context) (v schema.MediaExtras, err error) {
|
||||
if !m.op.Is(OpUpdateOne) {
|
||||
return v, errors.New("OldExtras is only allowed on UpdateOne operations")
|
||||
}
|
||||
if m.id == nil || m.oldValue == nil {
|
||||
return v, errors.New("OldExtras requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldExtras: %w", err)
|
||||
}
|
||||
return oldValue.Extras, nil
|
||||
}
|
||||
|
||||
// ClearExtras clears the value of the "extras" field.
|
||||
func (m *MediaMutation) ClearExtras() {
|
||||
m.extras = nil
|
||||
m.clearedFields[media.FieldExtras] = struct{}{}
|
||||
}
|
||||
|
||||
// ExtrasCleared returns if the "extras" field was cleared in this mutation.
|
||||
func (m *MediaMutation) ExtrasCleared() bool {
|
||||
_, ok := m.clearedFields[media.FieldExtras]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ResetExtras resets all changes to the "extras" field.
|
||||
func (m *MediaMutation) ResetExtras() {
|
||||
m.extras = nil
|
||||
delete(m.clearedFields, media.FieldExtras)
|
||||
}
|
||||
|
||||
// AddEpisodeIDs adds the "episodes" edge to the Episode entity by ids.
|
||||
func (m *MediaMutation) AddEpisodeIDs(ids ...int) {
|
||||
if m.episodes == nil {
|
||||
@@ -4480,7 +4530,7 @@ func (m *MediaMutation) Type() string {
|
||||
// order to get all numeric fields that were incremented/decremented, call
|
||||
// AddedFields().
|
||||
func (m *MediaMutation) Fields() []string {
|
||||
fields := make([]string, 0, 14)
|
||||
fields := make([]string, 0, 15)
|
||||
if m.tmdb_id != nil {
|
||||
fields = append(fields, media.FieldTmdbID)
|
||||
}
|
||||
@@ -4523,6 +4573,9 @@ func (m *MediaMutation) Fields() []string {
|
||||
if m.limiter != nil {
|
||||
fields = append(fields, media.FieldLimiter)
|
||||
}
|
||||
if m.extras != nil {
|
||||
fields = append(fields, media.FieldExtras)
|
||||
}
|
||||
return fields
|
||||
}
|
||||
|
||||
@@ -4559,6 +4612,8 @@ func (m *MediaMutation) Field(name string) (ent.Value, bool) {
|
||||
return m.DownloadHistoryEpisodes()
|
||||
case media.FieldLimiter:
|
||||
return m.Limiter()
|
||||
case media.FieldExtras:
|
||||
return m.Extras()
|
||||
}
|
||||
return nil, false
|
||||
}
|
||||
@@ -4596,6 +4651,8 @@ func (m *MediaMutation) OldField(ctx context.Context, name string) (ent.Value, e
|
||||
return m.OldDownloadHistoryEpisodes(ctx)
|
||||
case media.FieldLimiter:
|
||||
return m.OldLimiter(ctx)
|
||||
case media.FieldExtras:
|
||||
return m.OldExtras(ctx)
|
||||
}
|
||||
return nil, fmt.Errorf("unknown Media field %s", name)
|
||||
}
|
||||
@@ -4703,6 +4760,13 @@ func (m *MediaMutation) SetField(name string, value ent.Value) error {
|
||||
}
|
||||
m.SetLimiter(v)
|
||||
return nil
|
||||
case media.FieldExtras:
|
||||
v, ok := value.(schema.MediaExtras)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetExtras(v)
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Media field %s", name)
|
||||
}
|
||||
@@ -4775,6 +4839,9 @@ func (m *MediaMutation) ClearedFields() []string {
|
||||
if m.FieldCleared(media.FieldLimiter) {
|
||||
fields = append(fields, media.FieldLimiter)
|
||||
}
|
||||
if m.FieldCleared(media.FieldExtras) {
|
||||
fields = append(fields, media.FieldExtras)
|
||||
}
|
||||
return fields
|
||||
}
|
||||
|
||||
@@ -4804,6 +4871,9 @@ func (m *MediaMutation) ClearField(name string) error {
|
||||
case media.FieldLimiter:
|
||||
m.ClearLimiter()
|
||||
return nil
|
||||
case media.FieldExtras:
|
||||
m.ClearExtras()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Media nullable field %s", name)
|
||||
}
|
||||
@@ -4854,6 +4924,9 @@ func (m *MediaMutation) ResetField(name string) error {
|
||||
case media.FieldLimiter:
|
||||
m.ResetLimiter()
|
||||
return nil
|
||||
case media.FieldExtras:
|
||||
m.ResetExtras()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Media field %s", name)
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ func (Media) Fields() []ent.Field {
|
||||
field.String("target_dir").Optional(),
|
||||
field.Bool("download_history_episodes").Optional().Default(false).Comment("tv series only"),
|
||||
field.JSON("limiter", MediaLimiter{}).Optional(),
|
||||
field.JSON("extras", MediaExtras{}).Optional(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,3 +45,9 @@ type MediaLimiter struct {
|
||||
SizeMin int `json:"size_min"` //in B
|
||||
SizeMax int `json:"size_max"` //in B
|
||||
}
|
||||
|
||||
type MediaExtras struct {
|
||||
IsAdult bool `json:"is_adult"`
|
||||
IsJav bool `json:"is_jav"`
|
||||
JavId string `json:"javid"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user