mirror of
https://github.com/AlistGo/alist.git
synced 2025-06-06 10:24:32 +08:00
✨ guide
This commit is contained in:
@ -16,6 +16,7 @@ import (
|
||||
var aliClient = resty.New()
|
||||
|
||||
func init() {
|
||||
RegisterDriver("AliDrive", &AliDrive{})
|
||||
aliClient.
|
||||
SetRetryCount(3).
|
||||
SetHeader("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36").
|
||||
@ -23,7 +24,23 @@ func init() {
|
||||
SetHeader("origin", "https://aliyundrive.com")
|
||||
}
|
||||
|
||||
type AliDrive struct {
|
||||
type AliDrive struct {}
|
||||
|
||||
func (a AliDrive) Items() []Item {
|
||||
return []Item{
|
||||
{
|
||||
Name: "refresh_token",
|
||||
Label: "refresh token",
|
||||
Type: "string",
|
||||
Required: true,
|
||||
},
|
||||
{
|
||||
Name: "root_folder",
|
||||
Label: "root folder file_id",
|
||||
Type: "string",
|
||||
Required: false,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (a AliDrive) Proxy(ctx *fiber.Ctx) {
|
||||
@ -224,6 +241,9 @@ func (a AliDrive) Save(account *model.Account, old *model.Account) error {
|
||||
if old != nil {
|
||||
conf.Cron.Remove(cron.EntryID(old.CronId))
|
||||
}
|
||||
if account.RootFolder == "" {
|
||||
account.RootFolder = "root"
|
||||
}
|
||||
refresh, access, err := AliRefreshToken(account.RefreshToken)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -260,7 +280,3 @@ func (a AliDrive) Save(account *model.Account, old *model.Account) error {
|
||||
}
|
||||
|
||||
var _ Driver = (*AliDrive)(nil)
|
||||
|
||||
func init() {
|
||||
RegisterDriver("AliDrive", &AliDrive{})
|
||||
}
|
||||
|
@ -7,10 +7,24 @@ import (
|
||||
)
|
||||
|
||||
type Driver interface {
|
||||
Items() []Item
|
||||
Path(path string, account *model.Account) (*model.File, []*model.File, error)
|
||||
Link(path string, account *model.Account) (string, error)
|
||||
Save(account *model.Account, old *model.Account) error
|
||||
Proxy(ctx *fiber.Ctx)
|
||||
// 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"`
|
||||
Required bool `json:"required"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
var driversMap = map[string]Driver{}
|
||||
@ -24,12 +38,12 @@ func GetDriver(name string) (driver Driver, ok bool) {
|
||||
return
|
||||
}
|
||||
|
||||
func GetDriverNames() []string {
|
||||
names := make([]string, 0)
|
||||
for k, _ := range driversMap {
|
||||
names = append(names, k)
|
||||
func GetDrivers() map[string][]Item {
|
||||
res := make(map[string][]Item, 0)
|
||||
for k, v := range driversMap {
|
||||
res[k] = v.Items()
|
||||
}
|
||||
return names
|
||||
return res
|
||||
}
|
||||
|
||||
type Json map[string]interface{}
|
||||
|
@ -14,15 +14,28 @@ import (
|
||||
)
|
||||
|
||||
type Native struct {
|
||||
}
|
||||
|
||||
func (n Native) Items() []Item {
|
||||
return []Item{
|
||||
{
|
||||
Name: "root_folder",
|
||||
Label: "root folder path",
|
||||
Type: "string",
|
||||
Required: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (n Native) Proxy(ctx *fiber.Ctx) {
|
||||
panic("implement me")
|
||||
// unnecessary
|
||||
}
|
||||
|
||||
func (n Native) Save(account *model.Account, old *model.Account) error {
|
||||
log.Debugf("save a account: [%s]", account.Name)
|
||||
if !utils.Exists(account.RootFolder) {
|
||||
return fmt.Errorf("[%s] not exist", account.RootFolder)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,7 @@ func Down(ctx *fiber.Ctx) error {
|
||||
if err != nil {
|
||||
return ErrorResp(ctx, err, 500)
|
||||
}
|
||||
if account.Type == "native" {
|
||||
if account.Type == "Native" {
|
||||
return ctx.SendFile(link)
|
||||
} else {
|
||||
return ctx.Redirect(link, 302)
|
||||
@ -49,7 +49,7 @@ func Proxy(ctx *fiber.Ctx) error {
|
||||
if err != nil {
|
||||
return ErrorResp(ctx, err, 500)
|
||||
}
|
||||
if account.Type == "native" {
|
||||
if account.Type == "Native" {
|
||||
return ctx.SendFile(link)
|
||||
} else {
|
||||
driver.Proxy(ctx)
|
||||
|
@ -6,5 +6,5 @@ import (
|
||||
)
|
||||
|
||||
func GetDrivers(ctx *fiber.Ctx) error {
|
||||
return SuccessResp(ctx, drivers.GetDriverNames())
|
||||
return SuccessResp(ctx, drivers.GetDrivers())
|
||||
}
|
Reference in New Issue
Block a user