alist/drivers/driver.go

69 lines
1.7 KiB
Go
Raw Normal View History

2021-10-26 14:28:37 +00:00
package drivers
2021-10-27 14:45:36 +00:00
import (
"github.com/Xhofe/alist/model"
2021-11-13 07:53:26 +00:00
"github.com/gin-gonic/gin"
2021-11-15 12:15:25 +00:00
"github.com/go-resty/resty/v2"
"net/http"
2021-10-27 14:45:36 +00:00
)
2021-10-26 14:28:37 +00:00
type Driver interface {
2021-10-29 06:50:26 +00:00
Items() []Item
Save(account *model.Account, old *model.Account) error
2021-10-26 14:28:37 +00:00
Path(path string, account *model.Account) (*model.File, []*model.File, error)
2021-10-29 06:50:26 +00:00
Link(path string, account *model.Account) (string, error)
2021-11-17 08:37:12 +00:00
Proxy(c *gin.Context, account *model.Account)
2021-11-02 15:53:05 +00:00
Preview(path string, account *model.Account) (interface{}, error)
2021-10-29 06:50:26 +00:00
// TODO
2021-11-17 08:25:32 +00:00
//Search(path string, keyword string, account *model.Account) ([]*model.File, error)
2021-10-29 06:50:26 +00:00
//MakeDir(path string, account *model.Account) error
//Move(src string, des string, account *model.Account) error
//Delete(path string) error
//Upload(file *fs.File, path string, account *model.Account) error
}
type Item struct {
Name string `json:"name"`
Label string `json:"label"`
Type string `json:"type"`
2021-11-02 15:53:05 +00:00
Values string `json:"values"`
2021-10-29 06:50:26 +00:00
Required bool `json:"required"`
Description string `json:"description"`
2021-10-26 14:28:37 +00:00
}
2021-11-02 15:53:05 +00:00
type TokenResp struct {
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
}
2021-10-26 14:28:37 +00:00
var driversMap = map[string]Driver{}
func RegisterDriver(name string, driver Driver) {
driversMap[name] = driver
}
func GetDriver(name string) (driver Driver, ok bool) {
driver, ok = driversMap[name]
return
}
2021-10-29 06:50:26 +00:00
func GetDrivers() map[string][]Item {
res := make(map[string][]Item, 0)
for k, v := range driversMap {
res[k] = v.Items()
2021-10-26 14:28:37 +00:00
}
2021-10-29 06:50:26 +00:00
return res
2021-10-26 14:28:37 +00:00
}
2021-10-27 14:45:36 +00:00
type Json map[string]interface{}
2021-11-15 12:15:25 +00:00
var noRedirectClient *resty.Client
func init() {
noRedirectClient = resty.New().SetRedirectPolicy(
resty.RedirectPolicyFunc(func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
}),
)
}