feat(explorer): save user's view setting to server / optionally share view setting via share link (#2232)
This commit is contained in:
@@ -209,6 +209,8 @@ type FileClient interface {
|
||||
Update(ctx context.Context, file *ent.File) (*ent.File, error)
|
||||
// ListEntities lists entities
|
||||
ListEntities(ctx context.Context, args *ListEntityParameters) (*ListEntityResult, error)
|
||||
// UpdateProps updates props of a file
|
||||
UpdateProps(ctx context.Context, file *ent.File, props *types.FileProps) (*ent.File, error)
|
||||
}
|
||||
|
||||
func NewFileClient(client *ent.Client, dbType conf.DBType, hasher hashid.Encoder) FileClient {
|
||||
@@ -275,6 +277,17 @@ func (f *fileClient) Update(ctx context.Context, file *ent.File) (*ent.File, err
|
||||
return q.Save(ctx)
|
||||
}
|
||||
|
||||
func (f *fileClient) UpdateProps(ctx context.Context, file *ent.File, props *types.FileProps) (*ent.File, error) {
|
||||
file, err := f.client.File.UpdateOne(file).
|
||||
SetProps(props).
|
||||
Save(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return file, nil
|
||||
}
|
||||
|
||||
func (f *fileClient) CountByTimeRange(ctx context.Context, start, end *time.Time) (int, error) {
|
||||
if start == nil || end == nil {
|
||||
return f.client.File.Query().Count(ctx)
|
||||
@@ -554,6 +567,10 @@ func (f *fileClient) Copy(ctx context.Context, files []*ent.File, dstMap map[int
|
||||
stm.SetPrimaryEntity(file.PrimaryEntity)
|
||||
}
|
||||
|
||||
if file.Props != nil && dstMap[file.FileChildren][0].OwnerID == file.OwnerID {
|
||||
stm.SetProps(file.Props)
|
||||
}
|
||||
|
||||
return stm
|
||||
})
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package inventory
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/cloudreve/Cloudreve/v4/inventory/types"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
@@ -62,6 +63,7 @@ type (
|
||||
Expires *time.Time
|
||||
OwnerID int
|
||||
FileID int
|
||||
Props *types.ShareProps
|
||||
}
|
||||
|
||||
ListShareArgs struct {
|
||||
@@ -122,6 +124,10 @@ func (c *shareClient) Upsert(ctx context.Context, params *CreateShareParams) (*e
|
||||
createQuery.ClearExpires()
|
||||
}
|
||||
|
||||
if params.Props != nil {
|
||||
createQuery.SetProps(params.Props)
|
||||
}
|
||||
|
||||
return createQuery.Save(ctx)
|
||||
}
|
||||
|
||||
@@ -138,6 +144,9 @@ func (c *shareClient) Upsert(ctx context.Context, params *CreateShareParams) (*e
|
||||
if params.Expires != nil {
|
||||
query.SetNillableExpires(params.Expires)
|
||||
}
|
||||
if params.Props != nil {
|
||||
query.SetProps(params.Props)
|
||||
}
|
||||
|
||||
return query.Save(ctx)
|
||||
}
|
||||
|
||||
@@ -7,13 +7,15 @@ import (
|
||||
// UserSetting 用户其他配置
|
||||
type (
|
||||
UserSetting struct {
|
||||
ProfileOff bool `json:"profile_off,omitempty"`
|
||||
PreferredTheme string `json:"preferred_theme,omitempty"`
|
||||
VersionRetention bool `json:"version_retention,omitempty"`
|
||||
VersionRetentionExt []string `json:"version_retention_ext,omitempty"`
|
||||
VersionRetentionMax int `json:"version_retention_max,omitempty"`
|
||||
Pined []PinedFile `json:"pined,omitempty"`
|
||||
Language string `json:"email_language,omitempty"`
|
||||
ProfileOff bool `json:"profile_off,omitempty"`
|
||||
PreferredTheme string `json:"preferred_theme,omitempty"`
|
||||
VersionRetention bool `json:"version_retention,omitempty"`
|
||||
VersionRetentionExt []string `json:"version_retention_ext,omitempty"`
|
||||
VersionRetentionMax int `json:"version_retention_max,omitempty"`
|
||||
Pined []PinedFile `json:"pined,omitempty"`
|
||||
Language string `json:"email_language,omitempty"`
|
||||
DisableViewSync bool `json:"disable_view_sync,omitempty"`
|
||||
FsViewMap map[string]ExplorerView `json:"fs_view_map,omitempty"`
|
||||
}
|
||||
|
||||
PinedFile struct {
|
||||
@@ -149,6 +151,32 @@ type (
|
||||
PolicyType string
|
||||
|
||||
FileProps struct {
|
||||
View *ExplorerView `json:"view,omitempty"`
|
||||
}
|
||||
|
||||
ExplorerView struct {
|
||||
PageSize int `json:"page_size" binding:"min=50"`
|
||||
Order string `json:"order,omitempty" binding:"max=255"`
|
||||
OrderDirection string `json:"order_direction,omitempty" binding:"eq=asc|eq=desc"`
|
||||
View string `json:"view,omitempty" binding:"eq=list|eq=grid|eq=gallery"`
|
||||
Thumbnail bool `json:"thumbnail,omitempty"`
|
||||
GalleryWidth int `json:"gallery_width,omitempty" binding:"min=50,max=500"`
|
||||
Columns []ListViewColumn `json:"columns,omitempty" binding:"max=1000"`
|
||||
}
|
||||
|
||||
ListViewColumn struct {
|
||||
Type int `json:"type" binding:"min=0"`
|
||||
Width *int `json:"width,omitempty"`
|
||||
Props *ColumTypeProps `json:"props,omitempty"`
|
||||
}
|
||||
|
||||
ColumTypeProps struct {
|
||||
MetadataKey string `json:"metadata_key,omitempty" binding:"max=255"`
|
||||
}
|
||||
|
||||
ShareProps struct {
|
||||
// Whether to share view setting from owner
|
||||
ShareView bool `json:"share_view,omitempty"`
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user