🎨 Optimize code structure
This commit is contained in:
parent
e7ba289d06
commit
7cf30836bf
@ -218,33 +218,17 @@ func (driver Pan123) MakeDir(path string, account *model.Account) error {
|
|||||||
}
|
}
|
||||||
_, err = driver.Request("https://www.123pan.com/api/file/upload_request",
|
_, err = driver.Request("https://www.123pan.com/api/file/upload_request",
|
||||||
base.Post, nil, nil, &data, nil, false, account)
|
base.Post, nil, nil, &data, nil, false, account)
|
||||||
//_, err = driver.Post("https://www.123pan.com/api/file/upload_request", data, account)
|
|
||||||
if err == nil {
|
|
||||||
_ = base.DeleteCache(dir, account)
|
|
||||||
}
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (driver Pan123) Move(src string, dst string, account *model.Account) error {
|
func (driver Pan123) Move(src string, dst string, account *model.Account) error {
|
||||||
srcDir, _ := filepath.Split(src)
|
dstDir, _ := filepath.Split(dst)
|
||||||
dstDir, dstName := filepath.Split(dst)
|
|
||||||
srcFile, err := driver.File(src, account)
|
srcFile, err := driver.File(src, account)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fileId, _ := strconv.Atoi(srcFile.Id)
|
fileId, _ := strconv.Atoi(srcFile.Id)
|
||||||
// rename
|
|
||||||
if srcDir == dstDir {
|
|
||||||
data := base.Json{
|
|
||||||
"driveId": 0,
|
|
||||||
"fileId": fileId,
|
|
||||||
"fileName": dstName,
|
|
||||||
}
|
|
||||||
_, err = driver.Request("https://www.123pan.com/api/file/rename",
|
|
||||||
base.Post, nil, nil, &data, nil, false, account)
|
|
||||||
//_, err = driver.Post("https://www.123pan.com/api/file/rename", data, account)
|
|
||||||
} else {
|
|
||||||
// move
|
|
||||||
dstDirFile, err := driver.File(dstDir, account)
|
dstDirFile, err := driver.File(dstDir, account)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -256,12 +240,24 @@ func (driver Pan123) Move(src string, dst string, account *model.Account) error
|
|||||||
}
|
}
|
||||||
_, err = driver.Request("https://www.123pan.com/api/file/mod_pid",
|
_, err = driver.Request("https://www.123pan.com/api/file/mod_pid",
|
||||||
base.Post, nil, nil, &data, nil, false, account)
|
base.Post, nil, nil, &data, nil, false, account)
|
||||||
//_, err = driver.Post("https://www.123pan.com/api/file/mod_pid", data, account)
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (driver Pan123) Rename(src string, dst string, account *model.Account) error {
|
||||||
|
_, dstName := filepath.Split(dst)
|
||||||
|
srcFile, err := driver.File(src, account)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
_ = base.DeleteCache(srcDir, account)
|
return err
|
||||||
_ = base.DeleteCache(dstDir, account)
|
|
||||||
}
|
}
|
||||||
|
fileId, _ := strconv.Atoi(srcFile.Id)
|
||||||
|
|
||||||
|
data := base.Json{
|
||||||
|
"driveId": 0,
|
||||||
|
"fileId": fileId,
|
||||||
|
"fileName": dstName,
|
||||||
|
}
|
||||||
|
_, err = driver.Request("https://www.123pan.com/api/file/rename",
|
||||||
|
base.Post, nil, nil, &data, nil, false, account)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -281,10 +277,6 @@ func (driver Pan123) Delete(path string, account *model.Account) error {
|
|||||||
}
|
}
|
||||||
_, err = driver.Request("https://www.123pan.com/api/file/trash",
|
_, err = driver.Request("https://www.123pan.com/api/file/trash",
|
||||||
base.Post, nil, nil, &data, nil, false, account)
|
base.Post, nil, nil, &data, nil, false, account)
|
||||||
//_, err = driver.Post("https://www.123pan.com/api/file/trash", data, account)
|
|
||||||
if err == nil {
|
|
||||||
_ = base.DeleteCache(utils.Dir(path), account)
|
|
||||||
}
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -224,36 +224,16 @@ func (driver Cloud189) MakeDir(path string, account *model.Account) error {
|
|||||||
"folderName": name,
|
"folderName": name,
|
||||||
}
|
}
|
||||||
_, err = driver.Request("https://cloud.189.cn/api/open/file/createFolder.action", "POST", form, nil, account)
|
_, err = driver.Request("https://cloud.189.cn/api/open/file/createFolder.action", "POST", form, nil, account)
|
||||||
if err == nil {
|
|
||||||
_ = base.DeleteCache(dir, account)
|
|
||||||
}
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (driver Cloud189) Move(src string, dst string, account *model.Account) error {
|
func (driver Cloud189) Move(src string, dst string, account *model.Account) error {
|
||||||
srcDir, _ := filepath.Split(src)
|
|
||||||
dstDir, dstName := filepath.Split(dst)
|
dstDir, dstName := filepath.Split(dst)
|
||||||
srcFile, err := driver.File(src, account)
|
srcFile, err := driver.File(src, account)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// rename
|
|
||||||
if srcDir == dstDir {
|
|
||||||
url := "https://cloud.189.cn/api/open/file/renameFile.action"
|
|
||||||
idKey := "fileId"
|
|
||||||
nameKey := "destFileName"
|
|
||||||
if srcFile.IsDir() {
|
|
||||||
url = "https://cloud.189.cn/api/open/file/renameFolder.action"
|
|
||||||
idKey = "folderId"
|
|
||||||
nameKey = "destFolderName"
|
|
||||||
}
|
|
||||||
form := map[string]string{
|
|
||||||
idKey: srcFile.Id,
|
|
||||||
nameKey: dstName,
|
|
||||||
}
|
|
||||||
_, err = driver.Request(url, "POST", form, nil, account)
|
|
||||||
} else {
|
|
||||||
// move
|
|
||||||
dstDirFile, err := driver.File(dstDir, account)
|
dstDirFile, err := driver.File(dstDir, account)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -279,11 +259,28 @@ func (driver Cloud189) Move(src string, dst string, account *model.Account) erro
|
|||||||
"taskInfos": string(taskInfosBytes),
|
"taskInfos": string(taskInfosBytes),
|
||||||
}
|
}
|
||||||
_, err = driver.Request("https://cloud.189.cn/api/open/batch/createBatchTask.action", "POST", form, nil, account)
|
_, err = driver.Request("https://cloud.189.cn/api/open/batch/createBatchTask.action", "POST", form, nil, account)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (driver Cloud189) Rename(src string, dst string, account *model.Account) error {
|
||||||
|
_, dstName := filepath.Split(dst)
|
||||||
|
srcFile, err := driver.File(src, account)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
if err == nil {
|
url := "https://cloud.189.cn/api/open/file/renameFile.action"
|
||||||
_ = base.DeleteCache(srcDir, account)
|
idKey := "fileId"
|
||||||
_ = base.DeleteCache(dstDir, account)
|
nameKey := "destFileName"
|
||||||
|
if srcFile.IsDir() {
|
||||||
|
url = "https://cloud.189.cn/api/open/file/renameFolder.action"
|
||||||
|
idKey = "folderId"
|
||||||
|
nameKey = "destFolderName"
|
||||||
}
|
}
|
||||||
|
form := map[string]string{
|
||||||
|
idKey: srcFile.Id,
|
||||||
|
nameKey: dstName,
|
||||||
|
}
|
||||||
|
_, err = driver.Request(url, "POST", form, nil, account)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -318,9 +315,6 @@ func (driver Cloud189) Copy(src string, dst string, account *model.Account) erro
|
|||||||
"taskInfos": string(taskInfosBytes),
|
"taskInfos": string(taskInfosBytes),
|
||||||
}
|
}
|
||||||
_, err = driver.Request("https://cloud.189.cn/api/open/batch/createBatchTask.action", "POST", form, nil, account)
|
_, err = driver.Request("https://cloud.189.cn/api/open/batch/createBatchTask.action", "POST", form, nil, account)
|
||||||
if err == nil {
|
|
||||||
_ = base.DeleteCache(dstDir, account)
|
|
||||||
}
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -351,9 +345,6 @@ func (driver Cloud189) Delete(path string, account *model.Account) error {
|
|||||||
"taskInfos": string(taskInfosBytes),
|
"taskInfos": string(taskInfosBytes),
|
||||||
}
|
}
|
||||||
_, err = driver.Request("https://cloud.189.cn/api/open/batch/createBatchTask.action", "POST", form, nil, account)
|
_, err = driver.Request("https://cloud.189.cn/api/open/batch/createBatchTask.action", "POST", form, nil, account)
|
||||||
if err == nil {
|
|
||||||
_ = base.DeleteCache(utils.Dir(path), account)
|
|
||||||
}
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,7 +158,7 @@ func (driver AliDrive) RefreshToken(account *model.Account) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (driver AliDrive) Rename(fileId, name string, account *model.Account) error {
|
func (driver AliDrive) rename(fileId, name string, account *model.Account) error {
|
||||||
var resp base.Json
|
var resp base.Json
|
||||||
var e AliRespError
|
var e AliRespError
|
||||||
_, err := aliClient.R().SetResult(&resp).SetError(&e).
|
_, err := aliClient.R().SetResult(&resp).SetError(&e).
|
||||||
@ -179,7 +179,7 @@ func (driver AliDrive) Rename(fileId, name string, account *model.Account) error
|
|||||||
return err
|
return err
|
||||||
} else {
|
} else {
|
||||||
_ = model.SaveAccount(account)
|
_ = model.SaveAccount(account)
|
||||||
return driver.Rename(fileId, name, account)
|
return driver.rename(fileId, name, account)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return fmt.Errorf("%s", e.Message)
|
return fmt.Errorf("%s", e.Message)
|
||||||
@ -190,7 +190,7 @@ func (driver AliDrive) Rename(fileId, name string, account *model.Account) error
|
|||||||
return fmt.Errorf("%+v", resp)
|
return fmt.Errorf("%+v", resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (driver AliDrive) Batch(srcId,dstId string, account *model.Account) error {
|
func (driver AliDrive) batch(srcId, dstId string, account *model.Account) error {
|
||||||
var e AliRespError
|
var e AliRespError
|
||||||
res, err := aliClient.R().SetError(&e).
|
res, err := aliClient.R().SetError(&e).
|
||||||
SetHeader("authorization", "Bearer\t"+account.AccessToken).
|
SetHeader("authorization", "Bearer\t"+account.AccessToken).
|
||||||
@ -200,13 +200,13 @@ func (driver AliDrive) Batch(srcId,dstId string, account *model.Account) error {
|
|||||||
"headers": base.Json{
|
"headers": base.Json{
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
"method":"POST",
|
"method": "POST",
|
||||||
"id":srcId,
|
"id": srcId,
|
||||||
"body":base.Json{
|
"body": base.Json{
|
||||||
"drive_id": account.DriveId,
|
"drive_id": account.DriveId,
|
||||||
"file_id":srcId,
|
"file_id": srcId,
|
||||||
"to_drive_id":account.DriveId,
|
"to_drive_id": account.DriveId,
|
||||||
"to_parent_file_id":dstId,
|
"to_parent_file_id": dstId,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -222,7 +222,7 @@ func (driver AliDrive) Batch(srcId,dstId string, account *model.Account) error {
|
|||||||
return err
|
return err
|
||||||
} else {
|
} else {
|
||||||
_ = model.SaveAccount(account)
|
_ = model.SaveAccount(account)
|
||||||
return driver.Batch(srcId, dstId, account)
|
return driver.batch(srcId, dstId, account)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return fmt.Errorf("%s", e.Message)
|
return fmt.Errorf("%s", e.Message)
|
||||||
|
@ -286,34 +286,32 @@ func (driver AliDrive) MakeDir(path string, account *model.Account) error {
|
|||||||
return fmt.Errorf("%s", e.Message)
|
return fmt.Errorf("%s", e.Message)
|
||||||
}
|
}
|
||||||
if resp["file_name"] == name {
|
if resp["file_name"] == name {
|
||||||
_ = base.DeleteCache(dir, account)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return fmt.Errorf("%+v", resp)
|
return fmt.Errorf("%+v", resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (driver AliDrive) Move(src string, dst string, account *model.Account) error {
|
func (driver AliDrive) Move(src string, dst string, account *model.Account) error {
|
||||||
srcDir, _ := filepath.Split(src)
|
dstDir, _ := filepath.Split(dst)
|
||||||
dstDir, dstName := filepath.Split(dst)
|
|
||||||
srcFile, err := driver.File(src, account)
|
srcFile, err := driver.File(src, account)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// rename
|
|
||||||
if srcDir == dstDir {
|
|
||||||
err = driver.Rename(srcFile.Id, dstName, account)
|
|
||||||
} else {
|
|
||||||
// move
|
|
||||||
dstDirFile, err := driver.File(dstDir, account)
|
dstDirFile, err := driver.File(dstDir, account)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
err = driver.Batch(srcFile.Id, dstDirFile.Id, account)
|
err = driver.batch(srcFile.Id, dstDirFile.Id, account)
|
||||||
}
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (driver AliDrive) Rename(src string, dst string, account *model.Account) error {
|
||||||
|
_, dstName := filepath.Split(dst)
|
||||||
|
srcFile, err := driver.File(src, account)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
_ = base.DeleteCache(srcDir, account)
|
return err
|
||||||
_ = base.DeleteCache(dstDir, account)
|
|
||||||
}
|
}
|
||||||
|
err = driver.rename(srcFile.Id, dstName, account)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -349,7 +347,6 @@ func (driver AliDrive) Delete(path string, account *model.Account) error {
|
|||||||
return fmt.Errorf("%s", e.Message)
|
return fmt.Errorf("%s", e.Message)
|
||||||
}
|
}
|
||||||
if res.StatusCode() == 204 {
|
if res.StatusCode() == 204 {
|
||||||
_ = base.DeleteCache(utils.Dir(path), account)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return errors.New(res.String())
|
return errors.New(res.String())
|
||||||
@ -471,7 +468,6 @@ func (driver AliDrive) Upload(file *model.FileStream, account *model.Account) er
|
|||||||
return fmt.Errorf("%s", e.Message)
|
return fmt.Errorf("%s", e.Message)
|
||||||
}
|
}
|
||||||
if resp2["file_id"] == resp.FileId {
|
if resp2["file_id"] == resp.FileId {
|
||||||
_ = base.DeleteCache(file.ParentPath, account)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return fmt.Errorf("%+v", resp2)
|
return fmt.Errorf("%+v", resp2)
|
||||||
|
@ -171,6 +171,10 @@ func (driver Alist) Move(src string, dst string, account *model.Account) error {
|
|||||||
return base.ErrNotImplement
|
return base.ErrNotImplement
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (driver Alist) Rename(src string, dst string, account *model.Account) error {
|
||||||
|
return base.ErrNotImplement
|
||||||
|
}
|
||||||
|
|
||||||
func (driver Alist) Copy(src string, dst string, account *model.Account) error {
|
func (driver Alist) Copy(src string, dst string, account *model.Account) error {
|
||||||
return base.ErrNotImplement
|
return base.ErrNotImplement
|
||||||
}
|
}
|
||||||
|
@ -46,6 +46,8 @@ type Driver interface {
|
|||||||
MakeDir(path string, account *model.Account) error
|
MakeDir(path string, account *model.Account) error
|
||||||
// Move 移动/改名
|
// Move 移动/改名
|
||||||
Move(src string, dst string, account *model.Account) error
|
Move(src string, dst string, account *model.Account) error
|
||||||
|
// Rename 改名
|
||||||
|
Rename(src string, dst string, account *model.Account) error
|
||||||
// Copy 拷贝
|
// Copy 拷贝
|
||||||
Copy(src string, dst string, account *model.Account) error
|
Copy(src string, dst string, account *model.Account) error
|
||||||
// Delete 删除
|
// Delete 删除
|
||||||
|
@ -193,16 +193,10 @@ func (driver FTP) MakeDir(path string, account *model.Account) error {
|
|||||||
}
|
}
|
||||||
defer func() { _ = conn.Quit() }()
|
defer func() { _ = conn.Quit() }()
|
||||||
err = conn.MakeDir(realPath)
|
err = conn.MakeDir(realPath)
|
||||||
if err == nil {
|
|
||||||
_ = base.DeleteCache(utils.Dir(path), account)
|
|
||||||
}
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (driver FTP) Move(src string, dst string, account *model.Account) error {
|
func (driver FTP) Move(src string, dst string, account *model.Account) error {
|
||||||
//if utils.Dir(src) != utils.Dir(dst) {
|
|
||||||
// return base.ErrNotSupport
|
|
||||||
//}
|
|
||||||
realSrc := utils.Join(account.RootFolder, src)
|
realSrc := utils.Join(account.RootFolder, src)
|
||||||
realDst := utils.Join(account.RootFolder, dst)
|
realDst := utils.Join(account.RootFolder, dst)
|
||||||
conn, err := driver.Login(account)
|
conn, err := driver.Login(account)
|
||||||
@ -211,15 +205,13 @@ func (driver FTP) Move(src string, dst string, account *model.Account) error {
|
|||||||
}
|
}
|
||||||
defer func() { _ = conn.Quit() }()
|
defer func() { _ = conn.Quit() }()
|
||||||
err = conn.Rename(realSrc, realDst)
|
err = conn.Rename(realSrc, realDst)
|
||||||
if err != nil {
|
|
||||||
_ = base.DeleteCache(utils.Dir(src), account)
|
|
||||||
if utils.Dir(src) != utils.Dir(dst) {
|
|
||||||
_ = base.DeleteCache(utils.Dir(dst), account)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (driver FTP) Rename(src string, dst string, account *model.Account) error {
|
||||||
|
return driver.Move(src, dst, account)
|
||||||
|
}
|
||||||
|
|
||||||
func (driver FTP) Copy(src string, dst string, account *model.Account) error {
|
func (driver FTP) Copy(src string, dst string, account *model.Account) error {
|
||||||
return base.ErrNotSupport
|
return base.ErrNotSupport
|
||||||
}
|
}
|
||||||
@ -233,9 +225,6 @@ func (driver FTP) Delete(path string, account *model.Account) error {
|
|||||||
}
|
}
|
||||||
defer func() { _ = conn.Quit() }()
|
defer func() { _ = conn.Quit() }()
|
||||||
err = conn.Delete(realPath)
|
err = conn.Delete(realPath)
|
||||||
if err == nil {
|
|
||||||
_ = base.DeleteCache(utils.Dir(path), account)
|
|
||||||
}
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -250,9 +239,6 @@ func (driver FTP) Upload(file *model.FileStream, account *model.Account) error {
|
|||||||
}
|
}
|
||||||
defer func() { _ = conn.Quit() }()
|
defer func() { _ = conn.Quit() }()
|
||||||
err = conn.Stor(realPath, file)
|
err = conn.Stor(realPath, file)
|
||||||
if err == nil {
|
|
||||||
_ = base.DeleteCache(file.ParentPath, account)
|
|
||||||
}
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,9 +194,6 @@ func (driver GoogleDrive) MakeDir(path string, account *model.Account) error {
|
|||||||
"mimeType": "application/vnd.google-apps.folder",
|
"mimeType": "application/vnd.google-apps.folder",
|
||||||
}
|
}
|
||||||
_, err = driver.Request("https://www.googleapis.com/drive/v3/files", base.Post, nil, nil, nil, &data, nil, account)
|
_, err = driver.Request("https://www.googleapis.com/drive/v3/files", base.Post, nil, nil, nil, &data, nil, account)
|
||||||
if err == nil {
|
|
||||||
_ = base.DeleteCache(utils.Dir(path), account)
|
|
||||||
}
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -206,13 +203,6 @@ func (driver GoogleDrive) Move(src string, dst string, account *model.Account) e
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if utils.Dir(src) == utils.Dir(dst) {
|
|
||||||
// rename
|
|
||||||
data := base.Json{
|
|
||||||
"name": utils.Base(dst),
|
|
||||||
}
|
|
||||||
_, err = driver.Request(url, base.Patch, nil, nil, nil, &data, nil, account)
|
|
||||||
} else {
|
|
||||||
dstParentFile, err := driver.File(utils.Dir(dst), account)
|
dstParentFile, err := driver.File(utils.Dir(dst), account)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -222,13 +212,19 @@ func (driver GoogleDrive) Move(src string, dst string, account *model.Account) e
|
|||||||
"removeParents": "root",
|
"removeParents": "root",
|
||||||
}
|
}
|
||||||
_, err = driver.Request(url, base.Patch, nil, query, nil, nil, nil, account)
|
_, err = driver.Request(url, base.Patch, nil, query, nil, nil, nil, account)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (driver GoogleDrive) Rename(src string, dst string, account *model.Account) error {
|
||||||
|
srcFile, err := driver.File(src, account)
|
||||||
|
url := "https://www.googleapis.com/drive/v3/files/" + srcFile.Id
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
if err == nil {
|
data := base.Json{
|
||||||
_ = base.DeleteCache(utils.Dir(src), account)
|
"name": utils.Base(dst),
|
||||||
if utils.Dir(src) != utils.Dir(dst) {
|
|
||||||
_ = base.DeleteCache(utils.Dir(dst), account)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
_, err = driver.Request(url, base.Patch, nil, nil, nil, &data, nil, account)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -243,9 +239,6 @@ func (driver GoogleDrive) Delete(path string, account *model.Account) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_, err = driver.Request(url, base.Delete, nil, nil, nil, nil, nil, account)
|
_, err = driver.Request(url, base.Delete, nil, nil, nil, nil, nil, account)
|
||||||
if err == nil {
|
|
||||||
_ = base.DeleteCache(utils.Dir(path), account)
|
|
||||||
}
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -286,9 +279,6 @@ func (driver GoogleDrive) Upload(file *model.FileStream, account *model.Account)
|
|||||||
putUrl := res.Header().Get("location")
|
putUrl := res.Header().Get("location")
|
||||||
byteData, _ := ioutil.ReadAll(file)
|
byteData, _ := ioutil.ReadAll(file)
|
||||||
_, err = driver.Request(putUrl, base.Put, nil, nil, nil, byteData, nil, account)
|
_, err = driver.Request(putUrl, base.Put, nil, nil, nil, byteData, nil, account)
|
||||||
if err == nil {
|
|
||||||
_ = base.DeleteCache(file.ParentPath, account)
|
|
||||||
}
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,6 +170,10 @@ func (driver *Lanzou) Move(src string, dst string, account *model.Account) error
|
|||||||
return base.ErrNotImplement
|
return base.ErrNotImplement
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (driver *Lanzou) Rename(src string, dst string, account *model.Account) error {
|
||||||
|
return base.ErrNotImplement
|
||||||
|
}
|
||||||
|
|
||||||
func (driver *Lanzou) Copy(src string, dst string, account *model.Account) error {
|
func (driver *Lanzou) Copy(src string, dst string, account *model.Account) error {
|
||||||
return base.ErrNotImplement
|
return base.ErrNotImplement
|
||||||
}
|
}
|
||||||
|
@ -164,6 +164,10 @@ func (driver Native) Move(src string, dst string, account *model.Account) error
|
|||||||
return os.Rename(fullSrc, fullDst)
|
return os.Rename(fullSrc, fullDst)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (driver Native) Rename(src string, dst string, account *model.Account) error {
|
||||||
|
return driver.Move(src, dst, account)
|
||||||
|
}
|
||||||
|
|
||||||
func (driver Native) Copy(src string, dst string, account *model.Account) error {
|
func (driver Native) Copy(src string, dst string, account *model.Account) error {
|
||||||
fullSrc := filepath.Join(account.RootFolder, src)
|
fullSrc := filepath.Join(account.RootFolder, src)
|
||||||
fullDst := filepath.Join(account.RootFolder, dst)
|
fullDst := filepath.Join(account.RootFolder, dst)
|
||||||
|
@ -218,14 +218,10 @@ func (driver Onedrive) MakeDir(path string, account *model.Account) error {
|
|||||||
"@microsoft.graph.conflictBehavior": "rename",
|
"@microsoft.graph.conflictBehavior": "rename",
|
||||||
}
|
}
|
||||||
_, err := driver.Request(url, base.Post, nil, nil, nil, &data, nil, account)
|
_, err := driver.Request(url, base.Post, nil, nil, nil, &data, nil, account)
|
||||||
if err == nil {
|
|
||||||
_ = base.DeleteCache(utils.Dir(path), account)
|
|
||||||
}
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (driver Onedrive) Move(src string, dst string, account *model.Account) error {
|
func (driver Onedrive) Move(src string, dst string, account *model.Account) error {
|
||||||
log.Debugf("onedrive move")
|
|
||||||
dstParentFile, err := driver.GetFile(account, utils.Dir(dst))
|
dstParentFile, err := driver.GetFile(account, utils.Dir(dst))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -238,15 +234,13 @@ func (driver Onedrive) Move(src string, dst string, account *model.Account) erro
|
|||||||
}
|
}
|
||||||
url := driver.GetMetaUrl(account, false, src)
|
url := driver.GetMetaUrl(account, false, src)
|
||||||
_, err = driver.Request(url, base.Patch, nil, nil, nil, &data, nil, account)
|
_, err = driver.Request(url, base.Patch, nil, nil, nil, &data, nil, account)
|
||||||
if err == nil {
|
|
||||||
_ = base.DeleteCache(utils.Dir(src), account)
|
|
||||||
if utils.Dir(src) != utils.Dir(dst) {
|
|
||||||
_ = base.DeleteCache(utils.Dir(dst), account)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (driver Onedrive) Rename(src string, dst string, account *model.Account) error {
|
||||||
|
return driver.Move(src, dst, account)
|
||||||
|
}
|
||||||
|
|
||||||
func (driver Onedrive) Copy(src string, dst string, account *model.Account) error {
|
func (driver Onedrive) Copy(src string, dst string, account *model.Account) error {
|
||||||
dstParentFile, err := driver.GetFile(account, utils.Dir(dst))
|
dstParentFile, err := driver.GetFile(account, utils.Dir(dst))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -261,21 +255,12 @@ func (driver Onedrive) Copy(src string, dst string, account *model.Account) erro
|
|||||||
}
|
}
|
||||||
url := driver.GetMetaUrl(account, false, src) + "/copy"
|
url := driver.GetMetaUrl(account, false, src) + "/copy"
|
||||||
_, err = driver.Request(url, base.Post, nil, nil, nil, &data, nil, account)
|
_, err = driver.Request(url, base.Post, nil, nil, nil, &data, nil, account)
|
||||||
if err == nil {
|
|
||||||
_ = base.DeleteCache(utils.Dir(src), account)
|
|
||||||
if utils.Dir(src) != utils.Dir(dst) {
|
|
||||||
_ = base.DeleteCache(utils.Dir(dst), account)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (driver Onedrive) Delete(path string, account *model.Account) error {
|
func (driver Onedrive) Delete(path string, account *model.Account) error {
|
||||||
url := driver.GetMetaUrl(account, false, path)
|
url := driver.GetMetaUrl(account, false, path)
|
||||||
_, err := driver.Request(url, base.Delete, nil, nil, nil, nil, nil, account)
|
_, err := driver.Request(url, base.Delete, nil, nil, nil, nil, nil, account)
|
||||||
if err == nil {
|
|
||||||
_ = base.DeleteCache(utils.Dir(path), account)
|
|
||||||
}
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -289,9 +274,6 @@ func (driver Onedrive) Upload(file *model.FileStream, account *model.Account) er
|
|||||||
} else {
|
} else {
|
||||||
err = driver.UploadBig(file, account)
|
err = driver.UploadBig(file, account)
|
||||||
}
|
}
|
||||||
if err == nil {
|
|
||||||
_ = base.DeleteCache(file.ParentPath, account)
|
|
||||||
}
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
59
drivers/operate/operate.go
Normal file
59
drivers/operate/operate.go
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
package operate
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/Xhofe/alist/drivers/base"
|
||||||
|
"github.com/Xhofe/alist/model"
|
||||||
|
"github.com/Xhofe/alist/utils"
|
||||||
|
)
|
||||||
|
|
||||||
|
func MakeDir(driver base.Driver, account *model.Account, path string, clearCache bool) error {
|
||||||
|
err := driver.MakeDir(path, account)
|
||||||
|
if err == nil && clearCache {
|
||||||
|
_ = base.DeleteCache(utils.Dir(path), account)
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func Move(driver base.Driver, account *model.Account, src, dst string, clearCache bool) error {
|
||||||
|
rename := false
|
||||||
|
if utils.Dir(src) == utils.Dir(dst) {
|
||||||
|
rename = true
|
||||||
|
}
|
||||||
|
var err error
|
||||||
|
if rename {
|
||||||
|
err = driver.Rename(src, dst, account)
|
||||||
|
} else {
|
||||||
|
err = driver.Move(src, dst, account)
|
||||||
|
}
|
||||||
|
if err == nil && clearCache {
|
||||||
|
_ = base.DeleteCache(utils.Dir(src), account)
|
||||||
|
if !rename {
|
||||||
|
_ = base.DeleteCache(utils.Dir(dst), account)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func Copy(driver base.Driver, account *model.Account, src, dst string, clearCache bool) error {
|
||||||
|
err := driver.Copy(src, dst, account)
|
||||||
|
if err == nil && clearCache {
|
||||||
|
_ = base.DeleteCache(utils.Dir(dst), account)
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func Delete(driver base.Driver, account *model.Account, path string, clearCache bool) error {
|
||||||
|
err := driver.Delete(path, account)
|
||||||
|
if err == nil && clearCache {
|
||||||
|
_ = base.DeleteCache(utils.Dir(path), account)
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func Upload(driver base.Driver, account *model.Account, file *model.FileStream, clearCache bool) error {
|
||||||
|
err := driver.Upload(file, account)
|
||||||
|
if err == nil && clearCache {
|
||||||
|
_ = base.DeleteCache(file.ParentPath, account)
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
@ -159,26 +159,15 @@ func (driver PikPak) MakeDir(path string, account *model.Account) error {
|
|||||||
"parent_id": parentFile.Id,
|
"parent_id": parentFile.Id,
|
||||||
"name": name,
|
"name": name,
|
||||||
}, nil, account)
|
}, nil, account)
|
||||||
if err == nil {
|
|
||||||
_ = base.DeleteCache(dir, account)
|
|
||||||
}
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (driver PikPak) Move(src string, dst string, account *model.Account) error {
|
func (driver PikPak) Move(src string, dst string, account *model.Account) error {
|
||||||
srcDir, _ := filepath.Split(src)
|
dstDir, _ := filepath.Split(dst)
|
||||||
dstDir, dstName := filepath.Split(dst)
|
|
||||||
srcFile, err := driver.File(src, account)
|
srcFile, err := driver.File(src, account)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// rename
|
|
||||||
if srcDir == dstDir {
|
|
||||||
_, err = driver.Request("https://api-drive.mypikpak.com/drive/v1/files/"+srcFile.Id, base.Patch, nil, &base.Json{
|
|
||||||
"name": dstName,
|
|
||||||
}, nil, account)
|
|
||||||
} else {
|
|
||||||
// move
|
|
||||||
dstDirFile, err := driver.File(dstDir, account)
|
dstDirFile, err := driver.File(dstDir, account)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -189,11 +178,18 @@ func (driver PikPak) Move(src string, dst string, account *model.Account) error
|
|||||||
"parent_id": dstDirFile.Id,
|
"parent_id": dstDirFile.Id,
|
||||||
},
|
},
|
||||||
}, nil, account)
|
}, nil, account)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (driver PikPak) Rename(src string, dst string, account *model.Account) error {
|
||||||
|
_, dstName := filepath.Split(dst)
|
||||||
|
srcFile, err := driver.File(src, account)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
if err == nil {
|
_, err = driver.Request("https://api-drive.mypikpak.com/drive/v1/files/"+srcFile.Id, base.Patch, nil, &base.Json{
|
||||||
_ = base.DeleteCache(srcDir, account)
|
"name": dstName,
|
||||||
_ = base.DeleteCache(dstDir, account)
|
}, nil, account)
|
||||||
}
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -212,9 +208,6 @@ func (driver PikPak) Copy(src string, dst string, account *model.Account) error
|
|||||||
"parent_id": dstDirFile.Id,
|
"parent_id": dstDirFile.Id,
|
||||||
},
|
},
|
||||||
}, nil, account)
|
}, nil, account)
|
||||||
if err == nil {
|
|
||||||
_ = base.DeleteCache(utils.Dir(dst), account)
|
|
||||||
}
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -226,9 +219,6 @@ func (driver PikPak) Delete(path string, account *model.Account) error {
|
|||||||
_, err = driver.Request("https://api-drive.mypikpak.com/drive/v1/files:batchTrash", base.Post, nil, &base.Json{
|
_, err = driver.Request("https://api-drive.mypikpak.com/drive/v1/files:batchTrash", base.Post, nil, &base.Json{
|
||||||
"ids": []string{file.Id},
|
"ids": []string{file.Id},
|
||||||
}, nil, account)
|
}, nil, account)
|
||||||
if err == nil {
|
|
||||||
_ = base.DeleteCache(utils.Dir(path), account)
|
|
||||||
}
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -274,9 +264,6 @@ func (driver PikPak) Upload(file *model.FileStream, account *model.Account) erro
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
err = bucket.PutObjectWithURL(signedURL, file)
|
err = bucket.PutObjectWithURL(signedURL, file)
|
||||||
if err == nil {
|
|
||||||
_ = base.DeleteCache(file.ParentPath, account)
|
|
||||||
}
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -193,6 +193,10 @@ func (driver S3) Move(src string, dst string, account *model.Account) error {
|
|||||||
return driver.Delete(src, account)
|
return driver.Delete(src, account)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (driver S3) Rename(src string, dst string, account *model.Account) error {
|
||||||
|
return driver.Move(src, dst, account)
|
||||||
|
}
|
||||||
|
|
||||||
func (driver S3) Copy(src string, dst string, account *model.Account) error {
|
func (driver S3) Copy(src string, dst string, account *model.Account) error {
|
||||||
client, err := driver.GetClient(account)
|
client, err := driver.GetClient(account)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -210,9 +214,6 @@ func (driver S3) Copy(src string, dst string, account *model.Account) error {
|
|||||||
Key: &dstKey,
|
Key: &dstKey,
|
||||||
}
|
}
|
||||||
_, err = client.CopyObject(input)
|
_, err = client.CopyObject(input)
|
||||||
if err == nil {
|
|
||||||
_ = base.DeleteCache(dst, account)
|
|
||||||
}
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -231,9 +232,6 @@ func (driver S3) Delete(path string, account *model.Account) error {
|
|||||||
Key: &key,
|
Key: &key,
|
||||||
}
|
}
|
||||||
_, err = client.DeleteObject(input)
|
_, err = client.DeleteObject(input)
|
||||||
if err == nil {
|
|
||||||
_ = base.DeleteCache(utils.Dir(path), account)
|
|
||||||
}
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -253,9 +251,6 @@ func (driver S3) Upload(file *model.FileStream, account *model.Account) error {
|
|||||||
Body: file,
|
Body: file,
|
||||||
}
|
}
|
||||||
_, err := uploader.Upload(input)
|
_, err := uploader.Upload(input)
|
||||||
if err == nil {
|
|
||||||
_ = base.DeleteCache(file.ParentPath, account)
|
|
||||||
}
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,9 +169,6 @@ func (driver Shandian) MakeDir(path string, account *model.Account) error {
|
|||||||
"name": utils.Base(path),
|
"name": utils.Base(path),
|
||||||
}
|
}
|
||||||
_, err = driver.Post("https://shandianpan.com/api/pan/mkdir", data, nil, account)
|
_, err = driver.Post("https://shandianpan.com/api/pan/mkdir", data, nil, account)
|
||||||
if err == nil {
|
|
||||||
_ = base.DeleteCache(utils.Dir(path), account)
|
|
||||||
}
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -180,14 +177,6 @@ func (driver Shandian) Move(src string, dst string, account *model.Account) erro
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if utils.Dir(src) == utils.Dir(dst) {
|
|
||||||
// rename
|
|
||||||
data := map[string]interface{}{
|
|
||||||
"id": srcFile.Id,
|
|
||||||
"name": utils.Base(dst),
|
|
||||||
}
|
|
||||||
_, err = driver.Post("https://shandianpan.com/api/pan/change", data, nil, account)
|
|
||||||
} else {
|
|
||||||
dstParentFile, err := driver.File(utils.Dir(dst), account)
|
dstParentFile, err := driver.File(utils.Dir(dst), account)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -197,13 +186,19 @@ func (driver Shandian) Move(src string, dst string, account *model.Account) erro
|
|||||||
"to_id": dstParentFile.Id,
|
"to_id": dstParentFile.Id,
|
||||||
}
|
}
|
||||||
_, err = driver.Post("https://shandianpan.com/api/pan/move", data, nil, account)
|
_, err = driver.Post("https://shandianpan.com/api/pan/move", data, nil, account)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (driver Shandian) Rename(src string, dst string, account *model.Account) error {
|
||||||
|
srcFile, err := driver.File(src, account)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
if err == nil {
|
data := map[string]interface{}{
|
||||||
_ = base.DeleteCache(utils.Dir(src), account)
|
"id": srcFile.Id,
|
||||||
if utils.Dir(src) != utils.Dir(dst) {
|
"name": utils.Base(dst),
|
||||||
_ = base.DeleteCache(utils.Dir(dst), account)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
_, err = driver.Post("https://shandianpan.com/api/pan/change", data, nil, account)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -220,9 +215,6 @@ func (driver Shandian) Delete(path string, account *model.Account) error {
|
|||||||
"id": file.Id,
|
"id": file.Id,
|
||||||
}
|
}
|
||||||
_, err = driver.Post("https://shandianpan.com/api/pan/recycle-in", data, nil, account)
|
_, err = driver.Post("https://shandianpan.com/api/pan/recycle-in", data, nil, account)
|
||||||
if err == nil {
|
|
||||||
_ = base.DeleteCache(utils.Dir(path), account)
|
|
||||||
}
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -272,7 +264,6 @@ func (driver Shandian) Upload(file *model.FileStream, account *model.Account) er
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if r.Code == 0 {
|
if r.Code == 0 {
|
||||||
_ = base.DeleteCache(file.ParentPath, account)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return errors.New(r.Msg)
|
return errors.New(r.Msg)
|
||||||
|
@ -145,39 +145,28 @@ func (driver WebDav) Preview(path string, account *model.Account) (interface{},
|
|||||||
func (driver WebDav) MakeDir(path string, account *model.Account) error {
|
func (driver WebDav) MakeDir(path string, account *model.Account) error {
|
||||||
c := driver.NewClient(account)
|
c := driver.NewClient(account)
|
||||||
err := c.MkdirAll(driver.WebDavPath(path), 0644)
|
err := c.MkdirAll(driver.WebDavPath(path), 0644)
|
||||||
if err == nil {
|
|
||||||
_ = base.DeleteCache(utils.Dir(path), account)
|
|
||||||
}
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (driver WebDav) Move(src string, dst string, account *model.Account) error {
|
func (driver WebDav) Move(src string, dst string, account *model.Account) error {
|
||||||
c := driver.NewClient(account)
|
c := driver.NewClient(account)
|
||||||
err := c.Rename(driver.WebDavPath(src), driver.WebDavPath(dst), true)
|
err := c.Rename(driver.WebDavPath(src), driver.WebDavPath(dst), true)
|
||||||
if err == nil {
|
|
||||||
_ = base.DeleteCache(utils.Dir(src), account)
|
|
||||||
if utils.Dir(src) != utils.Dir(dst) {
|
|
||||||
_ = base.DeleteCache(utils.Dir(dst), account)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (driver WebDav) Rename(src string, dst string, account *model.Account) error {
|
||||||
|
return driver.Move(src, dst, account)
|
||||||
|
}
|
||||||
|
|
||||||
func (driver WebDav) Copy(src string, dst string, account *model.Account) error {
|
func (driver WebDav) Copy(src string, dst string, account *model.Account) error {
|
||||||
c := driver.NewClient(account)
|
c := driver.NewClient(account)
|
||||||
err := c.Copy(driver.WebDavPath(src), driver.WebDavPath(dst), true)
|
err := c.Copy(driver.WebDavPath(src), driver.WebDavPath(dst), true)
|
||||||
if err == nil {
|
|
||||||
_ = base.DeleteCache(utils.Dir(dst), account)
|
|
||||||
}
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (driver WebDav) Delete(path string, account *model.Account) error {
|
func (driver WebDav) Delete(path string, account *model.Account) error {
|
||||||
c := driver.NewClient(account)
|
c := driver.NewClient(account)
|
||||||
err := c.RemoveAll(driver.WebDavPath(path))
|
err := c.RemoveAll(driver.WebDavPath(path))
|
||||||
if err == nil {
|
|
||||||
_ = base.DeleteCache(utils.Dir(path), account)
|
|
||||||
}
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -188,9 +177,6 @@ func (driver WebDav) Upload(file *model.FileStream, account *model.Account) erro
|
|||||||
c := driver.NewClient(account)
|
c := driver.NewClient(account)
|
||||||
path := utils.Join(file.ParentPath, file.Name)
|
path := utils.Join(file.ParentPath, file.Name)
|
||||||
err := c.WriteStream(driver.WebDavPath(path), file, 0644)
|
err := c.WriteStream(driver.WebDavPath(path), file, 0644)
|
||||||
if err == nil {
|
|
||||||
_ = base.DeleteCache(file.ParentPath, account)
|
|
||||||
}
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ package controllers
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/Xhofe/alist/conf"
|
"github.com/Xhofe/alist/conf"
|
||||||
|
"github.com/Xhofe/alist/drivers/operate"
|
||||||
"github.com/Xhofe/alist/model"
|
"github.com/Xhofe/alist/model"
|
||||||
"github.com/Xhofe/alist/server/common"
|
"github.com/Xhofe/alist/server/common"
|
||||||
"github.com/Xhofe/alist/utils"
|
"github.com/Xhofe/alist/utils"
|
||||||
@ -48,7 +49,7 @@ func UploadFile(c *gin.Context) {
|
|||||||
Name: file.Filename,
|
Name: file.Filename,
|
||||||
MIMEType: file.Header.Get("Content-Type"),
|
MIMEType: file.Header.Get("Content-Type"),
|
||||||
}
|
}
|
||||||
err = driver.Upload(&fileStream, account)
|
err = operate.Upload(driver, account, &fileStream, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
common.ErrorResp(c, err, 500)
|
common.ErrorResp(c, err, 500)
|
||||||
return
|
return
|
||||||
|
@ -9,7 +9,9 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"github.com/Xhofe/alist/conf"
|
"github.com/Xhofe/alist/conf"
|
||||||
"github.com/Xhofe/alist/drivers/base"
|
"github.com/Xhofe/alist/drivers/base"
|
||||||
|
"github.com/Xhofe/alist/drivers/operate"
|
||||||
"github.com/Xhofe/alist/model"
|
"github.com/Xhofe/alist/model"
|
||||||
|
"github.com/Xhofe/alist/server/common"
|
||||||
"github.com/Xhofe/alist/utils"
|
"github.com/Xhofe/alist/utils"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"net"
|
"net"
|
||||||
@ -22,30 +24,6 @@ import (
|
|||||||
|
|
||||||
type FileSystem struct{}
|
type FileSystem struct{}
|
||||||
|
|
||||||
func ParsePath(rawPath string) (*model.Account, string, base.Driver, error) {
|
|
||||||
var internalPath, name string
|
|
||||||
switch model.AccountsCount() {
|
|
||||||
case 0:
|
|
||||||
return nil, "", nil, fmt.Errorf("no accounts,please add one first")
|
|
||||||
case 1:
|
|
||||||
internalPath = rawPath
|
|
||||||
break
|
|
||||||
default:
|
|
||||||
paths := strings.Split(rawPath, "/")
|
|
||||||
internalPath = "/" + strings.Join(paths[2:], "/")
|
|
||||||
name = paths[1]
|
|
||||||
}
|
|
||||||
account, ok := model.GetAccount(name)
|
|
||||||
if !ok {
|
|
||||||
return nil, "", nil, fmt.Errorf("no [%s] account", name)
|
|
||||||
}
|
|
||||||
driver, ok := base.GetDriver(account.Type)
|
|
||||||
if !ok {
|
|
||||||
return nil, "", nil, fmt.Errorf("no [%s] driver", account.Type)
|
|
||||||
}
|
|
||||||
return &account, internalPath, driver, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (fs *FileSystem) File(rawPath string) (*model.File, error) {
|
func (fs *FileSystem) File(rawPath string) (*model.File, error) {
|
||||||
rawPath = utils.ParsePath(rawPath)
|
rawPath = utils.ParsePath(rawPath)
|
||||||
if model.AccountsCount() > 1 && rawPath == "/" {
|
if model.AccountsCount() > 1 && rawPath == "/" {
|
||||||
@ -58,7 +36,7 @@ func (fs *FileSystem) File(rawPath string) (*model.File, error) {
|
|||||||
UpdatedAt: &now,
|
UpdatedAt: &now,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
account, path_, driver, err := ParsePath(rawPath)
|
account, path_, driver, err := common.ParsePath(rawPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -74,34 +52,13 @@ func (fs *FileSystem) Files(rawPath string) ([]model.File, error) {
|
|||||||
}
|
}
|
||||||
return files, nil
|
return files, nil
|
||||||
}
|
}
|
||||||
account, path_, driver, err := ParsePath(rawPath)
|
account, path_, driver, err := common.ParsePath(rawPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return driver.Files(path_, account)
|
return driver.Files(path_, account)
|
||||||
}
|
}
|
||||||
|
|
||||||
//func GetPW(path string, name string) string {
|
|
||||||
// if !conf.CheckDown {
|
|
||||||
// return ""
|
|
||||||
// }
|
|
||||||
// meta, err := model.GetMetaByPath(path)
|
|
||||||
// if err == nil {
|
|
||||||
// if meta.Password != "" {
|
|
||||||
// return utils.SignWithPassword(name, meta.Password)
|
|
||||||
// }
|
|
||||||
// return ""
|
|
||||||
// } else {
|
|
||||||
// if !conf.CheckParent {
|
|
||||||
// return ""
|
|
||||||
// }
|
|
||||||
// if path == "/" {
|
|
||||||
// return ""
|
|
||||||
// }
|
|
||||||
// return GetPW(utils.Dir(path), name)
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
func ClientIP(r *http.Request) string {
|
func ClientIP(r *http.Request) string {
|
||||||
xForwardedFor := r.Header.Get("X-Forwarded-For")
|
xForwardedFor := r.Header.Get("X-Forwarded-For")
|
||||||
ip := strings.TrimSpace(strings.Split(xForwardedFor, ",")[0])
|
ip := strings.TrimSpace(strings.Split(xForwardedFor, ",")[0])
|
||||||
@ -127,7 +84,7 @@ func (fs *FileSystem) Link(r *http.Request, rawPath string) (string, error) {
|
|||||||
if model.AccountsCount() > 1 && rawPath == "/" {
|
if model.AccountsCount() > 1 && rawPath == "/" {
|
||||||
// error
|
// error
|
||||||
}
|
}
|
||||||
account, path_, driver, err := ParsePath(rawPath)
|
account, path_, driver, err := common.ParsePath(rawPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
@ -161,12 +118,12 @@ func (fs *FileSystem) CreateDirectory(ctx context.Context, rawPath string) error
|
|||||||
if model.AccountsCount() > 1 && len(strings.Split(rawPath, "/")) < 2 {
|
if model.AccountsCount() > 1 && len(strings.Split(rawPath, "/")) < 2 {
|
||||||
return ErrNotImplemented
|
return ErrNotImplemented
|
||||||
}
|
}
|
||||||
account, path_, driver, err := ParsePath(rawPath)
|
account, path_, driver, err := common.ParsePath(rawPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
log.Debugf("mkdir: %s", path_)
|
log.Debugf("mkdir: %s", path_)
|
||||||
return driver.MakeDir(path_, account)
|
return operate.MakeDir(driver, account, path_, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fs *FileSystem) Upload(ctx context.Context, r *http.Request, rawPath string) error {
|
func (fs *FileSystem) Upload(ctx context.Context, r *http.Request, rawPath string) error {
|
||||||
@ -174,7 +131,7 @@ func (fs *FileSystem) Upload(ctx context.Context, r *http.Request, rawPath strin
|
|||||||
if model.AccountsCount() > 1 && rawPath == "/" {
|
if model.AccountsCount() > 1 && rawPath == "/" {
|
||||||
return ErrNotImplemented
|
return ErrNotImplemented
|
||||||
}
|
}
|
||||||
account, path_, driver, err := ParsePath(rawPath)
|
account, path_, driver, err := common.ParsePath(rawPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -191,7 +148,7 @@ func (fs *FileSystem) Upload(ctx context.Context, r *http.Request, rawPath strin
|
|||||||
Name: fileName,
|
Name: fileName,
|
||||||
ParentPath: filePath,
|
ParentPath: filePath,
|
||||||
}
|
}
|
||||||
return driver.Upload(&fileData, account)
|
return operate.Upload(driver, account, &fileData, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fs *FileSystem) Delete(rawPath string) error {
|
func (fs *FileSystem) Delete(rawPath string) error {
|
||||||
@ -202,11 +159,11 @@ func (fs *FileSystem) Delete(rawPath string) error {
|
|||||||
if model.AccountsCount() > 1 && len(strings.Split(rawPath, "/")) < 2 {
|
if model.AccountsCount() > 1 && len(strings.Split(rawPath, "/")) < 2 {
|
||||||
return ErrNotImplemented
|
return ErrNotImplemented
|
||||||
}
|
}
|
||||||
account, path_, driver, err := ParsePath(rawPath)
|
account, path_, driver, err := common.ParsePath(rawPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return driver.Delete(path_, account)
|
return operate.Delete(driver, account, path_, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
// slashClean is equivalent to but slightly more efficient than
|
// slashClean is equivalent to but slightly more efficient than
|
||||||
@ -228,18 +185,18 @@ func moveFiles(ctx context.Context, fs *FileSystem, src string, dst string, over
|
|||||||
if src == dst {
|
if src == dst {
|
||||||
return http.StatusMethodNotAllowed, errDestinationEqualsSource
|
return http.StatusMethodNotAllowed, errDestinationEqualsSource
|
||||||
}
|
}
|
||||||
srcAccount, srcPath, driver, err := ParsePath(src)
|
srcAccount, srcPath, driver, err := common.ParsePath(src)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return http.StatusMethodNotAllowed, err
|
return http.StatusMethodNotAllowed, err
|
||||||
}
|
}
|
||||||
dstAccount, dstPath, _, err := ParsePath(dst)
|
dstAccount, dstPath, _, err := common.ParsePath(dst)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return http.StatusMethodNotAllowed, err
|
return http.StatusMethodNotAllowed, err
|
||||||
}
|
}
|
||||||
if srcAccount.Name != dstAccount.Name {
|
if srcAccount.Name != dstAccount.Name {
|
||||||
return http.StatusMethodNotAllowed, errInvalidDestination
|
return http.StatusMethodNotAllowed, errInvalidDestination
|
||||||
}
|
}
|
||||||
err = driver.Move(srcPath, dstPath, srcAccount)
|
err = operate.Move(driver, srcAccount, srcPath, dstPath, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debug(err)
|
log.Debug(err)
|
||||||
return http.StatusInternalServerError, err
|
return http.StatusInternalServerError, err
|
||||||
@ -257,11 +214,11 @@ func copyFiles(ctx context.Context, fs *FileSystem, src string, dst string, over
|
|||||||
if src == dst {
|
if src == dst {
|
||||||
return http.StatusMethodNotAllowed, errDestinationEqualsSource
|
return http.StatusMethodNotAllowed, errDestinationEqualsSource
|
||||||
}
|
}
|
||||||
srcAccount, srcPath, driver, err := ParsePath(src)
|
srcAccount, srcPath, driver, err := common.ParsePath(src)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return http.StatusMethodNotAllowed, err
|
return http.StatusMethodNotAllowed, err
|
||||||
}
|
}
|
||||||
dstAccount, dstPath, _, err := ParsePath(dst)
|
dstAccount, dstPath, _, err := common.ParsePath(dst)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return http.StatusMethodNotAllowed, err
|
return http.StatusMethodNotAllowed, err
|
||||||
}
|
}
|
||||||
@ -269,7 +226,7 @@ func copyFiles(ctx context.Context, fs *FileSystem, src string, dst string, over
|
|||||||
// TODO 跨账号复制
|
// TODO 跨账号复制
|
||||||
return http.StatusMethodNotAllowed, errInvalidDestination
|
return http.StatusMethodNotAllowed, errInvalidDestination
|
||||||
}
|
}
|
||||||
err = driver.Copy(srcPath, dstPath, srcAccount)
|
err = operate.Copy(driver, srcAccount, srcPath, dstPath, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return http.StatusInternalServerError, err
|
return http.StatusInternalServerError, err
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user