🔨 refactor driver: ali

This commit is contained in:
微凉
2021-11-27 19:40:36 +08:00
parent 98691b2aa8
commit f577d82242
14 changed files with 999 additions and 918 deletions

View File

@ -4,16 +4,17 @@ import (
"github.com/Xhofe/alist/model"
"github.com/gin-gonic/gin"
"github.com/go-resty/resty/v2"
log "github.com/sirupsen/logrus"
"net/http"
)
type Driver interface {
Items() []Item
Save(account *model.Account, old *model.Account) error
//File(path string, account *model.Account) (*model.File, error)
//Files(path string, account *model.Account) ([]model.File, error)
Path(path string, account *model.Account) (*model.File, []model.File, error)
File(path string, account *model.Account) (*model.File, error)
Files(path string, account *model.Account) ([]model.File, error)
Link(path string, account *model.Account) (string, error)
Path(path string, account *model.Account) (*model.File, []model.File, error)
Proxy(c *gin.Context, account *model.Account)
Preview(path string, account *model.Account) (interface{}, error)
// TODO
@ -41,6 +42,7 @@ type TokenResp struct {
var driversMap = map[string]Driver{}
func RegisterDriver(name string, driver Driver) {
log.Infof("register driver: [%s]", name)
driversMap[name] = driver
}
@ -59,10 +61,10 @@ func GetDrivers() map[string][]Item {
type Json map[string]interface{}
var noRedirectClient *resty.Client
var NoRedirectClient *resty.Client
func init() {
noRedirectClient = resty.New().SetRedirectPolicy(
NoRedirectClient = resty.New().SetRedirectPolicy(
resty.RedirectPolicyFunc(func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
}),