🎨 change link interface

This commit is contained in:
微凉 2021-12-19 20:00:53 +08:00
parent f5b8815a84
commit d00f75c814
14 changed files with 96 additions and 73 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -14,7 +14,6 @@ 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",
@ -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
} }

View File

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

View File

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

View File

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

View File

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