feat(explorer): save user's view setting to server / optionally share view setting via share link (#2232)

This commit is contained in:
Aaron Liu
2025-06-05 10:00:37 +08:00
parent c13b7365b0
commit 522fcca6af
31 changed files with 704 additions and 158 deletions

View File

@@ -14,6 +14,7 @@ import (
"github.com/cloudreve/Cloudreve/v4/ent/file"
"github.com/cloudreve/Cloudreve/v4/ent/share"
"github.com/cloudreve/Cloudreve/v4/ent/user"
"github.com/cloudreve/Cloudreve/v4/inventory/types"
)
// ShareCreate is the builder for creating a Share entity.
@@ -136,6 +137,12 @@ func (sc *ShareCreate) SetNillableRemainDownloads(i *int) *ShareCreate {
return sc
}
// SetProps sets the "props" field.
func (sc *ShareCreate) SetProps(tp *types.ShareProps) *ShareCreate {
sc.mutation.SetProps(tp)
return sc
}
// SetUserID sets the "user" edge to the User entity by ID.
func (sc *ShareCreate) SetUserID(id int) *ShareCreate {
sc.mutation.SetUserID(id)
@@ -316,6 +323,10 @@ func (sc *ShareCreate) createSpec() (*Share, *sqlgraph.CreateSpec) {
_spec.SetField(share.FieldRemainDownloads, field.TypeInt, value)
_node.RemainDownloads = &value
}
if value, ok := sc.mutation.Props(); ok {
_spec.SetField(share.FieldProps, field.TypeJSON, value)
_node.Props = value
}
if nodes := sc.mutation.UserIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
@@ -528,6 +539,24 @@ func (u *ShareUpsert) ClearRemainDownloads() *ShareUpsert {
return u
}
// SetProps sets the "props" field.
func (u *ShareUpsert) SetProps(v *types.ShareProps) *ShareUpsert {
u.Set(share.FieldProps, v)
return u
}
// UpdateProps sets the "props" field to the value that was provided on create.
func (u *ShareUpsert) UpdateProps() *ShareUpsert {
u.SetExcluded(share.FieldProps)
return u
}
// ClearProps clears the value of the "props" field.
func (u *ShareUpsert) ClearProps() *ShareUpsert {
u.SetNull(share.FieldProps)
return u
}
// UpdateNewValues updates the mutable fields using the new values that were set on create.
// Using this option is equivalent to using:
//
@@ -720,6 +749,27 @@ func (u *ShareUpsertOne) ClearRemainDownloads() *ShareUpsertOne {
})
}
// SetProps sets the "props" field.
func (u *ShareUpsertOne) SetProps(v *types.ShareProps) *ShareUpsertOne {
return u.Update(func(s *ShareUpsert) {
s.SetProps(v)
})
}
// UpdateProps sets the "props" field to the value that was provided on create.
func (u *ShareUpsertOne) UpdateProps() *ShareUpsertOne {
return u.Update(func(s *ShareUpsert) {
s.UpdateProps()
})
}
// ClearProps clears the value of the "props" field.
func (u *ShareUpsertOne) ClearProps() *ShareUpsertOne {
return u.Update(func(s *ShareUpsert) {
s.ClearProps()
})
}
// Exec executes the query.
func (u *ShareUpsertOne) Exec(ctx context.Context) error {
if len(u.create.conflict) == 0 {
@@ -1083,6 +1133,27 @@ func (u *ShareUpsertBulk) ClearRemainDownloads() *ShareUpsertBulk {
})
}
// SetProps sets the "props" field.
func (u *ShareUpsertBulk) SetProps(v *types.ShareProps) *ShareUpsertBulk {
return u.Update(func(s *ShareUpsert) {
s.SetProps(v)
})
}
// UpdateProps sets the "props" field to the value that was provided on create.
func (u *ShareUpsertBulk) UpdateProps() *ShareUpsertBulk {
return u.Update(func(s *ShareUpsert) {
s.UpdateProps()
})
}
// ClearProps clears the value of the "props" field.
func (u *ShareUpsertBulk) ClearProps() *ShareUpsertBulk {
return u.Update(func(s *ShareUpsert) {
s.ClearProps()
})
}
// Exec executes the query.
func (u *ShareUpsertBulk) Exec(ctx context.Context) error {
if u.create.err != nil {