Skip to content

Commit

Permalink
feat(cloudreve): folder size count and switch (#5457 close #5395)
Browse files Browse the repository at this point in the history
  • Loading branch information
itsHenry35 authored Nov 4, 2023
1 parent a632596 commit 65c5ec0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
8 changes: 8 additions & 0 deletions drivers/cloudreve/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ func (d *Cloudreve) List(ctx context.Context, dir model.Obj, args model.ListArgs
if err != nil {
return nil, err
}
if src.Type == "dir" && d.EnableThumbAndFolderSize {
var dprop DirectoryProp
err = d.request(http.MethodGet, "/object/property/"+src.Id+"?is_folder=true", nil, &dprop)
if err != nil {
return nil, err
}
src.Size = dprop.Size
}
return objectToObj(src, thumb), nil
})
}
Expand Down
11 changes: 6 additions & 5 deletions drivers/cloudreve/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ type Addition struct {
// Usually one of two
driver.RootPath
// define other
Address string `json:"address" required:"true"`
Username string `json:"username"`
Password string `json:"password"`
Cookie string `json:"cookie"`
CustomUA string `json:"custom_ua"`
Address string `json:"address" required:"true"`
Username string `json:"username"`
Password string `json:"password"`
Cookie string `json:"cookie"`
CustomUA string `json:"custom_ua"`
EnableThumbAndFolderSize bool `json:"enable_thumb_and_folder_size"`
}

var config = driver.Config{
Expand Down
4 changes: 4 additions & 0 deletions drivers/cloudreve/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ type Object struct {
SourceEnabled bool `json:"source_enabled"`
}

type DirectoryProp struct {
Size int `json:"size"`
}

func objectToObj(f Object, t model.Thumbnail) *model.ObjThumb {
return &model.ObjThumb{
Object: model.Object{
Expand Down
3 changes: 3 additions & 0 deletions drivers/cloudreve/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ func convertSrc(obj model.Obj) map[string]interface{} {
}

func (d *Cloudreve) GetThumb(file Object) (model.Thumbnail, error) {
if !d.Addition.EnableThumbAndFolderSize {
return model.Thumbnail{}, nil
}
ua := d.CustomUA
if ua == "" {
ua = base.UserAgent
Expand Down

0 comments on commit 65c5ec0

Please sign in to comment.