Skip to content

Commit 29fcf59

Browse files
authored
fix(drivers/cloudreve_v4): add IsFolder attribute to Getter response (OpenListTeam#2035)
* fix(drivers/cloudreve_v4): add IsFolder attribute to Getter response Signed-off-by: MadDogOwner <xiaoran@xrgzs.top> * refactor(drivers/cloudreve_v4): implement File.fileToObject method Signed-off-by: MadDogOwner <xiaoran@xrgzs.top> * fix(drivers/cloudreve_v4): implement 404 not found for getter Signed-off-by: MadDogOwner <xiaoran@xrgzs.top> --------- Signed-off-by: MadDogOwner <xiaoran@xrgzs.top>
1 parent f0e53d1 commit 29fcf59

File tree

3 files changed

+19
-17
lines changed

3 files changed

+19
-17
lines changed

drivers/cloudreve_v4/driver.go

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,7 @@ func (d *CloudreveV4) List(ctx context.Context, dir model.Obj, args model.ListAr
129129
}
130130
}
131131
return &model.ObjThumb{
132-
Object: model.Object{
133-
ID: src.ID,
134-
Path: src.Path,
135-
Name: src.Name,
136-
Size: src.Size,
137-
Modified: src.UpdatedAt,
138-
Ctime: src.CreatedAt,
139-
IsFolder: src.Type == 1,
140-
},
132+
Object: *fileToObject(&src),
141133
Thumbnail: thumb,
142134
}, nil
143135
})
@@ -151,14 +143,7 @@ func (d *CloudreveV4) Get(ctx context.Context, path string) (model.Obj, error) {
151143
if err != nil {
152144
return nil, err
153145
}
154-
return &model.Object{
155-
ID: info.ID,
156-
Path: info.Path,
157-
Name: info.Name,
158-
Size: info.Size,
159-
Modified: info.UpdatedAt,
160-
Ctime: info.CreatedAt,
161-
}, nil
146+
return fileToObject(&info), nil
162147
}
163148

164149
func (d *CloudreveV4) Link(ctx context.Context, file model.Obj, args model.LinkArgs) (*model.Link, error) {

drivers/cloudreve_v4/types.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,18 @@ type File struct {
122122
PrimaryEntity string `json:"primary_entity"`
123123
}
124124

125+
func fileToObject(f *File) *model.Object {
126+
return &model.Object{
127+
ID: f.ID,
128+
Path: f.Path,
129+
Name: f.Name,
130+
Size: f.Size,
131+
Modified: f.UpdatedAt,
132+
Ctime: f.CreatedAt,
133+
IsFolder: f.Type == 1,
134+
}
135+
}
136+
125137
type StoragePolicy struct {
126138
ID string `json:"id"`
127139
Name string `json:"name"`

drivers/cloudreve_v4/util.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/OpenListTeam/OpenList/v4/drivers/base"
1717
"github.com/OpenListTeam/OpenList/v4/internal/conf"
1818
"github.com/OpenListTeam/OpenList/v4/internal/driver"
19+
"github.com/OpenListTeam/OpenList/v4/internal/errs"
1920
"github.com/OpenListTeam/OpenList/v4/internal/model"
2021
"github.com/OpenListTeam/OpenList/v4/internal/op"
2122
"github.com/OpenListTeam/OpenList/v4/internal/setting"
@@ -30,6 +31,7 @@ import (
3031

3132
const (
3233
CodeLoginRequired = http.StatusUnauthorized
34+
CodePathNotExist = 40016 // Path not exist
3335
CodeCredentialInvalid = 40020 // Failed to issue token
3436
)
3537

@@ -101,6 +103,9 @@ func (d *CloudreveV4) _request(method string, path string, callback base.ReqCall
101103
if r.Code == CodeCredentialInvalid {
102104
return ErrorIssueToken
103105
}
106+
if r.Code == CodePathNotExist {
107+
return errs.ObjectNotFound
108+
}
104109
return fmt.Errorf("%d: %s", r.Code, r.Msg)
105110
}
106111

0 commit comments

Comments
 (0)