fix(123): can't delete folder (close #1009)

pull/1011/head
Xhofe 2022-04-28 21:17:11 +08:00
parent 43c6e07bac
commit d6775cda69
3 changed files with 22 additions and 21 deletions

View File

@ -3,7 +3,6 @@ package _23
import ( import (
"errors" "errors"
"fmt" "fmt"
"github.com/Xhofe/alist/conf"
"github.com/Xhofe/alist/drivers/base" "github.com/Xhofe/alist/drivers/base"
"github.com/Xhofe/alist/model" "github.com/Xhofe/alist/model"
"github.com/Xhofe/alist/utils" "github.com/Xhofe/alist/utils"
@ -40,7 +39,7 @@ func (driver Pan123) Login(account *model.Account) error {
return err return err
} }
func (driver Pan123) FormatFile(file *Pan123File) *model.File { func (driver Pan123) FormatFile(file *File) *model.File {
f := &model.File{ f := &model.File{
Id: strconv.FormatInt(file.FileId, 10), Id: strconv.FormatInt(file.FileId, 10),
Name: file.FileName, Name: file.FileName,
@ -52,9 +51,9 @@ func (driver Pan123) FormatFile(file *Pan123File) *model.File {
return f return f
} }
func (driver Pan123) GetFiles(parentId string, account *model.Account) ([]Pan123File, error) { func (driver Pan123) GetFiles(parentId string, account *model.Account) ([]File, error) {
next := "0" next := "0"
res := make([]Pan123File, 0) res := make([]File, 0)
for next != "-1" { for next != "-1" {
var resp Pan123Files var resp Pan123Files
query := map[string]string{ query := map[string]string{
@ -139,7 +138,7 @@ func (driver Pan123) Request(url string, method int, headers, query map[string]s
// return body, nil // return body, nil
//} //}
func (driver Pan123) GetFile(path string, account *model.Account) (*Pan123File, error) { func (driver Pan123) GetFile(path string, account *model.Account) (*File, error) {
dir, name := filepath.Split(path) dir, name := filepath.Split(path)
dir = utils.ParsePath(dir) dir = utils.ParsePath(dir)
_, err := driver.Files(dir, account) _, err := driver.Files(dir, account)
@ -147,14 +146,15 @@ func (driver Pan123) GetFile(path string, account *model.Account) (*Pan123File,
return nil, err return nil, err
} }
parentFiles_, _ := base.GetCache(dir, account) parentFiles_, _ := base.GetCache(dir, account)
parentFiles, _ := parentFiles_.([]Pan123File) parentFiles, _ := parentFiles_.([]File)
for _, file := range parentFiles { for _, file := range parentFiles {
if file.FileName == name { if file.FileName == name {
if file.Type != conf.FOLDER { //if file.Type != conf.FOLDER {
return &file, err // return &file, err
} else { //} else {
return nil, base.ErrNotFile // return nil, base.ErrNotFile
} //}
return &file, nil
} }
} }
return nil, base.ErrPathNotFound return nil, base.ErrPathNotFound

View File

@ -108,10 +108,10 @@ func (driver Pan123) File(path string, account *model.Account) (*model.File, err
func (driver Pan123) Files(path string, account *model.Account) ([]model.File, error) { func (driver Pan123) Files(path string, account *model.Account) ([]model.File, error) {
path = utils.ParsePath(path) path = utils.ParsePath(path)
var rawFiles []Pan123File var rawFiles []File
cache, err := base.GetCache(path, account) cache, err := base.GetCache(path, account)
if err == nil { if err == nil {
rawFiles, _ = cache.([]Pan123File) rawFiles, _ = cache.([]File)
} else { } else {
file, err := driver.File(path, account) file, err := driver.File(path, account)
if err != nil { if err != nil {
@ -278,12 +278,13 @@ func (driver Pan123) Delete(path string, account *model.Account) error {
if err != nil { if err != nil {
return err return err
} }
log.Debugln("delete 123 file: ", file)
data := base.Json{ data := base.Json{
"driveId": 0, "driveId": 0,
"operation": true, "operation": true,
"fileTrashInfoList": file, "fileTrashInfoList": []File{*file},
} }
_, err = driver.Request("https://www.123pan.com/api/file/trash", _, err = driver.Request("https://www.123pan.com/b/api/file/trash",
base.Post, nil, nil, &data, nil, false, account) base.Post, nil, nil, &data, nil, false, account)
return err return err
} }

View File

@ -7,7 +7,7 @@ import (
"time" "time"
) )
type Pan123File struct { type File struct {
FileName string `json:"FileName"` FileName string `json:"FileName"`
Size int64 `json:"Size"` Size int64 `json:"Size"`
UpdateAt *time.Time `json:"UpdateAt"` UpdateAt *time.Time `json:"UpdateAt"`
@ -17,15 +17,15 @@ type Pan123File struct {
S3KeyFlag string `json:"S3KeyFlag"` S3KeyFlag string `json:"S3KeyFlag"`
} }
func (f Pan123File) GetSize() uint64 { func (f File) GetSize() uint64 {
return uint64(f.Size) return uint64(f.Size)
} }
func (f Pan123File) GetName() string { func (f File) GetName() string {
return f.FileName return f.FileName
} }
func (f Pan123File) GetType() int { func (f File) GetType() int {
if f.Type == 1 { if f.Type == 1 {
return conf.FOLDER return conf.FOLDER
} }
@ -47,8 +47,8 @@ type Pan123TokenResp struct {
type Pan123Files struct { type Pan123Files struct {
BaseResp BaseResp
Data struct { Data struct {
InfoList []Pan123File `json:"InfoList"` InfoList []File `json:"InfoList"`
Next string `json:"Next"` Next string `json:"Next"`
} `json:"data"` } `json:"data"`
} }