✨ guide
This commit is contained in:
parent
f4969560d4
commit
57ad66b43a
@ -16,6 +16,7 @@ import (
|
|||||||
var aliClient = resty.New()
|
var aliClient = resty.New()
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
RegisterDriver("AliDrive", &AliDrive{})
|
||||||
aliClient.
|
aliClient.
|
||||||
SetRetryCount(3).
|
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").
|
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")
|
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) {
|
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 {
|
if old != nil {
|
||||||
conf.Cron.Remove(cron.EntryID(old.CronId))
|
conf.Cron.Remove(cron.EntryID(old.CronId))
|
||||||
}
|
}
|
||||||
|
if account.RootFolder == "" {
|
||||||
|
account.RootFolder = "root"
|
||||||
|
}
|
||||||
refresh, access, err := AliRefreshToken(account.RefreshToken)
|
refresh, access, err := AliRefreshToken(account.RefreshToken)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -260,7 +280,3 @@ func (a AliDrive) Save(account *model.Account, old *model.Account) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var _ Driver = (*AliDrive)(nil)
|
var _ Driver = (*AliDrive)(nil)
|
||||||
|
|
||||||
func init() {
|
|
||||||
RegisterDriver("AliDrive", &AliDrive{})
|
|
||||||
}
|
|
||||||
|
@ -7,10 +7,24 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Driver interface {
|
type Driver interface {
|
||||||
|
Items() []Item
|
||||||
Path(path string, account *model.Account) (*model.File, []*model.File, error)
|
Path(path string, account *model.Account) (*model.File, []*model.File, error)
|
||||||
Link(path string, account *model.Account) (string, error)
|
Link(path string, account *model.Account) (string, error)
|
||||||
Save(account *model.Account, old *model.Account) error
|
Save(account *model.Account, old *model.Account) error
|
||||||
Proxy(ctx *fiber.Ctx)
|
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{}
|
var driversMap = map[string]Driver{}
|
||||||
@ -24,12 +38,12 @@ func GetDriver(name string) (driver Driver, ok bool) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetDriverNames() []string {
|
func GetDrivers() map[string][]Item {
|
||||||
names := make([]string, 0)
|
res := make(map[string][]Item, 0)
|
||||||
for k, _ := range driversMap {
|
for k, v := range driversMap {
|
||||||
names = append(names, k)
|
res[k] = v.Items()
|
||||||
}
|
}
|
||||||
return names
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
type Json map[string]interface{}
|
type Json map[string]interface{}
|
||||||
|
@ -14,15 +14,28 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Native struct {
|
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) {
|
func (n Native) Proxy(ctx *fiber.Ctx) {
|
||||||
panic("implement me")
|
// unnecessary
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n Native) Save(account *model.Account, old *model.Account) error {
|
func (n Native) Save(account *model.Account, old *model.Account) error {
|
||||||
log.Debugf("save a account: [%s]", account.Name)
|
log.Debugf("save a account: [%s]", account.Name)
|
||||||
|
if !utils.Exists(account.RootFolder) {
|
||||||
|
return fmt.Errorf("[%s] not exist", account.RootFolder)
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ func Down(ctx *fiber.Ctx) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return ErrorResp(ctx, err, 500)
|
return ErrorResp(ctx, err, 500)
|
||||||
}
|
}
|
||||||
if account.Type == "native" {
|
if account.Type == "Native" {
|
||||||
return ctx.SendFile(link)
|
return ctx.SendFile(link)
|
||||||
} else {
|
} else {
|
||||||
return ctx.Redirect(link, 302)
|
return ctx.Redirect(link, 302)
|
||||||
@ -49,7 +49,7 @@ func Proxy(ctx *fiber.Ctx) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return ErrorResp(ctx, err, 500)
|
return ErrorResp(ctx, err, 500)
|
||||||
}
|
}
|
||||||
if account.Type == "native" {
|
if account.Type == "Native" {
|
||||||
return ctx.SendFile(link)
|
return ctx.SendFile(link)
|
||||||
} else {
|
} else {
|
||||||
driver.Proxy(ctx)
|
driver.Proxy(ctx)
|
||||||
|
@ -6,5 +6,5 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func GetDrivers(ctx *fiber.Ctx) error {
|
func GetDrivers(ctx *fiber.Ctx) error {
|
||||||
return SuccessResp(ctx, drivers.GetDriverNames())
|
return SuccessResp(ctx, drivers.GetDrivers())
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user