Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 34 additions & 8 deletions drivers/wps/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,21 +382,47 @@ func (d *Wps) Put(ctx context.Context, dstDir model.Obj, file model.FileStreamer
}

func (d *Wps) GetDetails(ctx context.Context) (*model.StorageDetails, error) {
url := fmt.Sprintf("%s/api/v3/spaces", d.driveHost()+d.drivePrefix())
var resp spacesResp
if d.isPersonal() {
url := ENDPOINT_PERSONAL + "/api/v3/spaces"
var resp spacesResp
r, err := d.request(ctx).SetResult(&resp).SetError(&resp).Get(url)
if err != nil {
return nil, err
}
if r != nil && r.IsError() {
return nil, fmt.Errorf("http error: %d", r.StatusCode())
}
return &model.StorageDetails{
DiskUsage: model.DiskUsage{
TotalSpace: resp.Total,
UsedSpace: resp.Used,
},
}, nil
}
url := ENDPOINT_BUSINESS + "/3rd/plussvr/compose/v1/u/companies/batch/service-space?comp_ids=" + fmt.Sprint(d.login.CompanyID)
var resp serviceSpaceResp
r, err := d.request(ctx).SetResult(&resp).SetError(&resp).Get(url)
if err != nil {
return nil, err
}
if r != nil && r.IsError() {
return nil, fmt.Errorf("http error: %d", r.StatusCode())
}
return &model.StorageDetails{
DiskUsage: model.DiskUsage{
TotalSpace: resp.Total,
UsedSpace: resp.Used,
},
}, nil
if len(resp.Info) == 0 {
return nil, fmt.Errorf("empty service space info")
}
// info := resp.Info[0]
for _, info := range resp.Info {
if info.ID == d.login.CompanyID {
return &model.StorageDetails{
DiskUsage: model.DiskUsage{
TotalSpace: info.SpaceTotal,
UsedSpace: info.SpaceUsed,
},
}, nil
}
}
return nil, fmt.Errorf("service space info not found for company ID: %d", d.login.CompanyID)
}

var _ driver.Driver = (*Wps)(nil)
Expand Down
8 changes: 8 additions & 0 deletions drivers/wps/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,14 @@ type spacesResp struct {
} `json:"used_parts"`
}

type serviceSpaceResp struct {
Info []struct {
ID int64 `json:"id"`
SpaceTotal int64 `json:"space_total"`
SpaceUsed int64 `json:"space_used"`
} `json:"info"`
}

type uploadCreateUpdateResp struct {
apiResult
Method string `json:"method"`
Expand Down
26 changes: 15 additions & 11 deletions drivers/wps/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ func checkAPI(resp *resty.Response, result apiResult) error {
}

func (d *Wps) getGroups(ctx context.Context) ([]Group, error) {
if d.isPersonal() {
// different APIs
switch d.Mode {
case "Personal":
var resp personalGroupsResp
r, err := d.request(ctx).SetResult(&resp).SetError(&resp).Get(d.driveURL("/api/v3/groups"))
if err != nil {
Expand All @@ -169,17 +171,19 @@ func (d *Wps) getGroups(ctx context.Context) ([]Group, error) {
res = append(res, Group{GroupID: g.ID, Name: g.Name})
}
return res, nil
case "Business":
var resp groupsResp
url := fmt.Sprintf("%s/3rd/plus/groups/v1/companies/%d/users/self/groups/private", ENDPOINT_BUSINESS, d.login.CompanyID)
r, err := d.request(ctx).SetResult(&resp).SetError(&resp).Get(url)
if err != nil {
return nil, err
}
if r != nil && r.IsError() {
return nil, fmt.Errorf("http error: %d", r.StatusCode())
}
return resp.Groups, nil
}
var resp groupsResp
url := fmt.Sprintf("%s/3rd/plus/groups/v1/companies/%d/users/self/groups/private", ENDPOINT_BUSINESS, d.login.CompanyID)
r, err := d.request(ctx).SetResult(&resp).SetError(&resp).Get(url)
if err != nil {
return nil, err
}
if r != nil && r.IsError() {
return nil, fmt.Errorf("http error: %d", r.StatusCode())
}
return resp.Groups, nil
return nil, fmt.Errorf("unsupported mode: %s", d.Mode)
}

func (d *Wps) getFiles(ctx context.Context, groupID, parentID int64) ([]FileInfo, error) {
Expand Down
Loading