🎨 change link interface
This commit is contained in:
parent
f5b8815a84
commit
d00f75c814
@ -125,8 +125,8 @@ func (driver Pan123) Files(path string, account *model.Account) ([]model.File, e
|
|||||||
return files, nil
|
return files, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (driver Pan123) Link(path string, account *model.Account) (*base.Link, error) {
|
func (driver Pan123) Link(args base.Args, account *model.Account) (*base.Link, error) {
|
||||||
file, err := driver.GetFile(utils.ParsePath(path), account)
|
file, err := driver.GetFile(utils.ParsePath(args.Path), account)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -160,9 +160,9 @@ func (driver Pan123) Link(path string, account *model.Account) (*base.Link, erro
|
|||||||
link := base.Link{
|
link := base.Link{
|
||||||
Url: resp.Data.DownloadUrl,
|
Url: resp.Data.DownloadUrl,
|
||||||
}
|
}
|
||||||
//if res.StatusCode() == 302 {
|
if res.StatusCode() == 302 {
|
||||||
// link.Url = res.Header().Get("location")
|
link.Url = res.Header().Get("location")
|
||||||
//}
|
}
|
||||||
return &link, nil
|
return &link, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,7 +174,7 @@ func (driver Pan123) Path(path string, account *model.Account) (*model.File, []m
|
|||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
if !file.IsDir() {
|
if !file.IsDir() {
|
||||||
link, err := driver.Link(path, account)
|
link, err := driver.Link(base.Args{Path: path}, account)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
@ -138,8 +138,8 @@ func (driver Cloud189) Files(path string, account *model.Account) ([]model.File,
|
|||||||
return files, nil
|
return files, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (driver Cloud189) Link(path string, account *model.Account) (*base.Link, error) {
|
func (driver Cloud189) Link(args base.Args, account *model.Account) (*base.Link, error) {
|
||||||
file, err := driver.File(utils.ParsePath(path), account)
|
file, err := driver.File(utils.ParsePath(args.Path), account)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -167,7 +167,7 @@ func (driver Cloud189) Link(path string, account *model.Account) (*base.Link, er
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return driver.Link(path, account)
|
return driver.Link(args, account)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if resp.ResCode != 0 {
|
if resp.ResCode != 0 {
|
||||||
@ -194,7 +194,7 @@ func (driver Cloud189) Path(path string, account *model.Account) (*model.File, [
|
|||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
if !file.IsDir() {
|
if !file.IsDir() {
|
||||||
link, err := driver.Link(path, account)
|
link, err := driver.Link(base.Args{Path: path}, account)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
@ -229,7 +229,7 @@ func (driver Cloud189) MakeDir(path string, account *model.Account) error {
|
|||||||
"parentFolderId": parent.Id,
|
"parentFolderId": parent.Id,
|
||||||
"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 {
|
if err == nil {
|
||||||
_ = base.DeleteCache(dir, account)
|
_ = base.DeleteCache(dir, account)
|
||||||
}
|
}
|
||||||
@ -257,7 +257,7 @@ func (driver Cloud189) Move(src string, dst string, account *model.Account) erro
|
|||||||
idKey: srcFile.Id,
|
idKey: srcFile.Id,
|
||||||
nameKey: dstName,
|
nameKey: dstName,
|
||||||
}
|
}
|
||||||
_, err = driver.Request(url, "POST", form,nil, account)
|
_, err = driver.Request(url, "POST", form, nil, account)
|
||||||
} else {
|
} else {
|
||||||
// move
|
// move
|
||||||
dstDirFile, err := driver.File(dstDir, account)
|
dstDirFile, err := driver.File(dstDir, account)
|
||||||
@ -284,7 +284,7 @@ func (driver Cloud189) Move(src string, dst string, account *model.Account) erro
|
|||||||
"targetFolderId": dstDirFile.Id,
|
"targetFolderId": dstDirFile.Id,
|
||||||
"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 {
|
if err == nil {
|
||||||
_ = base.DeleteCache(srcDir, account)
|
_ = base.DeleteCache(srcDir, account)
|
||||||
@ -323,7 +323,7 @@ func (driver Cloud189) Copy(src string, dst string, account *model.Account) erro
|
|||||||
"targetFolderId": dstDirFile.Id,
|
"targetFolderId": dstDirFile.Id,
|
||||||
"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 {
|
if err == nil {
|
||||||
_ = base.DeleteCache(dstDir, account)
|
_ = base.DeleteCache(dstDir, account)
|
||||||
}
|
}
|
||||||
@ -356,7 +356,7 @@ func (driver Cloud189) Delete(path string, account *model.Account) error {
|
|||||||
"targetFolderId": "",
|
"targetFolderId": "",
|
||||||
"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 {
|
if err == nil {
|
||||||
_ = base.DeleteCache(utils.Dir(path), account)
|
_ = base.DeleteCache(utils.Dir(path), account)
|
||||||
}
|
}
|
||||||
@ -377,11 +377,11 @@ func (driver Cloud189) Upload(file *model.FileStream, account *model.Account) er
|
|||||||
}
|
}
|
||||||
res, err := driver.UploadRequest("/person/initMultiUpload", map[string]string{
|
res, err := driver.UploadRequest("/person/initMultiUpload", map[string]string{
|
||||||
"parentFolderId": parentFile.Id,
|
"parentFolderId": parentFile.Id,
|
||||||
"fileName": file.Name,
|
"fileName": file.Name,
|
||||||
"fileSize": strconv.FormatInt(int64(file.Size),10),
|
"fileSize": strconv.FormatInt(int64(file.Size), 10),
|
||||||
"sliceSize": strconv.FormatInt(int64(DEFAULT),10),
|
"sliceSize": strconv.FormatInt(int64(DEFAULT), 10),
|
||||||
"lazyCheck": "1",
|
"lazyCheck": "1",
|
||||||
},account)
|
}, account)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -409,21 +409,21 @@ func (driver Cloud189) Upload(file *model.FileStream, account *model.Account) er
|
|||||||
md5s = append(md5s, md5Str)
|
md5s = append(md5s, md5Str)
|
||||||
md5Sum.Write(byteData)
|
md5Sum.Write(byteData)
|
||||||
res, err = driver.UploadRequest("/person/getMultiUploadUrls", map[string]string{
|
res, err = driver.UploadRequest("/person/getMultiUploadUrls", map[string]string{
|
||||||
"partInfo": fmt.Sprintf("%s-%s",strconv.FormatInt(i,10),md5Base64),
|
"partInfo": fmt.Sprintf("%s-%s", strconv.FormatInt(i, 10), md5Base64),
|
||||||
"uploadFileId": uploadFileId,
|
"uploadFileId": uploadFileId,
|
||||||
},account)
|
}, account)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
uploadData := jsoniter.Get(res,"uploadUrls.partNumber_"+strconv.FormatInt(i,10))
|
uploadData := jsoniter.Get(res, "uploadUrls.partNumber_"+strconv.FormatInt(i, 10))
|
||||||
headers := strings.Split(uploadData.Get("requestHeader").ToString(),"&")
|
headers := strings.Split(uploadData.Get("requestHeader").ToString(), "&")
|
||||||
req, err := http.NewRequest("PUT", uploadData.Get("requestURL").ToString(), bytes.NewBuffer(byteData))
|
req, err := http.NewRequest("PUT", uploadData.Get("requestURL").ToString(), bytes.NewBuffer(byteData))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _,header := range headers{
|
for _, header := range headers {
|
||||||
kv := strings.Split(header, "=")
|
kv := strings.Split(header, "=")
|
||||||
req.Header.Set(kv[0],strings.Join(kv[1:],"="))
|
req.Header.Set(kv[0], strings.Join(kv[1:], "="))
|
||||||
}
|
}
|
||||||
res, err := base.HttpClient.Do(req)
|
res, err := base.HttpClient.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -432,12 +432,12 @@ func (driver Cloud189) Upload(file *model.FileStream, account *model.Account) er
|
|||||||
log.Debugf("%+v", res)
|
log.Debugf("%+v", res)
|
||||||
}
|
}
|
||||||
id := md5Sum.Sum(nil)
|
id := md5Sum.Sum(nil)
|
||||||
res,err = driver.UploadRequest("/person/commitMultiUploadFile", map[string]string{
|
res, err = driver.UploadRequest("/person/commitMultiUploadFile", map[string]string{
|
||||||
"uploadFileId": uploadFileId,
|
"uploadFileId": uploadFileId,
|
||||||
"fileMd5": hex.EncodeToString(id),
|
"fileMd5": hex.EncodeToString(id),
|
||||||
"sliceMd5": utils.GetMD5Encode(strings.Join(md5s,"\n")),
|
"sliceMd5": utils.GetMD5Encode(strings.Join(md5s, "\n")),
|
||||||
"lazyCheck":"1",
|
"lazyCheck": "1",
|
||||||
},account)
|
}, account)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
_ = base.DeleteCache(file.ParentPath, account)
|
_ = base.DeleteCache(file.ParentPath, account)
|
||||||
}
|
}
|
||||||
|
@ -158,8 +158,8 @@ func (driver AliDrive) Files(path string, account *model.Account) ([]model.File,
|
|||||||
return files, nil
|
return files, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (driver AliDrive) Link(path string, account *model.Account) (*base.Link, error) {
|
func (driver AliDrive) Link(args base.Args, account *model.Account) (*base.Link, error) {
|
||||||
file, err := driver.File(path, account)
|
file, err := driver.File(args.Path, account)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -183,7 +183,7 @@ func (driver AliDrive) Link(path string, account *model.Account) (*base.Link, er
|
|||||||
return nil, err
|
return nil, err
|
||||||
} else {
|
} else {
|
||||||
_ = model.SaveAccount(account)
|
_ = model.SaveAccount(account)
|
||||||
return driver.Link(path, account)
|
return driver.Link(args, account)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil, fmt.Errorf("%s", e.Message)
|
return nil, fmt.Errorf("%s", e.Message)
|
||||||
@ -201,7 +201,7 @@ func (driver AliDrive) Path(path string, account *model.Account) (*model.File, [
|
|||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
if !file.IsDir() {
|
if !file.IsDir() {
|
||||||
link, err := driver.Link(path, account)
|
link, err := driver.Link(base.Args{Path: path}, account)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
@ -101,7 +101,8 @@ func (driver Alist) Files(path string, account *model.Account) ([]model.File, er
|
|||||||
return files, nil
|
return files, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (driver Alist) Link(path string, account *model.Account) (*base.Link, error) {
|
func (driver Alist) Link(args base.Args, account *model.Account) (*base.Link, error) {
|
||||||
|
path := args.Path
|
||||||
path = utils.ParsePath(path)
|
path = utils.ParsePath(path)
|
||||||
name := utils.Base(path)
|
name := utils.Base(path)
|
||||||
flag := "d"
|
flag := "d"
|
||||||
|
@ -12,25 +12,45 @@ type DriverConfig struct {
|
|||||||
Name string
|
Name string
|
||||||
OnlyProxy bool
|
OnlyProxy bool
|
||||||
NoLink bool // 必须本机返回的
|
NoLink bool // 必须本机返回的
|
||||||
|
ApiProxy bool // 使用API中转的
|
||||||
|
}
|
||||||
|
|
||||||
|
type Args struct {
|
||||||
|
Path string
|
||||||
|
IP string
|
||||||
}
|
}
|
||||||
|
|
||||||
type Driver interface {
|
type Driver interface {
|
||||||
|
// Config 配置
|
||||||
Config() DriverConfig
|
Config() DriverConfig
|
||||||
|
// Items 账号所需参数
|
||||||
Items() []Item
|
Items() []Item
|
||||||
|
// Save 保存时处理
|
||||||
Save(account *model.Account, old *model.Account) error
|
Save(account *model.Account, old *model.Account) error
|
||||||
|
// File 取文件
|
||||||
File(path string, account *model.Account) (*model.File, error)
|
File(path string, account *model.Account) (*model.File, error)
|
||||||
|
// Files 取文件夹
|
||||||
Files(path string, account *model.Account) ([]model.File, error)
|
Files(path string, account *model.Account) ([]model.File, error)
|
||||||
Link(path string, account *model.Account) (*Link, error)
|
// Link 取链接
|
||||||
|
Link(args Args, account *model.Account) (*Link, error)
|
||||||
|
// Path 取路径(文件或文件夹)
|
||||||
Path(path string, account *model.Account) (*model.File, []model.File, error)
|
Path(path string, account *model.Account) (*model.File, []model.File, error)
|
||||||
|
// Proxy 代理处理
|
||||||
Proxy(c *gin.Context, account *model.Account)
|
Proxy(c *gin.Context, account *model.Account)
|
||||||
|
// Preview 预览
|
||||||
Preview(path string, account *model.Account) (interface{}, error)
|
Preview(path string, account *model.Account) (interface{}, error)
|
||||||
|
// MakeDir 创建文件夹
|
||||||
|
MakeDir(path string, account *model.Account) error
|
||||||
|
// Move 移动/改名
|
||||||
|
Move(src string, dst string, account *model.Account) error
|
||||||
|
// Copy 拷贝
|
||||||
|
Copy(src string, dst string, account *model.Account) error
|
||||||
|
// Delete 删除
|
||||||
|
Delete(path string, account *model.Account) error
|
||||||
|
// Upload 上传
|
||||||
|
Upload(file *model.FileStream, account *model.Account) error
|
||||||
// TODO
|
// TODO
|
||||||
//Search(path string, keyword string, account *model.Account) ([]*model.File, error)
|
//Search(path string, keyword string, account *model.Account) ([]*model.File, error)
|
||||||
MakeDir(path string, account *model.Account) error
|
|
||||||
Move(src string, dst string, account *model.Account) error
|
|
||||||
Copy(src string, dst string, account *model.Account) error
|
|
||||||
Delete(path string, account *model.Account) error
|
|
||||||
Upload(file *model.FileStream, account *model.Account) error
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Item struct {
|
type Item struct {
|
||||||
@ -90,12 +110,14 @@ func GetDrivers() map[string][]Item {
|
|||||||
Label: "down_proxy_url",
|
Label: "down_proxy_url",
|
||||||
Type: TypeString,
|
Type: TypeString,
|
||||||
},
|
},
|
||||||
{
|
}, res[k]...)
|
||||||
|
if v.Config().ApiProxy {
|
||||||
|
res[k] = append(res[k], Item{
|
||||||
Name: "api_proxy_url",
|
Name: "api_proxy_url",
|
||||||
Label: "api_proxy_url",
|
Label: "api_proxy_url",
|
||||||
Type: TypeString,
|
Type: TypeString,
|
||||||
},
|
})
|
||||||
}, res[k]...)
|
}
|
||||||
}
|
}
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
@ -146,7 +146,8 @@ func (driver FTP) Files(path string, account *model.Account) ([]model.File, erro
|
|||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (driver FTP) Link(path string, account *model.Account) (*base.Link, error) {
|
func (driver FTP) Link(args base.Args, account *model.Account) (*base.Link, error) {
|
||||||
|
path := args.Path
|
||||||
path = utils.ParsePath(path)
|
path = utils.ParsePath(path)
|
||||||
realPath := utils.Join(account.RootFolder, path)
|
realPath := utils.Join(account.RootFolder, path)
|
||||||
conn, err := driver.Login(account)
|
conn, err := driver.Login(account)
|
||||||
|
@ -15,8 +15,8 @@ type GoogleDrive struct{}
|
|||||||
|
|
||||||
func (driver GoogleDrive) Config() base.DriverConfig {
|
func (driver GoogleDrive) Config() base.DriverConfig {
|
||||||
return base.DriverConfig{
|
return base.DriverConfig{
|
||||||
Name: "GoogleDrive",
|
Name: "GoogleDrive",
|
||||||
OnlyProxy: true,
|
OnlyProxy: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,8 +116,8 @@ func (driver GoogleDrive) Files(path string, account *model.Account) ([]model.Fi
|
|||||||
return files, nil
|
return files, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (driver GoogleDrive) Link(path string, account *model.Account) (*base.Link, error) {
|
func (driver GoogleDrive) Link(args base.Args, account *model.Account) (*base.Link, error) {
|
||||||
file, err := driver.File(path, account)
|
file, err := driver.File(args.Path, account)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -136,7 +136,7 @@ func (driver GoogleDrive) Link(path string, account *model.Account) (*base.Link,
|
|||||||
_ = model.SaveAccount(account)
|
_ = model.SaveAccount(account)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return driver.Link(path, account)
|
return driver.Link(args, account)
|
||||||
}
|
}
|
||||||
return nil, fmt.Errorf("%s: %v", e.Error.Message, e.Error.Errors)
|
return nil, fmt.Errorf("%s: %v", e.Error.Message, e.Error.Errors)
|
||||||
}
|
}
|
||||||
@ -144,7 +144,7 @@ func (driver GoogleDrive) Link(path string, account *model.Account) (*base.Link,
|
|||||||
Url: url + "&alt=media",
|
Url: url + "&alt=media",
|
||||||
Headers: []base.Header{
|
Headers: []base.Header{
|
||||||
{
|
{
|
||||||
Name: "Authorization",
|
Name: "Authorization",
|
||||||
Value: "Bearer " + account.AccessToken,
|
Value: "Bearer " + account.AccessToken,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -198,4 +198,4 @@ func (driver GoogleDrive) Upload(file *model.FileStream, account *model.Account)
|
|||||||
return base.ErrNotImplement
|
return base.ErrNotImplement
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ base.Driver = (*GoogleDrive)(nil)
|
var _ base.Driver = (*GoogleDrive)(nil)
|
||||||
|
@ -114,8 +114,8 @@ func (driver Lanzou) Files(path string, account *model.Account) ([]model.File, e
|
|||||||
return files, nil
|
return files, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (driver Lanzou) Link(path string, account *model.Account) (*base.Link, error) {
|
func (driver Lanzou) Link(args base.Args, account *model.Account) (*base.Link, error) {
|
||||||
file, err := driver.File(path, account)
|
file, err := driver.File(args.Path, account)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -145,7 +145,7 @@ func (driver Lanzou) Path(path string, account *model.Account) (*model.File, []m
|
|||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
if !file.IsDir() {
|
if !file.IsDir() {
|
||||||
link, err := driver.Link(path, account)
|
link, err := driver.Link(base.Args{Path: path}, account)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
@ -123,8 +123,8 @@ func (driver Native) Files(path string, account *model.Account) ([]model.File, e
|
|||||||
return files, nil
|
return files, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (driver Native) Link(path string, account *model.Account) (*base.Link, error) {
|
func (driver Native) Link(args base.Args, account *model.Account) (*base.Link, error) {
|
||||||
fullPath := filepath.Join(account.RootFolder, path)
|
fullPath := filepath.Join(account.RootFolder, args.Path)
|
||||||
s, err := os.Stat(fullPath)
|
s, err := os.Stat(fullPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -14,10 +14,9 @@ import (
|
|||||||
|
|
||||||
type Onedrive struct{}
|
type Onedrive struct{}
|
||||||
|
|
||||||
|
|
||||||
func (driver Onedrive) Config() base.DriverConfig {
|
func (driver Onedrive) Config() base.DriverConfig {
|
||||||
return base.DriverConfig{
|
return base.DriverConfig{
|
||||||
Name: "Onedrive",
|
Name: "Onedrive",
|
||||||
OnlyProxy: false,
|
OnlyProxy: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -173,8 +172,8 @@ func (driver Onedrive) Files(path string, account *model.Account) ([]model.File,
|
|||||||
return files, nil
|
return files, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (driver Onedrive) Link(path string, account *model.Account) (*base.Link, error) {
|
func (driver Onedrive) Link(args base.Args, account *model.Account) (*base.Link, error) {
|
||||||
file, err := driver.GetFile(account, path)
|
file, err := driver.GetFile(account, args.Path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -232,4 +231,4 @@ func (driver Onedrive) Upload(file *model.FileStream, account *model.Account) er
|
|||||||
return base.ErrNotImplement
|
return base.ErrNotImplement
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ base.Driver = (*Onedrive)(nil)
|
var _ base.Driver = (*Onedrive)(nil)
|
||||||
|
@ -99,8 +99,8 @@ func (driver PikPak) Files(path string, account *model.Account) ([]model.File, e
|
|||||||
return files, nil
|
return files, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (driver PikPak) Link(path string, account *model.Account) (*base.Link, error) {
|
func (driver PikPak) Link(args base.Args, account *model.Account) (*base.Link, error) {
|
||||||
file, err := driver.File(path, account)
|
file, err := driver.File(args.Path, account)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -123,7 +123,7 @@ func (driver PikPak) Path(path string, account *model.Account) (*model.File, []m
|
|||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
if !file.IsDir() {
|
if !file.IsDir() {
|
||||||
link, err := driver.Link(path, account)
|
link, err := driver.Link(base.Args{Path: path}, account)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ func Down(c *gin.Context) {
|
|||||||
Proxy(c)
|
Proxy(c)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
link, err := driver.Link(path, account)
|
link, err := driver.Link(base.Args{Path: path}, account)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
common.ErrorResp(c, err, 500)
|
common.ErrorResp(c, err, 500)
|
||||||
return
|
return
|
||||||
@ -71,7 +71,7 @@ func Proxy(c *gin.Context) {
|
|||||||
c.Redirect(302, link)
|
c.Redirect(302, link)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
link, err := driver.Link(path, account)
|
link, err := driver.Link(base.Args{Path: path}, account)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
common.ErrorResp(c, err, 500)
|
common.ErrorResp(c, err, 500)
|
||||||
return
|
return
|
||||||
|
@ -94,7 +94,7 @@ func Link(c *gin.Context) {
|
|||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
link, err := driver.Link(path, account)
|
link, err := driver.Link(base.Args{Path: path}, account)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
common.ErrorResp(c, err, 500)
|
common.ErrorResp(c, err, 500)
|
||||||
return
|
return
|
||||||
|
@ -123,7 +123,7 @@ func (fs *FileSystem) Link(r *http.Request, rawPath string) (string, error) {
|
|||||||
link += "?sign" + sign
|
link += "?sign" + sign
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
link_, err := driver.Link(path_, account)
|
link_, err := driver.Link(base.Args{Path: path_}, account)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
@ -145,7 +145,7 @@ func (fs *FileSystem) CreateDirectory(ctx context.Context, rawPath string) error
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return driver.MakeDir(path_,account)
|
return driver.MakeDir(path_, account)
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
||||||
@ -218,7 +218,7 @@ func moveFiles(ctx context.Context, fs *FileSystem, src string, dst string, over
|
|||||||
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 = driver.Move(srcPath, dstPath, srcAccount)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debug(err)
|
log.Debug(err)
|
||||||
return http.StatusInternalServerError, err
|
return http.StatusInternalServerError, err
|
||||||
@ -248,7 +248,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 = driver.Copy(srcPath, dstPath, srcAccount)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return http.StatusInternalServerError, err
|
return http.StatusInternalServerError, err
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user