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-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
|
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-10-27 10:59:03 +00:00
|
|
|
Save(account *model.Account, old *model.Account) error
|
2021-11-13 07:53:26 +00:00
|
|
|
Proxy(c *gin.Context)
|
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
|
|
|
|
//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{}
|