change path interface

pull/548/head
微凉 2021-11-23 15:58:03 +08:00
parent e31402e94f
commit 163ee1159e
9 changed files with 32 additions and 32 deletions

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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)

View File

@ -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
}

View File

@ -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,

View File

@ -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

View File

@ -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,

View File

@ -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) {