mirror of
https://github.com/OpenListTeam/OpenList.git
synced 2026-10-10 04:53:09 +08:00
fix(fs): panic when failed to get storage details (#1964)
This commit is contained in:
@@ -331,11 +331,11 @@ func (d *Open115) GetDetails(ctx context.Context) (*model.StorageDetails, error)
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
total, err := userInfo.RtSpaceInfo.AllTotal.Size.Int64()
|
total, err := ParseInt64(userInfo.RtSpaceInfo.AllTotal.Size)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
used, err := userInfo.RtSpaceInfo.AllUse.Size.Int64()
|
used, err := ParseInt64(userInfo.RtSpaceInfo.AllUse.Size)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,15 @@
|
|||||||
package _115_open
|
package _115_open
|
||||||
|
|
||||||
// do others that not defined in Driver interface
|
import "encoding/json"
|
||||||
|
|
||||||
|
func ParseInt64(v json.Number) (int64, error) {
|
||||||
|
i, err := v.Int64()
|
||||||
|
if err == nil {
|
||||||
|
return i, nil
|
||||||
|
}
|
||||||
|
f, e1 := v.Float64()
|
||||||
|
if e1 == nil {
|
||||||
|
return int64(f), nil
|
||||||
|
}
|
||||||
|
return int64(0), err
|
||||||
|
}
|
||||||
|
|||||||
@@ -218,8 +218,8 @@ func (d *Alias) List(ctx context.Context, dir model.Obj, args model.ListArgs) ([
|
|||||||
}
|
}
|
||||||
if details, ok := model.GetStorageDetails(obj); ok {
|
if details, ok := model.GetStorageDetails(obj); ok {
|
||||||
objRet = &model.ObjStorageDetails{
|
objRet = &model.ObjStorageDetails{
|
||||||
Obj: objRet,
|
Obj: objRet,
|
||||||
StorageDetailsWithName: *details,
|
StorageDetails: details,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
objMap[name] = objRet
|
objMap[name] = objRet
|
||||||
|
|||||||
@@ -50,11 +50,8 @@ func (d *Alias) listRoot(ctx context.Context, withDetails, refresh bool) []model
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
objs[idx] = &model.ObjStorageDetails{
|
objs[idx] = &model.ObjStorageDetails{
|
||||||
Obj: objs[idx],
|
Obj: objs[idx],
|
||||||
StorageDetailsWithName: model.StorageDetailsWithName{
|
StorageDetails: nil,
|
||||||
StorageDetails: nil,
|
|
||||||
DriverName: remoteDriver.Config().Name,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
workerCount++
|
workerCount++
|
||||||
go func(dri driver.Driver, i int) {
|
go func(dri driver.Driver, i int) {
|
||||||
|
|||||||
@@ -79,29 +79,24 @@ type StorageDetails struct {
|
|||||||
DiskUsage
|
DiskUsage
|
||||||
}
|
}
|
||||||
|
|
||||||
type StorageDetailsWithName struct {
|
|
||||||
*StorageDetails
|
|
||||||
DriverName string `json:"driver_name"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ObjWithStorageDetails interface {
|
type ObjWithStorageDetails interface {
|
||||||
GetStorageDetails() *StorageDetailsWithName
|
GetStorageDetails() *StorageDetails
|
||||||
}
|
}
|
||||||
|
|
||||||
type ObjStorageDetails struct {
|
type ObjStorageDetails struct {
|
||||||
Obj
|
Obj
|
||||||
StorageDetailsWithName
|
*StorageDetails
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *ObjStorageDetails) Unwrap() Obj {
|
func (o *ObjStorageDetails) Unwrap() Obj {
|
||||||
return o.Obj
|
return o.Obj
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o ObjStorageDetails) GetStorageDetails() *StorageDetailsWithName {
|
func (o *ObjStorageDetails) GetStorageDetails() *StorageDetails {
|
||||||
return &o.StorageDetailsWithName
|
return o.StorageDetails
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetStorageDetails(obj Obj) (*StorageDetailsWithName, bool) {
|
func GetStorageDetails(obj Obj) (*StorageDetails, bool) {
|
||||||
if obj, ok := obj.(ObjWithStorageDetails); ok {
|
if obj, ok := obj.(ObjWithStorageDetails); ok {
|
||||||
return obj.GetStorageDetails(), true
|
return obj.GetStorageDetails(), true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -353,11 +353,8 @@ func GetStorageVirtualFilesWithDetailsByPath(ctx context.Context, prefix string,
|
|||||||
return obj
|
return obj
|
||||||
}
|
}
|
||||||
ret := &model.ObjStorageDetails{
|
ret := &model.ObjStorageDetails{
|
||||||
Obj: obj,
|
Obj: obj,
|
||||||
StorageDetailsWithName: model.StorageDetailsWithName{
|
StorageDetails: nil,
|
||||||
StorageDetails: nil,
|
|
||||||
DriverName: d.Config().Name,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
resultChan := make(chan *model.StorageDetails, 1)
|
resultChan := make(chan *model.StorageDetails, 1)
|
||||||
go func(dri driver.Driver) {
|
go func(dri driver.Driver) {
|
||||||
|
|||||||
+11
-11
@@ -33,17 +33,17 @@ type DirReq struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ObjResp struct {
|
type ObjResp struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Size int64 `json:"size"`
|
Size int64 `json:"size"`
|
||||||
IsDir bool `json:"is_dir"`
|
IsDir bool `json:"is_dir"`
|
||||||
Modified time.Time `json:"modified"`
|
Modified time.Time `json:"modified"`
|
||||||
Created time.Time `json:"created"`
|
Created time.Time `json:"created"`
|
||||||
Sign string `json:"sign"`
|
Sign string `json:"sign"`
|
||||||
Thumb string `json:"thumb"`
|
Thumb string `json:"thumb"`
|
||||||
Type int `json:"type"`
|
Type int `json:"type"`
|
||||||
HashInfoStr string `json:"hashinfo"`
|
HashInfoStr string `json:"hashinfo"`
|
||||||
HashInfo map[*utils.HashType]string `json:"hash_info"`
|
HashInfo map[*utils.HashType]string `json:"hash_info"`
|
||||||
MountDetails *model.StorageDetailsWithName `json:"mount_details,omitempty"`
|
MountDetails *model.StorageDetails `json:"mount_details,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type FsListResp struct {
|
type FsListResp struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user