feat(explorer): save user's view setting to server / optionally share view setting via share link (#2232)
This commit is contained in:
@@ -120,8 +120,6 @@ func (s *GetDirectLinkService) Get(c *gin.Context) ([]DirectLinkResponse, error)
|
||||
return BuildDirectLinkResponse(res), err
|
||||
}
|
||||
|
||||
const defaultPageSize = 100
|
||||
|
||||
type (
|
||||
// ListFileParameterCtx define key fore ListFileService
|
||||
ListFileParameterCtx struct{}
|
||||
@@ -130,7 +128,7 @@ type (
|
||||
ListFileService struct {
|
||||
Uri string `uri:"uri" form:"uri" json:"uri" binding:"required"`
|
||||
Page int `uri:"page" form:"page" json:"page" binding:"min=0"`
|
||||
PageSize int `uri:"page_size" form:"page_size" json:"page_size" binding:"min=10"`
|
||||
PageSize int `uri:"page_size" form:"page_size" json:"page_size"`
|
||||
OrderBy string `uri:"order_by" form:"order_by" json:"order_by"`
|
||||
OrderDirection string `uri:"order_direction" form:"order_direction" json:"order_direction"`
|
||||
NextPageToken string `uri:"next_page_token" form:"next_page_token" json:"next_page_token"`
|
||||
@@ -150,10 +148,6 @@ func (service *ListFileService) List(c *gin.Context) (*ListResponse, error) {
|
||||
}
|
||||
|
||||
pageSize := service.PageSize
|
||||
if pageSize == 0 {
|
||||
pageSize = defaultPageSize
|
||||
}
|
||||
|
||||
streamed := false
|
||||
hasher := dep.HashIDEncoder()
|
||||
parent, res, err := m.List(c, uri, &manager.ListArgs{
|
||||
@@ -670,3 +664,29 @@ func RedirectDirectLink(c *gin.Context, name string) error {
|
||||
c.Header("Cache-Control", fmt.Sprintf("public, max-age=%d", int(earliestExpire.Sub(time.Now()).Seconds())))
|
||||
return nil
|
||||
}
|
||||
|
||||
type (
|
||||
PatchViewParameterCtx struct{}
|
||||
PatchViewService struct {
|
||||
Uri string `json:"uri" binding:"required"`
|
||||
View *types.ExplorerView `json:"view"`
|
||||
}
|
||||
)
|
||||
|
||||
func (s *PatchViewService) Patch(c *gin.Context) error {
|
||||
dep := dependency.FromContext(c)
|
||||
user := inventory.UserFromContext(c)
|
||||
m := manager.NewFileManager(dep, user)
|
||||
defer m.Recycle()
|
||||
|
||||
uri, err := fs.NewUriFromString(s.Uri)
|
||||
if err != nil {
|
||||
return serializer.NewError(serializer.CodeParamErr, "unknown uri", err)
|
||||
}
|
||||
|
||||
if err := m.PatchView(c, uri, s.View); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -207,11 +207,12 @@ type ListResponse struct {
|
||||
// It persists some intermedia state so that the following request don't need to query database again.
|
||||
// All the operations under this directory that supports context hint should carry this value in header
|
||||
// as X-Cr-Context-Hint.
|
||||
ContextHint *uuid.UUID `json:"context_hint"`
|
||||
RecursionLimitReached bool `json:"recursion_limit_reached,omitempty"`
|
||||
MixedType bool `json:"mixed_type"`
|
||||
SingleFileView bool `json:"single_file_view,omitempty"`
|
||||
StoragePolicy *StoragePolicy `json:"storage_policy,omitempty"`
|
||||
ContextHint *uuid.UUID `json:"context_hint"`
|
||||
RecursionLimitReached bool `json:"recursion_limit_reached,omitempty"`
|
||||
MixedType bool `json:"mixed_type"`
|
||||
SingleFileView bool `json:"single_file_view,omitempty"`
|
||||
StoragePolicy *StoragePolicy `json:"storage_policy,omitempty"`
|
||||
View *types.ExplorerView `json:"view,omitempty"`
|
||||
}
|
||||
|
||||
type FileResponse struct {
|
||||
@@ -233,10 +234,11 @@ type FileResponse struct {
|
||||
}
|
||||
|
||||
type ExtendedInfo struct {
|
||||
StoragePolicy *StoragePolicy `json:"storage_policy,omitempty"`
|
||||
StorageUsed int64 `json:"storage_used"`
|
||||
Shares []Share `json:"shares,omitempty"`
|
||||
Entities []Entity `json:"entities,omitempty"`
|
||||
StoragePolicy *StoragePolicy `json:"storage_policy,omitempty"`
|
||||
StorageUsed int64 `json:"storage_used"`
|
||||
Shares []Share `json:"shares,omitempty"`
|
||||
Entities []Entity `json:"entities,omitempty"`
|
||||
View *types.ExplorerView `json:"view,omitempty"`
|
||||
}
|
||||
|
||||
type StoragePolicy struct {
|
||||
@@ -274,6 +276,7 @@ type Share struct {
|
||||
// Only viewable by owner
|
||||
IsPrivate bool `json:"is_private,omitempty"`
|
||||
Password string `json:"password,omitempty"`
|
||||
ShareView bool `json:"share_view,omitempty"`
|
||||
|
||||
// Only viewable if explicitly unlocked by owner
|
||||
SourceUri string `json:"source_uri,omitempty"`
|
||||
@@ -306,6 +309,7 @@ func BuildShare(s *ent.Share, base *url.URL, hasher hashid.Encoder, requester *e
|
||||
|
||||
if requester.ID == owner.ID {
|
||||
res.IsPrivate = s.Password != ""
|
||||
res.ShareView = s.Props != nil && s.Props.ShareView
|
||||
}
|
||||
|
||||
return &res
|
||||
@@ -323,6 +327,7 @@ func BuildListResponse(ctx context.Context, u *ent.User, parent fs.File, res *fs
|
||||
MixedType: res.MixedType,
|
||||
SingleFileView: res.SingleFileView,
|
||||
StoragePolicy: BuildStoragePolicy(res.StoragePolicy, hasher),
|
||||
View: res.View,
|
||||
}
|
||||
|
||||
if !res.Parent.IsNil() {
|
||||
@@ -382,7 +387,7 @@ func BuildExtendedInfo(ctx context.Context, u *ent.User, f fs.File, hasher hashi
|
||||
ext.Shares = lo.Map(extendedInfo.Shares, func(s *ent.Share, index int) Share {
|
||||
return *BuildShare(s, base, hasher, u, u, f.DisplayName(), f.Type(), true, false)
|
||||
})
|
||||
|
||||
ext.View = extendedInfo.View
|
||||
}
|
||||
|
||||
return ext
|
||||
|
||||
Reference in New Issue
Block a user