diff --git a/drivers/123pan.go b/drivers/123pan.go index a3fa8426..eaac4a31 100644 --- a/drivers/123pan.go +++ b/drivers/123pan.go @@ -172,16 +172,16 @@ func (p Pan123) GetFiles(parentId string, account *model.Account) ([]Pan123File, return res, nil } -func (p Pan123) Path(path string, account *model.Account) (*model.File, []*model.File, error) { +func (p Pan123) Path(path string, account *model.Account) (*model.File, []model.File, error) { path = utils.ParsePath(path) log.Debugf("pan123 path: %s", path) cache, err := conf.Cache.Get(conf.Ctx, fmt.Sprintf("%s%s", account.Name, path)) if err == nil { files, _ := cache.([]Pan123File) if len(files) != 0 { - res := make([]*model.File, 0) + res := make([]model.File, 0) for _, file := range files { - res = append(res, p.FormatFile(&file)) + res = append(res, *p.FormatFile(&file)) } return nil, res, nil } @@ -226,9 +226,9 @@ func (p Pan123) Path(path string, account *model.Account) (*model.File, []*model } log.Debugf("%+v", files) _ = conf.Cache.Set(conf.Ctx, fmt.Sprintf("%s%s", account.Name, path), files, nil) - res := make([]*model.File, 0) + res := make([]model.File, 0) for _, file := range files { - res = append(res, p.FormatFile(&file)) + res = append(res, *p.FormatFile(&file)) } return nil, res, nil } diff --git a/drivers/189.go b/drivers/189.go index 88b34753..b7169ec4 100644 --- a/drivers/189.go +++ b/drivers/189.go @@ -113,16 +113,16 @@ func (c Cloud189) FormatFile(file *Cloud189File) *model.File { return f } -func (c Cloud189) Path(path string, account *model.Account) (*model.File, []*model.File, error) { +func (c Cloud189) Path(path string, account *model.Account) (*model.File, []model.File, error) { path = utils.ParsePath(path) log.Debugf("189 path: %s", path) cache, err := conf.Cache.Get(conf.Ctx, fmt.Sprintf("%s%s", account.Name, path)) if err == nil { files, _ := cache.([]Cloud189File) if len(files) != 0 { - res := make([]*model.File, 0) + res := make([]model.File, 0) for _, file := range files { - res = append(res, c.FormatFile(&file)) + res = append(res, *c.FormatFile(&file)) } return nil, res, nil } @@ -164,9 +164,9 @@ func (c Cloud189) Path(path string, account *model.Account) (*model.File, []*mod return nil, nil, err } _ = conf.Cache.Set(conf.Ctx, fmt.Sprintf("%s%s", account.Name, path), files, nil) - res := make([]*model.File, 0) + res := make([]model.File, 0) for _, file := range files { - res = append(res, c.FormatFile(&file)) + res = append(res, *c.FormatFile(&file)) } return nil, res, nil } diff --git a/drivers/alidrive.go b/drivers/alidrive.go index 72aba422..ddcbff8d 100644 --- a/drivers/alidrive.go +++ b/drivers/alidrive.go @@ -232,16 +232,16 @@ func (a AliDrive) GetFile(path string, account *model.Account) (*AliFile, error) } // path: /aaa/bbb -func (a AliDrive) Path(path string, account *model.Account) (*model.File, []*model.File, error) { +func (a AliDrive) Path(path string, account *model.Account) (*model.File, []model.File, error) { path = utils.ParsePath(path) log.Debugf("ali path: %s", path) cache, err := conf.Cache.Get(conf.Ctx, fmt.Sprintf("%s%s", account.Name, path)) if err == nil { files, _ := cache.([]AliFile) if len(files) != 0 { - res := make([]*model.File, 0) + res := make([]model.File, 0) for _, file := range files { - res = append(res, a.FormatFile(&file)) + res = append(res, *a.FormatFile(&file)) } return nil, res, nil } @@ -283,9 +283,9 @@ func (a AliDrive) Path(path string, account *model.Account) (*model.File, []*mod return nil, nil, err } _ = conf.Cache.Set(conf.Ctx, fmt.Sprintf("%s%s", account.Name, path), files, nil) - res := make([]*model.File, 0) + res := make([]model.File, 0) for _, file := range files { - res = append(res, a.FormatFile(&file)) + res = append(res, *a.FormatFile(&file)) } return nil, res, nil } diff --git a/drivers/driver.go b/drivers/driver.go index 99990a22..a3621b1e 100644 --- a/drivers/driver.go +++ b/drivers/driver.go @@ -10,7 +10,7 @@ import ( type Driver interface { Items() []Item Save(account *model.Account, old *model.Account) error - Path(path string, account *model.Account) (*model.File, []*model.File, error) + Path(path string, account *model.Account) (*model.File, []model.File, error) Link(path string, account *model.Account) (string, error) Proxy(c *gin.Context, account *model.Account) Preview(path string, account *model.Account) (interface{}, error) diff --git a/drivers/googledrive.go b/drivers/googledrive.go index a99b8f5c..7f2f9cbb 100644 --- a/drivers/googledrive.go +++ b/drivers/googledrive.go @@ -197,16 +197,16 @@ func (g GoogleDrive) GetFile(path string, account *model.Account) (*GoogleFile, return nil, fmt.Errorf("path not found") } -func (g GoogleDrive) Path(path string, account *model.Account) (*model.File, []*model.File, error) { +func (g GoogleDrive) Path(path string, account *model.Account) (*model.File, []model.File, error) { path = utils.ParsePath(path) log.Debugf("google path: %s", path) cache, err := conf.Cache.Get(conf.Ctx, fmt.Sprintf("%s%s", account.Name, path)) if err == nil { files, _ := cache.([]GoogleFile) if len(files) != 0 { - res := make([]*model.File, 0) + res := make([]model.File, 0) for _, file := range files { - res = append(res, g.FormatFile(&file)) + res = append(res, *g.FormatFile(&file)) } return nil, res, nil } @@ -243,9 +243,9 @@ func (g GoogleDrive) Path(path string, account *model.Account) (*model.File, []* return nil, nil, err } _ = conf.Cache.Set(conf.Ctx, fmt.Sprintf("%s%s", account.Name, path), files, nil) - res := make([]*model.File, 0) + res := make([]model.File, 0) for _, file := range files { - res = append(res, g.FormatFile(&file)) + res = append(res, *g.FormatFile(&file)) } return nil, res, nil } diff --git a/drivers/native.go b/drivers/native.go index 797b0458..a4633d52 100644 --- a/drivers/native.go +++ b/drivers/native.go @@ -52,14 +52,14 @@ func (n Native) Save(account *model.Account, old *model.Account) error { } // TODO sort files -func (n Native) Path(path string, account *model.Account) (*model.File, []*model.File, error) { +func (n Native) Path(path string, account *model.Account) (*model.File, []model.File, error) { fullPath := filepath.Join(account.RootFolder, path) log.Debugf("%s-%s-%s", account.RootFolder, path, fullPath) if !utils.Exists(fullPath) { return nil, nil, fmt.Errorf("path not found") } if utils.IsDir(fullPath) { - result := make([]*model.File, 0) + result := make([]model.File, 0) files, err := ioutil.ReadDir(fullPath) if err != nil { return nil, nil, err @@ -69,7 +69,7 @@ func (n Native) Path(path string, account *model.Account) (*model.File, []*model continue } time := f.ModTime() - file := &model.File{ + file := model.File{ Name: f.Name(), Size: f.Size(), Type: 0, diff --git a/drivers/onedrive.go b/drivers/onedrive.go index c7818bbd..b0b33213 100644 --- a/drivers/onedrive.go +++ b/drivers/onedrive.go @@ -262,11 +262,11 @@ func (o Onedrive) GetFile(account *model.Account, path string) (*OneFile, error) return &file, nil } -func (o Onedrive) Path(path string, account *model.Account) (*model.File, []*model.File, error) { +func (o Onedrive) Path(path string, account *model.Account) (*model.File, []model.File, error) { path = utils.ParsePath(path) cache, err := conf.Cache.Get(conf.Ctx, fmt.Sprintf("%s%s", account.Name, path)) if err == nil { - files, _ := cache.([]*model.File) + files, _ := cache.([]model.File) return nil, files, nil } file, err := o.GetFile(account, path) @@ -280,9 +280,9 @@ func (o Onedrive) Path(path string, account *model.Account) (*model.File, []*mod if err != nil { return nil, nil, err } - res := make([]*model.File, 0) + res := make([]model.File, 0) for _, file := range files { - res = append(res, o.FormatFile(&file)) + res = append(res, *o.FormatFile(&file)) } _ = conf.Cache.Set(conf.Ctx, fmt.Sprintf("%s%s", account.Name, path), res, nil) return nil, res, nil diff --git a/model/account.go b/model/account.go index efc35b9e..34b55826 100644 --- a/model/account.go +++ b/model/account.go @@ -99,14 +99,14 @@ func GetAccountById(id uint) (*Account, error) { return &account, nil } -func GetAccountFiles() ([]*File, error) { - files := make([]*File, 0) +func GetAccountFiles() ([]File, error) { + files := make([]File, 0) var accounts []Account if err := conf.DB.Order("`index`").Find(&accounts).Error; err != nil { return nil, err } for _, v := range accounts { - files = append(files, &File{ + files = append(files, File{ Name: v.Name, Size: 0, Type: conf.FOLDER, diff --git a/server/path.go b/server/path.go index b9283da1..e503ce3c 100644 --- a/server/path.go +++ b/server/path.go @@ -72,7 +72,7 @@ func Path(c *gin.Context) { }) } else { if meta != nil && meta.Hide != "" { - tmpFiles := make([]*model.File, 0) + tmpFiles := make([]model.File, 0) hideFiles := strings.Split(meta.Hide, ",") for _, item := range files { if !utils.IsContain(hideFiles, item.Name) {