mirror of https://github.com/cloudreve/Cloudreve
parent
e31a6cbcb3
commit
80b25e88ee
2
assets
2
assets
|
@ -1 +1 @@
|
||||||
Subproject commit c4a6593921d34ec47d78d5288c2d1c0865d435b6
|
Subproject commit 09480ffa21d859a1d2f9bb2421e6f78f113494c4
|
|
@ -1034,8 +1034,7 @@ func (c *FileClient) Hooks() []Hook {
|
||||||
|
|
||||||
// Interceptors returns the client interceptors.
|
// Interceptors returns the client interceptors.
|
||||||
func (c *FileClient) Interceptors() []Interceptor {
|
func (c *FileClient) Interceptors() []Interceptor {
|
||||||
inters := c.inters.File
|
return c.inters.File
|
||||||
return append(inters[:len(inters):len(inters)], file.Interceptors[:]...)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *FileClient) mutate(ctx context.Context, m *FileMutation) (Value, error) {
|
func (c *FileClient) mutate(ctx context.Context, m *FileMutation) (Value, error) {
|
||||||
|
|
16
ent/file.go
16
ent/file.go
|
@ -25,8 +25,6 @@ type File struct {
|
||||||
CreatedAt time.Time `json:"created_at,omitempty"`
|
CreatedAt time.Time `json:"created_at,omitempty"`
|
||||||
// UpdatedAt holds the value of the "updated_at" field.
|
// UpdatedAt holds the value of the "updated_at" field.
|
||||||
UpdatedAt time.Time `json:"updated_at,omitempty"`
|
UpdatedAt time.Time `json:"updated_at,omitempty"`
|
||||||
// DeletedAt holds the value of the "deleted_at" field.
|
|
||||||
DeletedAt *time.Time `json:"deleted_at,omitempty"`
|
|
||||||
// Type holds the value of the "type" field.
|
// Type holds the value of the "type" field.
|
||||||
Type int `json:"type,omitempty"`
|
Type int `json:"type,omitempty"`
|
||||||
// Name holds the value of the "name" field.
|
// Name holds the value of the "name" field.
|
||||||
|
@ -171,7 +169,7 @@ func (*File) scanValues(columns []string) ([]any, error) {
|
||||||
values[i] = new(sql.NullInt64)
|
values[i] = new(sql.NullInt64)
|
||||||
case file.FieldName:
|
case file.FieldName:
|
||||||
values[i] = new(sql.NullString)
|
values[i] = new(sql.NullString)
|
||||||
case file.FieldCreatedAt, file.FieldUpdatedAt, file.FieldDeletedAt:
|
case file.FieldCreatedAt, file.FieldUpdatedAt:
|
||||||
values[i] = new(sql.NullTime)
|
values[i] = new(sql.NullTime)
|
||||||
default:
|
default:
|
||||||
values[i] = new(sql.UnknownType)
|
values[i] = new(sql.UnknownType)
|
||||||
|
@ -206,13 +204,6 @@ func (f *File) assignValues(columns []string, values []any) error {
|
||||||
} else if value.Valid {
|
} else if value.Valid {
|
||||||
f.UpdatedAt = value.Time
|
f.UpdatedAt = value.Time
|
||||||
}
|
}
|
||||||
case file.FieldDeletedAt:
|
|
||||||
if value, ok := values[i].(*sql.NullTime); !ok {
|
|
||||||
return fmt.Errorf("unexpected type %T for field deleted_at", values[i])
|
|
||||||
} else if value.Valid {
|
|
||||||
f.DeletedAt = new(time.Time)
|
|
||||||
*f.DeletedAt = value.Time
|
|
||||||
}
|
|
||||||
case file.FieldType:
|
case file.FieldType:
|
||||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||||
return fmt.Errorf("unexpected type %T for field type", values[i])
|
return fmt.Errorf("unexpected type %T for field type", values[i])
|
||||||
|
@ -351,11 +342,6 @@ func (f *File) String() string {
|
||||||
builder.WriteString("updated_at=")
|
builder.WriteString("updated_at=")
|
||||||
builder.WriteString(f.UpdatedAt.Format(time.ANSIC))
|
builder.WriteString(f.UpdatedAt.Format(time.ANSIC))
|
||||||
builder.WriteString(", ")
|
builder.WriteString(", ")
|
||||||
if v := f.DeletedAt; v != nil {
|
|
||||||
builder.WriteString("deleted_at=")
|
|
||||||
builder.WriteString(v.Format(time.ANSIC))
|
|
||||||
}
|
|
||||||
builder.WriteString(", ")
|
|
||||||
builder.WriteString("type=")
|
builder.WriteString("type=")
|
||||||
builder.WriteString(fmt.Sprintf("%v", f.Type))
|
builder.WriteString(fmt.Sprintf("%v", f.Type))
|
||||||
builder.WriteString(", ")
|
builder.WriteString(", ")
|
||||||
|
|
|
@ -19,8 +19,6 @@ const (
|
||||||
FieldCreatedAt = "created_at"
|
FieldCreatedAt = "created_at"
|
||||||
// FieldUpdatedAt holds the string denoting the updated_at field in the database.
|
// FieldUpdatedAt holds the string denoting the updated_at field in the database.
|
||||||
FieldUpdatedAt = "updated_at"
|
FieldUpdatedAt = "updated_at"
|
||||||
// FieldDeletedAt holds the string denoting the deleted_at field in the database.
|
|
||||||
FieldDeletedAt = "deleted_at"
|
|
||||||
// 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"
|
||||||
// FieldName holds the string denoting the name field in the database.
|
// FieldName holds the string denoting the name field in the database.
|
||||||
|
@ -112,7 +110,6 @@ var Columns = []string{
|
||||||
FieldID,
|
FieldID,
|
||||||
FieldCreatedAt,
|
FieldCreatedAt,
|
||||||
FieldUpdatedAt,
|
FieldUpdatedAt,
|
||||||
FieldDeletedAt,
|
|
||||||
FieldType,
|
FieldType,
|
||||||
FieldName,
|
FieldName,
|
||||||
FieldOwnerID,
|
FieldOwnerID,
|
||||||
|
@ -146,14 +143,11 @@ func ValidColumn(column string) bool {
|
||||||
//
|
//
|
||||||
// import _ "github.com/cloudreve/Cloudreve/v4/ent/runtime"
|
// import _ "github.com/cloudreve/Cloudreve/v4/ent/runtime"
|
||||||
var (
|
var (
|
||||||
Hooks [1]ent.Hook
|
Hooks [1]ent.Hook
|
||||||
Interceptors [1]ent.Interceptor
|
|
||||||
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
|
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
|
||||||
DefaultCreatedAt func() time.Time
|
DefaultCreatedAt func() time.Time
|
||||||
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
|
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
|
||||||
DefaultUpdatedAt func() time.Time
|
DefaultUpdatedAt func() time.Time
|
||||||
// UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field.
|
|
||||||
UpdateDefaultUpdatedAt func() time.Time
|
|
||||||
// DefaultSize holds the default value on creation for the "size" field.
|
// DefaultSize holds the default value on creation for the "size" field.
|
||||||
DefaultSize int64
|
DefaultSize int64
|
||||||
// DefaultIsSymbolic holds the default value on creation for the "is_symbolic" field.
|
// DefaultIsSymbolic holds the default value on creation for the "is_symbolic" field.
|
||||||
|
@ -178,11 +172,6 @@ func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||||
return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc()
|
return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc()
|
||||||
}
|
}
|
||||||
|
|
||||||
// ByDeletedAt orders the results by the deleted_at field.
|
|
||||||
func ByDeletedAt(opts ...sql.OrderTermOption) OrderOption {
|
|
||||||
return sql.OrderByField(FieldDeletedAt, opts...).ToFunc()
|
|
||||||
}
|
|
||||||
|
|
||||||
// ByType orders the results by the type field.
|
// ByType orders the results by the type field.
|
||||||
func ByType(opts ...sql.OrderTermOption) OrderOption {
|
func ByType(opts ...sql.OrderTermOption) OrderOption {
|
||||||
return sql.OrderByField(FieldType, opts...).ToFunc()
|
return sql.OrderByField(FieldType, opts...).ToFunc()
|
||||||
|
|
|
@ -65,11 +65,6 @@ func UpdatedAt(v time.Time) predicate.File {
|
||||||
return predicate.File(sql.FieldEQ(FieldUpdatedAt, v))
|
return predicate.File(sql.FieldEQ(FieldUpdatedAt, v))
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeletedAt applies equality check predicate on the "deleted_at" field. It's identical to DeletedAtEQ.
|
|
||||||
func DeletedAt(v time.Time) predicate.File {
|
|
||||||
return predicate.File(sql.FieldEQ(FieldDeletedAt, v))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Type applies equality check predicate on the "type" field. It's identical to TypeEQ.
|
// Type applies equality check predicate on the "type" field. It's identical to TypeEQ.
|
||||||
func Type(v int) predicate.File {
|
func Type(v int) predicate.File {
|
||||||
return predicate.File(sql.FieldEQ(FieldType, v))
|
return predicate.File(sql.FieldEQ(FieldType, v))
|
||||||
|
@ -190,56 +185,6 @@ func UpdatedAtLTE(v time.Time) predicate.File {
|
||||||
return predicate.File(sql.FieldLTE(FieldUpdatedAt, v))
|
return predicate.File(sql.FieldLTE(FieldUpdatedAt, v))
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeletedAtEQ applies the EQ predicate on the "deleted_at" field.
|
|
||||||
func DeletedAtEQ(v time.Time) predicate.File {
|
|
||||||
return predicate.File(sql.FieldEQ(FieldDeletedAt, v))
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeletedAtNEQ applies the NEQ predicate on the "deleted_at" field.
|
|
||||||
func DeletedAtNEQ(v time.Time) predicate.File {
|
|
||||||
return predicate.File(sql.FieldNEQ(FieldDeletedAt, v))
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeletedAtIn applies the In predicate on the "deleted_at" field.
|
|
||||||
func DeletedAtIn(vs ...time.Time) predicate.File {
|
|
||||||
return predicate.File(sql.FieldIn(FieldDeletedAt, vs...))
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeletedAtNotIn applies the NotIn predicate on the "deleted_at" field.
|
|
||||||
func DeletedAtNotIn(vs ...time.Time) predicate.File {
|
|
||||||
return predicate.File(sql.FieldNotIn(FieldDeletedAt, vs...))
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeletedAtGT applies the GT predicate on the "deleted_at" field.
|
|
||||||
func DeletedAtGT(v time.Time) predicate.File {
|
|
||||||
return predicate.File(sql.FieldGT(FieldDeletedAt, v))
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeletedAtGTE applies the GTE predicate on the "deleted_at" field.
|
|
||||||
func DeletedAtGTE(v time.Time) predicate.File {
|
|
||||||
return predicate.File(sql.FieldGTE(FieldDeletedAt, v))
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeletedAtLT applies the LT predicate on the "deleted_at" field.
|
|
||||||
func DeletedAtLT(v time.Time) predicate.File {
|
|
||||||
return predicate.File(sql.FieldLT(FieldDeletedAt, v))
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeletedAtLTE applies the LTE predicate on the "deleted_at" field.
|
|
||||||
func DeletedAtLTE(v time.Time) predicate.File {
|
|
||||||
return predicate.File(sql.FieldLTE(FieldDeletedAt, v))
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeletedAtIsNil applies the IsNil predicate on the "deleted_at" field.
|
|
||||||
func DeletedAtIsNil() predicate.File {
|
|
||||||
return predicate.File(sql.FieldIsNull(FieldDeletedAt))
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeletedAtNotNil applies the NotNil predicate on the "deleted_at" field.
|
|
||||||
func DeletedAtNotNil() predicate.File {
|
|
||||||
return predicate.File(sql.FieldNotNull(FieldDeletedAt))
|
|
||||||
}
|
|
||||||
|
|
||||||
// TypeEQ applies the EQ predicate on the "type" field.
|
// TypeEQ applies the EQ predicate on the "type" field.
|
||||||
func TypeEQ(v int) predicate.File {
|
func TypeEQ(v int) predicate.File {
|
||||||
return predicate.File(sql.FieldEQ(FieldType, v))
|
return predicate.File(sql.FieldEQ(FieldType, v))
|
||||||
|
|
|
@ -57,20 +57,6 @@ func (fc *FileCreate) SetNillableUpdatedAt(t *time.Time) *FileCreate {
|
||||||
return fc
|
return fc
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetDeletedAt sets the "deleted_at" field.
|
|
||||||
func (fc *FileCreate) SetDeletedAt(t time.Time) *FileCreate {
|
|
||||||
fc.mutation.SetDeletedAt(t)
|
|
||||||
return fc
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
|
|
||||||
func (fc *FileCreate) SetNillableDeletedAt(t *time.Time) *FileCreate {
|
|
||||||
if t != nil {
|
|
||||||
fc.SetDeletedAt(*t)
|
|
||||||
}
|
|
||||||
return fc
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetType sets the "type" field.
|
// SetType sets the "type" field.
|
||||||
func (fc *FileCreate) SetType(i int) *FileCreate {
|
func (fc *FileCreate) SetType(i int) *FileCreate {
|
||||||
fc.mutation.SetType(i)
|
fc.mutation.SetType(i)
|
||||||
|
@ -413,10 +399,6 @@ func (fc *FileCreate) createSpec() (*File, *sqlgraph.CreateSpec) {
|
||||||
_spec.SetField(file.FieldUpdatedAt, field.TypeTime, value)
|
_spec.SetField(file.FieldUpdatedAt, field.TypeTime, value)
|
||||||
_node.UpdatedAt = value
|
_node.UpdatedAt = value
|
||||||
}
|
}
|
||||||
if value, ok := fc.mutation.DeletedAt(); ok {
|
|
||||||
_spec.SetField(file.FieldDeletedAt, field.TypeTime, value)
|
|
||||||
_node.DeletedAt = &value
|
|
||||||
}
|
|
||||||
if value, ok := fc.mutation.GetType(); ok {
|
if value, ok := fc.mutation.GetType(); ok {
|
||||||
_spec.SetField(file.FieldType, field.TypeInt, value)
|
_spec.SetField(file.FieldType, field.TypeInt, value)
|
||||||
_node.Type = value
|
_node.Type = value
|
||||||
|
@ -636,24 +618,6 @@ func (u *FileUpsert) UpdateUpdatedAt() *FileUpsert {
|
||||||
return u
|
return u
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetDeletedAt sets the "deleted_at" field.
|
|
||||||
func (u *FileUpsert) SetDeletedAt(v time.Time) *FileUpsert {
|
|
||||||
u.Set(file.FieldDeletedAt, v)
|
|
||||||
return u
|
|
||||||
}
|
|
||||||
|
|
||||||
// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
|
|
||||||
func (u *FileUpsert) UpdateDeletedAt() *FileUpsert {
|
|
||||||
u.SetExcluded(file.FieldDeletedAt)
|
|
||||||
return u
|
|
||||||
}
|
|
||||||
|
|
||||||
// ClearDeletedAt clears the value of the "deleted_at" field.
|
|
||||||
func (u *FileUpsert) ClearDeletedAt() *FileUpsert {
|
|
||||||
u.SetNull(file.FieldDeletedAt)
|
|
||||||
return u
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetType sets the "type" field.
|
// SetType sets the "type" field.
|
||||||
func (u *FileUpsert) SetType(v int) *FileUpsert {
|
func (u *FileUpsert) SetType(v int) *FileUpsert {
|
||||||
u.Set(file.FieldType, v)
|
u.Set(file.FieldType, v)
|
||||||
|
@ -863,27 +827,6 @@ func (u *FileUpsertOne) UpdateUpdatedAt() *FileUpsertOne {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetDeletedAt sets the "deleted_at" field.
|
|
||||||
func (u *FileUpsertOne) SetDeletedAt(v time.Time) *FileUpsertOne {
|
|
||||||
return u.Update(func(s *FileUpsert) {
|
|
||||||
s.SetDeletedAt(v)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
|
|
||||||
func (u *FileUpsertOne) UpdateDeletedAt() *FileUpsertOne {
|
|
||||||
return u.Update(func(s *FileUpsert) {
|
|
||||||
s.UpdateDeletedAt()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// ClearDeletedAt clears the value of the "deleted_at" field.
|
|
||||||
func (u *FileUpsertOne) ClearDeletedAt() *FileUpsertOne {
|
|
||||||
return u.Update(func(s *FileUpsert) {
|
|
||||||
s.ClearDeletedAt()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetType sets the "type" field.
|
// SetType sets the "type" field.
|
||||||
func (u *FileUpsertOne) SetType(v int) *FileUpsertOne {
|
func (u *FileUpsertOne) SetType(v int) *FileUpsertOne {
|
||||||
return u.Update(func(s *FileUpsert) {
|
return u.Update(func(s *FileUpsert) {
|
||||||
|
@ -1289,27 +1232,6 @@ func (u *FileUpsertBulk) UpdateUpdatedAt() *FileUpsertBulk {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetDeletedAt sets the "deleted_at" field.
|
|
||||||
func (u *FileUpsertBulk) SetDeletedAt(v time.Time) *FileUpsertBulk {
|
|
||||||
return u.Update(func(s *FileUpsert) {
|
|
||||||
s.SetDeletedAt(v)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
|
|
||||||
func (u *FileUpsertBulk) UpdateDeletedAt() *FileUpsertBulk {
|
|
||||||
return u.Update(func(s *FileUpsert) {
|
|
||||||
s.UpdateDeletedAt()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// ClearDeletedAt clears the value of the "deleted_at" field.
|
|
||||||
func (u *FileUpsertBulk) ClearDeletedAt() *FileUpsertBulk {
|
|
||||||
return u.Update(func(s *FileUpsert) {
|
|
||||||
s.ClearDeletedAt()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetType sets the "type" field.
|
// SetType sets the "type" field.
|
||||||
func (u *FileUpsertBulk) SetType(v int) *FileUpsertBulk {
|
func (u *FileUpsertBulk) SetType(v int) *FileUpsertBulk {
|
||||||
return u.Update(func(s *FileUpsert) {
|
return u.Update(func(s *FileUpsert) {
|
||||||
|
|
|
@ -41,26 +41,14 @@ func (fu *FileUpdate) SetUpdatedAt(t time.Time) *FileUpdate {
|
||||||
return fu
|
return fu
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetDeletedAt sets the "deleted_at" field.
|
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
||||||
func (fu *FileUpdate) SetDeletedAt(t time.Time) *FileUpdate {
|
func (fu *FileUpdate) SetNillableUpdatedAt(t *time.Time) *FileUpdate {
|
||||||
fu.mutation.SetDeletedAt(t)
|
|
||||||
return fu
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
|
|
||||||
func (fu *FileUpdate) SetNillableDeletedAt(t *time.Time) *FileUpdate {
|
|
||||||
if t != nil {
|
if t != nil {
|
||||||
fu.SetDeletedAt(*t)
|
fu.SetUpdatedAt(*t)
|
||||||
}
|
}
|
||||||
return fu
|
return fu
|
||||||
}
|
}
|
||||||
|
|
||||||
// ClearDeletedAt clears the value of the "deleted_at" field.
|
|
||||||
func (fu *FileUpdate) ClearDeletedAt() *FileUpdate {
|
|
||||||
fu.mutation.ClearDeletedAt()
|
|
||||||
return fu
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetType sets the "type" field.
|
// SetType sets the "type" field.
|
||||||
func (fu *FileUpdate) SetType(i int) *FileUpdate {
|
func (fu *FileUpdate) SetType(i int) *FileUpdate {
|
||||||
fu.mutation.ResetType()
|
fu.mutation.ResetType()
|
||||||
|
@ -472,9 +460,6 @@ func (fu *FileUpdate) RemoveDirectLinks(d ...*DirectLink) *FileUpdate {
|
||||||
|
|
||||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||||
func (fu *FileUpdate) Save(ctx context.Context) (int, error) {
|
func (fu *FileUpdate) Save(ctx context.Context) (int, error) {
|
||||||
if err := fu.defaults(); err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
return withHooks(ctx, fu.sqlSave, fu.mutation, fu.hooks)
|
return withHooks(ctx, fu.sqlSave, fu.mutation, fu.hooks)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -500,18 +485,6 @@ func (fu *FileUpdate) ExecX(ctx context.Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// defaults sets the default values of the builder before save.
|
|
||||||
func (fu *FileUpdate) defaults() error {
|
|
||||||
if _, ok := fu.mutation.UpdatedAt(); !ok {
|
|
||||||
if file.UpdateDefaultUpdatedAt == nil {
|
|
||||||
return fmt.Errorf("ent: uninitialized file.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
|
|
||||||
}
|
|
||||||
v := file.UpdateDefaultUpdatedAt()
|
|
||||||
fu.mutation.SetUpdatedAt(v)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// check runs all checks and user-defined validators on the builder.
|
// check runs all checks and user-defined validators on the builder.
|
||||||
func (fu *FileUpdate) check() error {
|
func (fu *FileUpdate) check() error {
|
||||||
if _, ok := fu.mutation.OwnerID(); fu.mutation.OwnerCleared() && !ok {
|
if _, ok := fu.mutation.OwnerID(); fu.mutation.OwnerCleared() && !ok {
|
||||||
|
@ -535,12 +508,6 @@ func (fu *FileUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||||
if value, ok := fu.mutation.UpdatedAt(); ok {
|
if value, ok := fu.mutation.UpdatedAt(); ok {
|
||||||
_spec.SetField(file.FieldUpdatedAt, field.TypeTime, value)
|
_spec.SetField(file.FieldUpdatedAt, field.TypeTime, value)
|
||||||
}
|
}
|
||||||
if value, ok := fu.mutation.DeletedAt(); ok {
|
|
||||||
_spec.SetField(file.FieldDeletedAt, field.TypeTime, value)
|
|
||||||
}
|
|
||||||
if fu.mutation.DeletedAtCleared() {
|
|
||||||
_spec.ClearField(file.FieldDeletedAt, field.TypeTime)
|
|
||||||
}
|
|
||||||
if value, ok := fu.mutation.GetType(); ok {
|
if value, ok := fu.mutation.GetType(); ok {
|
||||||
_spec.SetField(file.FieldType, field.TypeInt, value)
|
_spec.SetField(file.FieldType, field.TypeInt, value)
|
||||||
}
|
}
|
||||||
|
@ -912,26 +879,14 @@ func (fuo *FileUpdateOne) SetUpdatedAt(t time.Time) *FileUpdateOne {
|
||||||
return fuo
|
return fuo
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetDeletedAt sets the "deleted_at" field.
|
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
||||||
func (fuo *FileUpdateOne) SetDeletedAt(t time.Time) *FileUpdateOne {
|
func (fuo *FileUpdateOne) SetNillableUpdatedAt(t *time.Time) *FileUpdateOne {
|
||||||
fuo.mutation.SetDeletedAt(t)
|
|
||||||
return fuo
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
|
|
||||||
func (fuo *FileUpdateOne) SetNillableDeletedAt(t *time.Time) *FileUpdateOne {
|
|
||||||
if t != nil {
|
if t != nil {
|
||||||
fuo.SetDeletedAt(*t)
|
fuo.SetUpdatedAt(*t)
|
||||||
}
|
}
|
||||||
return fuo
|
return fuo
|
||||||
}
|
}
|
||||||
|
|
||||||
// ClearDeletedAt clears the value of the "deleted_at" field.
|
|
||||||
func (fuo *FileUpdateOne) ClearDeletedAt() *FileUpdateOne {
|
|
||||||
fuo.mutation.ClearDeletedAt()
|
|
||||||
return fuo
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetType sets the "type" field.
|
// SetType sets the "type" field.
|
||||||
func (fuo *FileUpdateOne) SetType(i int) *FileUpdateOne {
|
func (fuo *FileUpdateOne) SetType(i int) *FileUpdateOne {
|
||||||
fuo.mutation.ResetType()
|
fuo.mutation.ResetType()
|
||||||
|
@ -1356,9 +1311,6 @@ func (fuo *FileUpdateOne) Select(field string, fields ...string) *FileUpdateOne
|
||||||
|
|
||||||
// Save executes the query and returns the updated File entity.
|
// Save executes the query and returns the updated File entity.
|
||||||
func (fuo *FileUpdateOne) Save(ctx context.Context) (*File, error) {
|
func (fuo *FileUpdateOne) Save(ctx context.Context) (*File, error) {
|
||||||
if err := fuo.defaults(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return withHooks(ctx, fuo.sqlSave, fuo.mutation, fuo.hooks)
|
return withHooks(ctx, fuo.sqlSave, fuo.mutation, fuo.hooks)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1384,18 +1336,6 @@ func (fuo *FileUpdateOne) ExecX(ctx context.Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// defaults sets the default values of the builder before save.
|
|
||||||
func (fuo *FileUpdateOne) defaults() error {
|
|
||||||
if _, ok := fuo.mutation.UpdatedAt(); !ok {
|
|
||||||
if file.UpdateDefaultUpdatedAt == nil {
|
|
||||||
return fmt.Errorf("ent: uninitialized file.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
|
|
||||||
}
|
|
||||||
v := file.UpdateDefaultUpdatedAt()
|
|
||||||
fuo.mutation.SetUpdatedAt(v)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// check runs all checks and user-defined validators on the builder.
|
// check runs all checks and user-defined validators on the builder.
|
||||||
func (fuo *FileUpdateOne) check() error {
|
func (fuo *FileUpdateOne) check() error {
|
||||||
if _, ok := fuo.mutation.OwnerID(); fuo.mutation.OwnerCleared() && !ok {
|
if _, ok := fuo.mutation.OwnerID(); fuo.mutation.OwnerCleared() && !ok {
|
||||||
|
@ -1436,12 +1376,6 @@ func (fuo *FileUpdateOne) sqlSave(ctx context.Context) (_node *File, err error)
|
||||||
if value, ok := fuo.mutation.UpdatedAt(); ok {
|
if value, ok := fuo.mutation.UpdatedAt(); ok {
|
||||||
_spec.SetField(file.FieldUpdatedAt, field.TypeTime, value)
|
_spec.SetField(file.FieldUpdatedAt, field.TypeTime, value)
|
||||||
}
|
}
|
||||||
if value, ok := fuo.mutation.DeletedAt(); ok {
|
|
||||||
_spec.SetField(file.FieldDeletedAt, field.TypeTime, value)
|
|
||||||
}
|
|
||||||
if fuo.mutation.DeletedAtCleared() {
|
|
||||||
_spec.ClearField(file.FieldDeletedAt, field.TypeTime)
|
|
||||||
}
|
|
||||||
if value, ok := fuo.mutation.GetType(); ok {
|
if value, ok := fuo.mutation.GetType(); ok {
|
||||||
_spec.SetField(file.FieldType, field.TypeInt, value)
|
_spec.SetField(file.FieldType, field.TypeInt, value)
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -107,7 +107,6 @@ var (
|
||||||
{Name: "id", Type: field.TypeInt, Increment: true},
|
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||||
{Name: "created_at", Type: field.TypeTime, SchemaType: map[string]string{"mysql": "datetime"}},
|
{Name: "created_at", Type: field.TypeTime, SchemaType: map[string]string{"mysql": "datetime"}},
|
||||||
{Name: "updated_at", Type: field.TypeTime, SchemaType: map[string]string{"mysql": "datetime"}},
|
{Name: "updated_at", Type: field.TypeTime, SchemaType: map[string]string{"mysql": "datetime"}},
|
||||||
{Name: "deleted_at", Type: field.TypeTime, Nullable: true, SchemaType: map[string]string{"mysql": "datetime"}},
|
|
||||||
{Name: "type", Type: field.TypeInt},
|
{Name: "type", Type: field.TypeInt},
|
||||||
{Name: "name", Type: field.TypeString},
|
{Name: "name", Type: field.TypeString},
|
||||||
{Name: "size", Type: field.TypeInt64, Default: 0},
|
{Name: "size", Type: field.TypeInt64, Default: 0},
|
||||||
|
@ -126,19 +125,19 @@ var (
|
||||||
ForeignKeys: []*schema.ForeignKey{
|
ForeignKeys: []*schema.ForeignKey{
|
||||||
{
|
{
|
||||||
Symbol: "files_files_children",
|
Symbol: "files_files_children",
|
||||||
Columns: []*schema.Column{FilesColumns[10]},
|
Columns: []*schema.Column{FilesColumns[9]},
|
||||||
RefColumns: []*schema.Column{FilesColumns[0]},
|
RefColumns: []*schema.Column{FilesColumns[0]},
|
||||||
OnDelete: schema.SetNull,
|
OnDelete: schema.SetNull,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Symbol: "files_storage_policies_files",
|
Symbol: "files_storage_policies_files",
|
||||||
Columns: []*schema.Column{FilesColumns[11]},
|
Columns: []*schema.Column{FilesColumns[10]},
|
||||||
RefColumns: []*schema.Column{StoragePoliciesColumns[0]},
|
RefColumns: []*schema.Column{StoragePoliciesColumns[0]},
|
||||||
OnDelete: schema.SetNull,
|
OnDelete: schema.SetNull,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Symbol: "files_users_files",
|
Symbol: "files_users_files",
|
||||||
Columns: []*schema.Column{FilesColumns[12]},
|
Columns: []*schema.Column{FilesColumns[11]},
|
||||||
RefColumns: []*schema.Column{UsersColumns[0]},
|
RefColumns: []*schema.Column{UsersColumns[0]},
|
||||||
OnDelete: schema.NoAction,
|
OnDelete: schema.NoAction,
|
||||||
},
|
},
|
||||||
|
@ -147,17 +146,17 @@ var (
|
||||||
{
|
{
|
||||||
Name: "file_file_children_name",
|
Name: "file_file_children_name",
|
||||||
Unique: true,
|
Unique: true,
|
||||||
Columns: []*schema.Column{FilesColumns[10], FilesColumns[5]},
|
Columns: []*schema.Column{FilesColumns[9], FilesColumns[4]},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "file_file_children_type_updated_at",
|
Name: "file_file_children_type_updated_at",
|
||||||
Unique: false,
|
Unique: false,
|
||||||
Columns: []*schema.Column{FilesColumns[10], FilesColumns[4], FilesColumns[2]},
|
Columns: []*schema.Column{FilesColumns[9], FilesColumns[3], FilesColumns[2]},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "file_file_children_type_size",
|
Name: "file_file_children_type_size",
|
||||||
Unique: false,
|
Unique: false,
|
||||||
Columns: []*schema.Column{FilesColumns[10], FilesColumns[4], FilesColumns[6]},
|
Columns: []*schema.Column{FilesColumns[9], FilesColumns[3], FilesColumns[5]},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -2972,7 +2972,6 @@ type FileMutation struct {
|
||||||
id *int
|
id *int
|
||||||
created_at *time.Time
|
created_at *time.Time
|
||||||
updated_at *time.Time
|
updated_at *time.Time
|
||||||
deleted_at *time.Time
|
|
||||||
_type *int
|
_type *int
|
||||||
add_type *int
|
add_type *int
|
||||||
name *string
|
name *string
|
||||||
|
@ -3179,55 +3178,6 @@ func (m *FileMutation) ResetUpdatedAt() {
|
||||||
m.updated_at = nil
|
m.updated_at = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetDeletedAt sets the "deleted_at" field.
|
|
||||||
func (m *FileMutation) SetDeletedAt(t time.Time) {
|
|
||||||
m.deleted_at = &t
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeletedAt returns the value of the "deleted_at" field in the mutation.
|
|
||||||
func (m *FileMutation) DeletedAt() (r time.Time, exists bool) {
|
|
||||||
v := m.deleted_at
|
|
||||||
if v == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
return *v, true
|
|
||||||
}
|
|
||||||
|
|
||||||
// OldDeletedAt returns the old "deleted_at" field's value of the File entity.
|
|
||||||
// If the File 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 *FileMutation) OldDeletedAt(ctx context.Context) (v *time.Time, err error) {
|
|
||||||
if !m.op.Is(OpUpdateOne) {
|
|
||||||
return v, errors.New("OldDeletedAt is only allowed on UpdateOne operations")
|
|
||||||
}
|
|
||||||
if m.id == nil || m.oldValue == nil {
|
|
||||||
return v, errors.New("OldDeletedAt requires an ID field in the mutation")
|
|
||||||
}
|
|
||||||
oldValue, err := m.oldValue(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return v, fmt.Errorf("querying old value for OldDeletedAt: %w", err)
|
|
||||||
}
|
|
||||||
return oldValue.DeletedAt, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ClearDeletedAt clears the value of the "deleted_at" field.
|
|
||||||
func (m *FileMutation) ClearDeletedAt() {
|
|
||||||
m.deleted_at = nil
|
|
||||||
m.clearedFields[file.FieldDeletedAt] = struct{}{}
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation.
|
|
||||||
func (m *FileMutation) DeletedAtCleared() bool {
|
|
||||||
_, ok := m.clearedFields[file.FieldDeletedAt]
|
|
||||||
return ok
|
|
||||||
}
|
|
||||||
|
|
||||||
// ResetDeletedAt resets all changes to the "deleted_at" field.
|
|
||||||
func (m *FileMutation) ResetDeletedAt() {
|
|
||||||
m.deleted_at = nil
|
|
||||||
delete(m.clearedFields, file.FieldDeletedAt)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetType sets the "type" field.
|
// SetType sets the "type" field.
|
||||||
func (m *FileMutation) SetType(i int) {
|
func (m *FileMutation) SetType(i int) {
|
||||||
m._type = &i
|
m._type = &i
|
||||||
|
@ -4076,16 +4026,13 @@ func (m *FileMutation) 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 *FileMutation) Fields() []string {
|
func (m *FileMutation) Fields() []string {
|
||||||
fields := make([]string, 0, 12)
|
fields := make([]string, 0, 11)
|
||||||
if m.created_at != nil {
|
if m.created_at != nil {
|
||||||
fields = append(fields, file.FieldCreatedAt)
|
fields = append(fields, file.FieldCreatedAt)
|
||||||
}
|
}
|
||||||
if m.updated_at != nil {
|
if m.updated_at != nil {
|
||||||
fields = append(fields, file.FieldUpdatedAt)
|
fields = append(fields, file.FieldUpdatedAt)
|
||||||
}
|
}
|
||||||
if m.deleted_at != nil {
|
|
||||||
fields = append(fields, file.FieldDeletedAt)
|
|
||||||
}
|
|
||||||
if m._type != nil {
|
if m._type != nil {
|
||||||
fields = append(fields, file.FieldType)
|
fields = append(fields, file.FieldType)
|
||||||
}
|
}
|
||||||
|
@ -4125,8 +4072,6 @@ func (m *FileMutation) Field(name string) (ent.Value, bool) {
|
||||||
return m.CreatedAt()
|
return m.CreatedAt()
|
||||||
case file.FieldUpdatedAt:
|
case file.FieldUpdatedAt:
|
||||||
return m.UpdatedAt()
|
return m.UpdatedAt()
|
||||||
case file.FieldDeletedAt:
|
|
||||||
return m.DeletedAt()
|
|
||||||
case file.FieldType:
|
case file.FieldType:
|
||||||
return m.GetType()
|
return m.GetType()
|
||||||
case file.FieldName:
|
case file.FieldName:
|
||||||
|
@ -4158,8 +4103,6 @@ func (m *FileMutation) OldField(ctx context.Context, name string) (ent.Value, er
|
||||||
return m.OldCreatedAt(ctx)
|
return m.OldCreatedAt(ctx)
|
||||||
case file.FieldUpdatedAt:
|
case file.FieldUpdatedAt:
|
||||||
return m.OldUpdatedAt(ctx)
|
return m.OldUpdatedAt(ctx)
|
||||||
case file.FieldDeletedAt:
|
|
||||||
return m.OldDeletedAt(ctx)
|
|
||||||
case file.FieldType:
|
case file.FieldType:
|
||||||
return m.OldType(ctx)
|
return m.OldType(ctx)
|
||||||
case file.FieldName:
|
case file.FieldName:
|
||||||
|
@ -4201,13 +4144,6 @@ func (m *FileMutation) SetField(name string, value ent.Value) error {
|
||||||
}
|
}
|
||||||
m.SetUpdatedAt(v)
|
m.SetUpdatedAt(v)
|
||||||
return nil
|
return nil
|
||||||
case file.FieldDeletedAt:
|
|
||||||
v, ok := value.(time.Time)
|
|
||||||
if !ok {
|
|
||||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
|
||||||
}
|
|
||||||
m.SetDeletedAt(v)
|
|
||||||
return nil
|
|
||||||
case file.FieldType:
|
case file.FieldType:
|
||||||
v, ok := value.(int)
|
v, ok := value.(int)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
@ -4340,9 +4276,6 @@ func (m *FileMutation) AddField(name string, value ent.Value) error {
|
||||||
// mutation.
|
// mutation.
|
||||||
func (m *FileMutation) ClearedFields() []string {
|
func (m *FileMutation) ClearedFields() []string {
|
||||||
var fields []string
|
var fields []string
|
||||||
if m.FieldCleared(file.FieldDeletedAt) {
|
|
||||||
fields = append(fields, file.FieldDeletedAt)
|
|
||||||
}
|
|
||||||
if m.FieldCleared(file.FieldPrimaryEntity) {
|
if m.FieldCleared(file.FieldPrimaryEntity) {
|
||||||
fields = append(fields, file.FieldPrimaryEntity)
|
fields = append(fields, file.FieldPrimaryEntity)
|
||||||
}
|
}
|
||||||
|
@ -4369,9 +4302,6 @@ func (m *FileMutation) 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 *FileMutation) ClearField(name string) error {
|
func (m *FileMutation) ClearField(name string) error {
|
||||||
switch name {
|
switch name {
|
||||||
case file.FieldDeletedAt:
|
|
||||||
m.ClearDeletedAt()
|
|
||||||
return nil
|
|
||||||
case file.FieldPrimaryEntity:
|
case file.FieldPrimaryEntity:
|
||||||
m.ClearPrimaryEntity()
|
m.ClearPrimaryEntity()
|
||||||
return nil
|
return nil
|
||||||
|
@ -4398,9 +4328,6 @@ func (m *FileMutation) ResetField(name string) error {
|
||||||
case file.FieldUpdatedAt:
|
case file.FieldUpdatedAt:
|
||||||
m.ResetUpdatedAt()
|
m.ResetUpdatedAt()
|
||||||
return nil
|
return nil
|
||||||
case file.FieldDeletedAt:
|
|
||||||
m.ResetDeletedAt()
|
|
||||||
return nil
|
|
||||||
case file.FieldType:
|
case file.FieldType:
|
||||||
m.ResetType()
|
m.ResetType()
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -87,31 +87,24 @@ func init() {
|
||||||
entityDescReferenceCount := entityFields[3].Descriptor()
|
entityDescReferenceCount := entityFields[3].Descriptor()
|
||||||
// entity.DefaultReferenceCount holds the default value on creation for the reference_count field.
|
// entity.DefaultReferenceCount holds the default value on creation for the reference_count field.
|
||||||
entity.DefaultReferenceCount = entityDescReferenceCount.Default.(int)
|
entity.DefaultReferenceCount = entityDescReferenceCount.Default.(int)
|
||||||
fileMixin := schema.File{}.Mixin()
|
fileHooks := schema.File{}.Hooks()
|
||||||
fileMixinHooks0 := fileMixin[0].Hooks()
|
file.Hooks[0] = fileHooks[0]
|
||||||
file.Hooks[0] = fileMixinHooks0[0]
|
|
||||||
fileMixinInters0 := fileMixin[0].Interceptors()
|
|
||||||
file.Interceptors[0] = fileMixinInters0[0]
|
|
||||||
fileMixinFields0 := fileMixin[0].Fields()
|
|
||||||
_ = fileMixinFields0
|
|
||||||
fileFields := schema.File{}.Fields()
|
fileFields := schema.File{}.Fields()
|
||||||
_ = fileFields
|
_ = fileFields
|
||||||
// fileDescCreatedAt is the schema descriptor for created_at field.
|
// fileDescCreatedAt is the schema descriptor for created_at field.
|
||||||
fileDescCreatedAt := fileMixinFields0[0].Descriptor()
|
fileDescCreatedAt := fileFields[0].Descriptor()
|
||||||
// file.DefaultCreatedAt holds the default value on creation for the created_at field.
|
// file.DefaultCreatedAt holds the default value on creation for the created_at field.
|
||||||
file.DefaultCreatedAt = fileDescCreatedAt.Default.(func() time.Time)
|
file.DefaultCreatedAt = fileDescCreatedAt.Default.(func() time.Time)
|
||||||
// fileDescUpdatedAt is the schema descriptor for updated_at field.
|
// fileDescUpdatedAt is the schema descriptor for updated_at field.
|
||||||
fileDescUpdatedAt := fileMixinFields0[1].Descriptor()
|
fileDescUpdatedAt := fileFields[1].Descriptor()
|
||||||
// file.DefaultUpdatedAt holds the default value on creation for the updated_at field.
|
// file.DefaultUpdatedAt holds the default value on creation for the updated_at field.
|
||||||
file.DefaultUpdatedAt = fileDescUpdatedAt.Default.(func() time.Time)
|
file.DefaultUpdatedAt = fileDescUpdatedAt.Default.(func() time.Time)
|
||||||
// file.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field.
|
|
||||||
file.UpdateDefaultUpdatedAt = fileDescUpdatedAt.UpdateDefault.(func() time.Time)
|
|
||||||
// fileDescSize is the schema descriptor for size field.
|
// fileDescSize is the schema descriptor for size field.
|
||||||
fileDescSize := fileFields[3].Descriptor()
|
fileDescSize := fileFields[5].Descriptor()
|
||||||
// file.DefaultSize holds the default value on creation for the size field.
|
// file.DefaultSize holds the default value on creation for the size field.
|
||||||
file.DefaultSize = fileDescSize.Default.(int64)
|
file.DefaultSize = fileDescSize.Default.(int64)
|
||||||
// fileDescIsSymbolic is the schema descriptor for is_symbolic field.
|
// fileDescIsSymbolic is the schema descriptor for is_symbolic field.
|
||||||
fileDescIsSymbolic := fileFields[6].Descriptor()
|
fileDescIsSymbolic := fileFields[8].Descriptor()
|
||||||
// file.DefaultIsSymbolic holds the default value on creation for the is_symbolic field.
|
// file.DefaultIsSymbolic holds the default value on creation for the is_symbolic field.
|
||||||
file.DefaultIsSymbolic = fileDescIsSymbolic.Default.(bool)
|
file.DefaultIsSymbolic = fileDescIsSymbolic.Default.(bool)
|
||||||
groupMixin := schema.Group{}.Mixin()
|
groupMixin := schema.Group{}.Mixin()
|
||||||
|
|
|
@ -1,10 +1,15 @@
|
||||||
package schema
|
package schema
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
"time"
|
||||||
|
|
||||||
"entgo.io/ent"
|
"entgo.io/ent"
|
||||||
|
"entgo.io/ent/dialect"
|
||||||
"entgo.io/ent/schema/edge"
|
"entgo.io/ent/schema/edge"
|
||||||
"entgo.io/ent/schema/field"
|
"entgo.io/ent/schema/field"
|
||||||
"entgo.io/ent/schema/index"
|
"entgo.io/ent/schema/index"
|
||||||
|
"github.com/cloudreve/Cloudreve/v4/ent/hook"
|
||||||
"github.com/cloudreve/Cloudreve/v4/inventory/types"
|
"github.com/cloudreve/Cloudreve/v4/inventory/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -16,6 +21,17 @@ type File struct {
|
||||||
// Fields of the File.
|
// Fields of the File.
|
||||||
func (File) Fields() []ent.Field {
|
func (File) Fields() []ent.Field {
|
||||||
return []ent.Field{
|
return []ent.Field{
|
||||||
|
field.Time("created_at").
|
||||||
|
Immutable().
|
||||||
|
Default(time.Now).
|
||||||
|
SchemaType(map[string]string{
|
||||||
|
dialect.MySQL: "datetime",
|
||||||
|
}),
|
||||||
|
field.Time("updated_at").
|
||||||
|
Default(time.Now).
|
||||||
|
SchemaType(map[string]string{
|
||||||
|
dialect.MySQL: "datetime",
|
||||||
|
}),
|
||||||
field.Int("type"),
|
field.Int("type"),
|
||||||
field.String("name"),
|
field.String("name"),
|
||||||
field.Int("owner_id"),
|
field.Int("owner_id"),
|
||||||
|
@ -66,8 +82,19 @@ func (File) Indexes() []ent.Index {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (File) Mixin() []ent.Mixin {
|
func (f File) Hooks() []ent.Hook {
|
||||||
return []ent.Mixin{
|
return []ent.Hook{
|
||||||
CommonMixin{},
|
hook.On(func(next ent.Mutator) ent.Mutator {
|
||||||
|
return ent.MutateFunc(func(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||||
|
if s, ok := m.(interface{ SetUpdatedAt(time.Time) }); ok {
|
||||||
|
_, set := m.Field("updated_at")
|
||||||
|
if !set {
|
||||||
|
s.SetUpdatedAt(time.Now())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
v, err := next.Mutate(ctx, m)
|
||||||
|
return v, err
|
||||||
|
})
|
||||||
|
}, ent.OpUpdate|ent.OpUpdateOne),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -217,6 +217,8 @@ type FileClient interface {
|
||||||
ListEntities(ctx context.Context, args *ListEntityParameters) (*ListEntityResult, error)
|
ListEntities(ctx context.Context, args *ListEntityParameters) (*ListEntityResult, error)
|
||||||
// UpdateProps updates props of a file
|
// UpdateProps updates props of a file
|
||||||
UpdateProps(ctx context.Context, file *ent.File, props *types.FileProps) (*ent.File, error)
|
UpdateProps(ctx context.Context, file *ent.File, props *types.FileProps) (*ent.File, error)
|
||||||
|
// UpdateModifiedAt updates modified at of a file
|
||||||
|
UpdateModifiedAt(ctx context.Context, file *ent.File, modifiedAt time.Time) error
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFileClient(client *ent.Client, dbType conf.DBType, hasher hashid.Encoder) FileClient {
|
func NewFileClient(client *ent.Client, dbType conf.DBType, hasher hashid.Encoder) FileClient {
|
||||||
|
@ -646,6 +648,10 @@ func (f *fileClient) Copy(ctx context.Context, files []*ent.File, dstMap map[int
|
||||||
return newDstMap, map[int]int64{dstMap[files[0].FileChildren][0].OwnerID: sizeDiff}, nil
|
return newDstMap, map[int]int64{dstMap[files[0].FileChildren][0].OwnerID: sizeDiff}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (f *fileClient) UpdateModifiedAt(ctx context.Context, file *ent.File, modifiedAt time.Time) error {
|
||||||
|
return f.client.File.UpdateOne(file).SetUpdatedAt(modifiedAt).Exec(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
func (f *fileClient) UpsertMetadata(ctx context.Context, file *ent.File, data map[string]string, privateMask map[string]bool) error {
|
func (f *fileClient) UpsertMetadata(ctx context.Context, file *ent.File, data map[string]string, privateMask map[string]bool) error {
|
||||||
// Validate value length
|
// Validate value length
|
||||||
for key, value := range data {
|
for key, value := range data {
|
||||||
|
@ -718,10 +724,15 @@ func (f *fileClient) UpgradePlaceholder(ctx context.Context, file *ent.File, mod
|
||||||
}
|
}
|
||||||
|
|
||||||
if entityType == types.EntityTypeVersion {
|
if entityType == types.EntityTypeVersion {
|
||||||
if err := f.client.File.UpdateOne(file).
|
stm := f.client.File.UpdateOne(file).
|
||||||
SetSize(placeholder.Size).
|
SetSize(placeholder.Size).
|
||||||
SetPrimaryEntity(placeholder.ID).
|
SetPrimaryEntity(placeholder.ID)
|
||||||
Exec(ctx); err != nil {
|
|
||||||
|
if modifiedAt != nil {
|
||||||
|
stm.SetUpdatedAt(*modifiedAt)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := stm.Exec(ctx); err != nil {
|
||||||
return fmt.Errorf("failed to upgrade file primary entity: %v", err)
|
return fmt.Errorf("failed to upgrade file primary entity: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package dbfs
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/cloudreve/Cloudreve/v4/inventory"
|
"github.com/cloudreve/Cloudreve/v4/inventory"
|
||||||
"github.com/cloudreve/Cloudreve/v4/inventory/types"
|
"github.com/cloudreve/Cloudreve/v4/inventory/types"
|
||||||
|
@ -100,6 +101,7 @@ func (f *DBFS) PatchMetadata(ctx context.Context, path []*fs.URI, metas ...fs.Me
|
||||||
metadataMap := make(map[string]string)
|
metadataMap := make(map[string]string)
|
||||||
privateMap := make(map[string]bool)
|
privateMap := make(map[string]bool)
|
||||||
deleted := make([]string, 0)
|
deleted := make([]string, 0)
|
||||||
|
updateModifiedAt := false
|
||||||
for _, meta := range metas {
|
for _, meta := range metas {
|
||||||
if meta.Remove {
|
if meta.Remove {
|
||||||
deleted = append(deleted, meta.Key)
|
deleted = append(deleted, meta.Key)
|
||||||
|
@ -109,6 +111,9 @@ func (f *DBFS) PatchMetadata(ctx context.Context, path []*fs.URI, metas ...fs.Me
|
||||||
if meta.Private {
|
if meta.Private {
|
||||||
privateMap[meta.Key] = meta.Private
|
privateMap[meta.Key] = meta.Private
|
||||||
}
|
}
|
||||||
|
if meta.UpdateModifiedAt {
|
||||||
|
updateModifiedAt = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fc, tx, ctx, err := inventory.WithTx(ctx, f.fileClient)
|
fc, tx, ctx, err := inventory.WithTx(ctx, f.fileClient)
|
||||||
|
@ -128,6 +133,13 @@ func (f *DBFS) PatchMetadata(ctx context.Context, path []*fs.URI, metas ...fs.Me
|
||||||
return fmt.Errorf("failed to remove metadata: %w", err)
|
return fmt.Errorf("failed to remove metadata: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if updateModifiedAt {
|
||||||
|
if err := fc.UpdateModifiedAt(ctx, target.Model, time.Now()); err != nil {
|
||||||
|
_ = inventory.Rollback(tx)
|
||||||
|
return fmt.Errorf("failed to update file modified at: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := inventory.Commit(tx); err != nil {
|
if err := inventory.Commit(tx); err != nil {
|
||||||
|
|
|
@ -203,10 +203,11 @@ type (
|
||||||
}
|
}
|
||||||
|
|
||||||
MetadataPatch struct {
|
MetadataPatch struct {
|
||||||
Key string `json:"key" binding:"required"`
|
Key string `json:"key" binding:"required"`
|
||||||
Value string `json:"value"`
|
Value string `json:"value"`
|
||||||
Private bool `json:"private" binding:"ne=true"`
|
Private bool `json:"private" binding:"ne=true"`
|
||||||
Remove bool `json:"remove"`
|
Remove bool `json:"remove"`
|
||||||
|
UpdateModifiedAt bool `json:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListFileResult result of listing files.
|
// ListFileResult result of listing files.
|
||||||
|
|
|
@ -43,6 +43,8 @@ var (
|
||||||
// validateColor validates a color value
|
// validateColor validates a color value
|
||||||
validateColor = func(optional bool) metadataValidator {
|
validateColor = func(optional bool) metadataValidator {
|
||||||
return func(ctx context.Context, m *manager, patch *fs.MetadataPatch) error {
|
return func(ctx context.Context, m *manager, patch *fs.MetadataPatch) error {
|
||||||
|
patch.UpdateModifiedAt = true
|
||||||
|
|
||||||
if patch.Remove {
|
if patch.Remove {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -67,6 +69,8 @@ var (
|
||||||
return fmt.Errorf("cannot remove system metadata")
|
return fmt.Errorf("cannot remove system metadata")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
patch.UpdateModifiedAt = true
|
||||||
|
|
||||||
dep := dependency.FromContext(ctx)
|
dep := dependency.FromContext(ctx)
|
||||||
// Validate share owner is valid hashid
|
// Validate share owner is valid hashid
|
||||||
if patch.Key == shareOwnerMetadataKey {
|
if patch.Key == shareOwnerMetadataKey {
|
||||||
|
@ -96,6 +100,8 @@ var (
|
||||||
customizeMetadataSuffix: {
|
customizeMetadataSuffix: {
|
||||||
iconColorMetadataKey: validateColor(false),
|
iconColorMetadataKey: validateColor(false),
|
||||||
emojiIconMetadataKey: func(ctx context.Context, m *manager, patch *fs.MetadataPatch) error {
|
emojiIconMetadataKey: func(ctx context.Context, m *manager, patch *fs.MetadataPatch) error {
|
||||||
|
patch.UpdateModifiedAt = true
|
||||||
|
|
||||||
if patch.Remove {
|
if patch.Remove {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -125,6 +131,8 @@ var (
|
||||||
},
|
},
|
||||||
tagMetadataSuffix: {
|
tagMetadataSuffix: {
|
||||||
wildcardMetadataKey: func(ctx context.Context, m *manager, patch *fs.MetadataPatch) error {
|
wildcardMetadataKey: func(ctx context.Context, m *manager, patch *fs.MetadataPatch) error {
|
||||||
|
patch.UpdateModifiedAt = true
|
||||||
|
|
||||||
if err := validateColor(true)(ctx, m, patch); err != nil {
|
if err := validateColor(true)(ctx, m, patch); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -138,6 +146,8 @@ var (
|
||||||
},
|
},
|
||||||
customPropsMetadataSuffix: {
|
customPropsMetadataSuffix: {
|
||||||
wildcardMetadataKey: func(ctx context.Context, m *manager, patch *fs.MetadataPatch) error {
|
wildcardMetadataKey: func(ctx context.Context, m *manager, patch *fs.MetadataPatch) error {
|
||||||
|
patch.UpdateModifiedAt = true
|
||||||
|
|
||||||
if patch.Remove {
|
if patch.Remove {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -260,40 +270,44 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
func (m *manager) PatchMedata(ctx context.Context, path []*fs.URI, data ...fs.MetadataPatch) error {
|
func (m *manager) PatchMedata(ctx context.Context, path []*fs.URI, data ...fs.MetadataPatch) error {
|
||||||
if err := m.validateMetadata(ctx, data...); err != nil {
|
data, err := m.validateMetadata(ctx, data...)
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return m.fs.PatchMetadata(ctx, path, data...)
|
return m.fs.PatchMetadata(ctx, path, data...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *manager) validateMetadata(ctx context.Context, data ...fs.MetadataPatch) error {
|
func (m *manager) validateMetadata(ctx context.Context, data ...fs.MetadataPatch) ([]fs.MetadataPatch, error) {
|
||||||
|
validated := make([]fs.MetadataPatch, 0, len(data))
|
||||||
for _, patch := range data {
|
for _, patch := range data {
|
||||||
category := strings.Split(patch.Key, ":")
|
category := strings.Split(patch.Key, ":")
|
||||||
if len(category) < 2 {
|
if len(category) < 2 {
|
||||||
return serializer.NewError(serializer.CodeParamErr, "Invalid metadata key", nil)
|
return validated, serializer.NewError(serializer.CodeParamErr, "Invalid metadata key", nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
categoryValidators, ok := validators[category[0]]
|
categoryValidators, ok := validators[category[0]]
|
||||||
if !ok {
|
if !ok {
|
||||||
return serializer.NewError(serializer.CodeParamErr, "Invalid metadata key",
|
return validated, serializer.NewError(serializer.CodeParamErr, "Invalid metadata key",
|
||||||
fmt.Errorf("unknown category: %s", category[0]))
|
fmt.Errorf("unknown category: %s", category[0]))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Explicit validators
|
// Explicit validators
|
||||||
if v, ok := categoryValidators[patch.Key]; ok {
|
if v, ok := categoryValidators[patch.Key]; ok {
|
||||||
if err := v(ctx, m, &patch); err != nil {
|
if err := v(ctx, m, &patch); err != nil {
|
||||||
return serializer.NewError(serializer.CodeParamErr, "Invalid metadata patch", err)
|
return validated, serializer.NewError(serializer.CodeParamErr, "Invalid metadata patch", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wildcard validators
|
// Wildcard validators
|
||||||
if v, ok := categoryValidators[wildcardMetadataKey]; ok {
|
if v, ok := categoryValidators[wildcardMetadataKey]; ok {
|
||||||
if err := v(ctx, m, &patch); err != nil {
|
if err := v(ctx, m, &patch); err != nil {
|
||||||
return serializer.NewError(serializer.CodeParamErr, "Invalid metadata patch", err)
|
return validated, serializer.NewError(serializer.CodeParamErr, "Invalid metadata patch", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
validated = append(validated, patch)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return validated, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,7 +115,7 @@ func (m *manager) Create(ctx context.Context, path *fs.URI, fileType types.FileT
|
||||||
|
|
||||||
isSymbolic := false
|
isSymbolic := false
|
||||||
if o.Metadata != nil {
|
if o.Metadata != nil {
|
||||||
if err := m.validateMetadata(ctx, lo.MapToSlice(o.Metadata, func(key string, value string) fs.MetadataPatch {
|
_, err := m.validateMetadata(ctx, lo.MapToSlice(o.Metadata, func(key string, value string) fs.MetadataPatch {
|
||||||
if key == shareRedirectMetadataKey {
|
if key == shareRedirectMetadataKey {
|
||||||
isSymbolic = true
|
isSymbolic = true
|
||||||
}
|
}
|
||||||
|
@ -124,7 +124,8 @@ func (m *manager) Create(ctx context.Context, path *fs.URI, fileType types.FileT
|
||||||
Key: key,
|
Key: key,
|
||||||
Value: value,
|
Value: value,
|
||||||
}
|
}
|
||||||
})...); err != nil {
|
})...)
|
||||||
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ func (m *manager) CreateUploadSession(ctx context.Context, req *fs.UploadRequest
|
||||||
|
|
||||||
// Validate metadata
|
// Validate metadata
|
||||||
if req.Props.Metadata != nil {
|
if req.Props.Metadata != nil {
|
||||||
if err := m.validateMetadata(ctx, lo.MapToSlice(req.Props.Metadata, func(key string, value string) fs.MetadataPatch {
|
if _, err := m.validateMetadata(ctx, lo.MapToSlice(req.Props.Metadata, func(key string, value string) fs.MetadataPatch {
|
||||||
return fs.MetadataPatch{
|
return fs.MetadataPatch{
|
||||||
Key: key,
|
Key: key,
|
||||||
Value: value,
|
Value: value,
|
||||||
|
|
Loading…
Reference in New Issue