Skip to content

Commit 795a18b

Browse files
authored
feat(drivers/thunder*): implement GetDetails (#2113)
Signed-off-by: MadDogOwner <xiaoran@xrgzs.top>
1 parent 82ae2d5 commit 795a18b

File tree

6 files changed

+110
-0
lines changed

6 files changed

+110
-0
lines changed

drivers/thunder/driver.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,32 @@ func (xc *XunLeiCommon) Put(ctx context.Context, dstDir model.Obj, file model.Fi
433433
return nil
434434
}
435435

436+
func (xc *XunLeiCommon) GetDetails(ctx context.Context) (*model.StorageDetails, error) {
437+
var about AboutResponse
438+
_, err := xc.Request(API_URL+"/about", http.MethodGet, func(r *resty.Request) {
439+
r.SetContext(ctx)
440+
}, &about)
441+
if err != nil {
442+
return nil, err
443+
}
444+
445+
total, err := strconv.ParseInt(about.Quota.Limit, 10, 64)
446+
if err != nil {
447+
return nil, err
448+
}
449+
used, err := strconv.ParseInt(about.Quota.Usage, 10, 64)
450+
if err != nil {
451+
return nil, err
452+
}
453+
454+
return &model.StorageDetails{
455+
DiskUsage: model.DiskUsage{
456+
TotalSpace: total,
457+
UsedSpace: used,
458+
},
459+
}, nil
460+
}
461+
436462
func (xc *XunLeiCommon) getFiles(ctx context.Context, folderId string) ([]model.Obj, error) {
437463
files := make([]model.Obj, 0)
438464
var pageToken string

drivers/thunder/types.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,3 +347,21 @@ type ReviewData struct {
347347
Deviceid string `json:"deviceid"`
348348
Devicesign string `json:"devicesign"`
349349
}
350+
351+
type AboutResponse struct {
352+
// Kind string `json:"kind"`
353+
Quota struct {
354+
// Kind string `json:"kind"`
355+
Limit string `json:"limit"`
356+
Usage string `json:"usage"`
357+
// UsageInTrash string `json:"usage_in_trash"`
358+
// PlayTimesLimit string `json:"play_times_limit"`
359+
// PlayTimesUsage string `json:"play_times_usage"`
360+
// IsUnlimited bool `json:"is_unlimited"`
361+
// UpgradeType string `json:"upgrade_type"`
362+
} `json:"quota"`
363+
// ExpiresAt string `json:"expires_at"`
364+
// Quotas struct {
365+
// } `json:"quotas"`
366+
// IsSearchFlushed bool `json:"is_search_flushed"`
367+
}

drivers/thunder_browser/driver.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,32 @@ func (xc *XunLeiBrowserCommon) Put(ctx context.Context, dstDir model.Obj, stream
543543
return nil
544544
}
545545

546+
func (xc *XunLeiBrowserCommon) GetDetails(ctx context.Context) (*model.StorageDetails, error) {
547+
var about AboutResponse
548+
_, err := xc.Request(API_URL+"/about", http.MethodGet, func(r *resty.Request) {
549+
r.SetContext(ctx)
550+
}, &about)
551+
if err != nil {
552+
return nil, err
553+
}
554+
555+
total, err := strconv.ParseInt(about.Quota.Limit, 10, 64)
556+
if err != nil {
557+
return nil, err
558+
}
559+
used, err := strconv.ParseInt(about.Quota.Usage, 10, 64)
560+
if err != nil {
561+
return nil, err
562+
}
563+
564+
return &model.StorageDetails{
565+
DiskUsage: model.DiskUsage{
566+
TotalSpace: total,
567+
UsedSpace: used,
568+
},
569+
}, nil
570+
}
571+
546572
func (xc *XunLeiBrowserCommon) getFiles(ctx context.Context, dir model.Obj, path string) ([]model.Obj, error) {
547573
files := make([]model.Obj, 0)
548574
var pageToken string

drivers/thunder_browser/types.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,3 +376,10 @@ type ReviewData struct {
376376
Deviceid string `json:"deviceid"`
377377
Devicesign string `json:"devicesign"`
378378
}
379+
380+
type AboutResponse struct {
381+
Quota struct {
382+
Limit string `json:"limit"`
383+
Usage string `json:"usage"`
384+
} `json:"quota"`
385+
}

drivers/thunderx/driver.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,32 @@ func (xc *XunLeiXCommon) Put(ctx context.Context, dstDir model.Obj, file model.F
423423
return nil
424424
}
425425

426+
func (xc *XunLeiXCommon) GetDetails(ctx context.Context) (*model.StorageDetails, error) {
427+
var about AboutResponse
428+
_, err := xc.Request(API_URL+"/about", http.MethodGet, func(r *resty.Request) {
429+
r.SetContext(ctx)
430+
}, &about)
431+
if err != nil {
432+
return nil, err
433+
}
434+
435+
total, err := strconv.ParseInt(about.Quota.Limit, 10, 64)
436+
if err != nil {
437+
return nil, err
438+
}
439+
used, err := strconv.ParseInt(about.Quota.Usage, 10, 64)
440+
if err != nil {
441+
return nil, err
442+
}
443+
444+
return &model.StorageDetails{
445+
DiskUsage: model.DiskUsage{
446+
TotalSpace: total,
447+
UsedSpace: used,
448+
},
449+
}, nil
450+
}
451+
426452
func (xc *XunLeiXCommon) getFiles(ctx context.Context, folderId string) ([]model.Obj, error) {
427453
files := make([]model.Obj, 0)
428454
var pageToken string

drivers/thunderx/types.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,3 +303,10 @@ type Media struct {
303303
IsVisible bool `json:"is_visible"`
304304
Category string `json:"category"`
305305
}
306+
307+
type AboutResponse struct {
308+
Quota struct {
309+
Limit string `json:"limit"`
310+
Usage string `json:"usage"`
311+
} `json:"quota"`
312+
}

0 commit comments

Comments
 (0)