🎨 Improve the code structure

pull/548/head
微凉 2021-12-06 15:55:05 +08:00
parent 7dfe48339c
commit 1779617cb9
24 changed files with 212 additions and 181 deletions

View File

@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"github.com/Xhofe/alist/bootstrap" "github.com/Xhofe/alist/bootstrap"
"github.com/Xhofe/alist/conf" "github.com/Xhofe/alist/conf"
_ "github.com/Xhofe/alist/drivers"
"github.com/Xhofe/alist/model" "github.com/Xhofe/alist/model"
"github.com/Xhofe/alist/server" "github.com/Xhofe/alist/server"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
@ -20,7 +21,7 @@ func init() {
} }
func Init() bool { func Init() bool {
bootstrap.InitLog() //bootstrap.InitLog()
bootstrap.InitConf() bootstrap.InitConf()
bootstrap.InitCron() bootstrap.InitCron()
bootstrap.InitModel() bootstrap.InitModel()

View File

@ -2,7 +2,7 @@ package bootstrap
import ( import (
"github.com/Xhofe/alist/conf" "github.com/Xhofe/alist/conf"
"github.com/Xhofe/alist/drivers" "github.com/Xhofe/alist/drivers/base"
"github.com/Xhofe/alist/model" "github.com/Xhofe/alist/model"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
@ -15,7 +15,7 @@ func InitAccounts() {
} }
for i, account := range accounts { for i, account := range accounts {
model.RegisterAccount(account) model.RegisterAccount(account)
driver, ok := drivers.GetDriver(account.Type) driver, ok := base.GetDriver(account.Type)
if !ok { if !ok {
log.Errorf("no [%s] driver", account.Type) log.Errorf("no [%s] driver", account.Type)
} else { } else {

View File

@ -20,3 +20,7 @@ func InitLog() {
}) })
log.Infof("init log...") log.Infof("init log...")
} }
func init() {
InitLog()
}

View File

@ -1,8 +1,9 @@
package drivers package _23
import ( import (
"fmt" "fmt"
"github.com/Xhofe/alist/conf" "github.com/Xhofe/alist/conf"
"github.com/Xhofe/alist/drivers/base"
"github.com/Xhofe/alist/model" "github.com/Xhofe/alist/model"
"github.com/Xhofe/alist/utils" "github.com/Xhofe/alist/utils"
"github.com/go-resty/resty/v2" "github.com/go-resty/resty/v2"
@ -52,7 +53,7 @@ func (driver Pan123) Login(account *model.Account) error {
var resp Pan123TokenResp var resp Pan123TokenResp
_, err := pan123Client.R(). _, err := pan123Client.R().
SetResult(&resp). SetResult(&resp).
SetBody(Json{ SetBody(base.Json{
"passport": account.Username, "passport": account.Username,
"password": account.Password, "password": account.Password,
}).Post("https://www.123pan.com/api/user/sign_in") }).Post("https://www.123pan.com/api/user/sign_in")
@ -135,14 +136,14 @@ func (driver Pan123) GetFile(path string, account *model.Account) (*Pan123File,
if file.Type != conf.FOLDER { if file.Type != conf.FOLDER {
return &file, err return &file, err
} else { } else {
return nil, ErrNotFile return nil, base.ErrNotFile
} }
} }
} }
return nil, ErrPathNotFound return nil, base.ErrPathNotFound
} }
func init() { func init() {
RegisterDriver(&Pan123{}) base.RegisterDriver(&Pan123{})
pan123Client.SetRetryCount(3) pan123Client.SetRetryCount(3)
} }

View File

@ -1,8 +1,9 @@
package drivers package _23
import ( import (
"fmt" "fmt"
"github.com/Xhofe/alist/conf" "github.com/Xhofe/alist/conf"
"github.com/Xhofe/alist/drivers/base"
"github.com/Xhofe/alist/model" "github.com/Xhofe/alist/model"
"github.com/Xhofe/alist/utils" "github.com/Xhofe/alist/utils"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
@ -13,46 +14,46 @@ import (
type Pan123 struct {} type Pan123 struct {}
func (driver Pan123) Config() DriverConfig { func (driver Pan123) Config() base.DriverConfig {
return DriverConfig{ return base.DriverConfig{
Name: "123Pan", Name: "123Pan",
OnlyProxy: false, OnlyProxy: false,
} }
} }
func (driver Pan123) Items() []Item { func (driver Pan123) Items() []base.Item {
return []Item{ return []base.Item{
{ {
Name: "username", Name: "username",
Label: "username", Label: "username",
Type: TypeString, Type: base.TypeString,
Required: true, Required: true,
Description: "account username/phone number", Description: "account username/phone number",
}, },
{ {
Name: "password", Name: "password",
Label: "password", Label: "password",
Type: TypeString, Type: base.TypeString,
Required: true, Required: true,
Description: "account password", Description: "account password",
}, },
{ {
Name: "root_folder", Name: "root_folder",
Label: "root folder file_id", Label: "root folder file_id",
Type: TypeString, Type: base.TypeString,
Required: false, Required: false,
}, },
{ {
Name: "order_by", Name: "order_by",
Label: "order_by", Label: "order_by",
Type: TypeSelect, Type: base.TypeSelect,
Values: "name,fileId,updateAt,createAt", Values: "name,fileId,updateAt,createAt",
Required: true, Required: true,
}, },
{ {
Name: "order_direction", Name: "order_direction",
Label: "order_direction", Label: "order_direction",
Type: TypeSelect, Type: base.TypeSelect,
Values: "asc,desc", Values: "asc,desc",
Required: true, Required: true,
}, },
@ -89,7 +90,7 @@ func (driver Pan123) File(path string, account *model.Account) (*model.File, err
return &file, nil return &file, nil
} }
} }
return nil, ErrPathNotFound return nil, base.ErrPathNotFound
} }
func (driver Pan123) Files(path string, account *model.Account) ([]model.File, error) { func (driver Pan123) Files(path string, account *model.Account) ([]model.File, error) {
@ -125,7 +126,7 @@ func (driver Pan123) Link(path string, account *model.Account) (string, error) {
} }
var resp Pan123DownResp var resp Pan123DownResp
_, err = pan123Client.R().SetResult(&resp).SetHeader("authorization", "Bearer "+account.AccessToken). _, err = pan123Client.R().SetResult(&resp).SetHeader("authorization", "Bearer "+account.AccessToken).
SetBody(Json{ SetBody(base.Json{
"driveId": 0, "driveId": 0,
"etag": file.Etag, "etag": file.Etag,
"fileId": file.FileId, "fileId": file.FileId,
@ -152,7 +153,7 @@ func (driver Pan123) Link(path string, account *model.Account) (string, error) {
return "", err return "", err
} }
u_ := fmt.Sprintf("https://%s%s",u.Host,u.Path) u_ := fmt.Sprintf("https://%s%s",u.Host,u.Path)
res, err := NoRedirectClient.R().SetQueryParamsFromValues(u.Query()).Get(u_) res, err := base.NoRedirectClient.R().SetQueryParamsFromValues(u.Query()).Get(u_)
if err != nil { if err != nil {
return "", err return "", err
} }
@ -186,27 +187,27 @@ func (driver Pan123) Proxy(c *gin.Context, account *model.Account) {
} }
func (driver Pan123) Preview(path string, account *model.Account) (interface{}, error) { func (driver Pan123) Preview(path string, account *model.Account) (interface{}, error) {
return nil, ErrNotSupport return nil, base.ErrNotSupport
} }
func (driver Pan123) MakeDir(path string, account *model.Account) error { func (driver Pan123) MakeDir(path string, account *model.Account) error {
return ErrNotImplement return base.ErrNotImplement
} }
func (driver Pan123) Move(src string, dst string, account *model.Account) error { func (driver Pan123) Move(src string, dst string, account *model.Account) error {
return ErrNotImplement return base.ErrNotImplement
} }
func (driver Pan123) Copy(src string, dst string, account *model.Account) error { func (driver Pan123) Copy(src string, dst string, account *model.Account) error {
return ErrNotImplement return base.ErrNotImplement
} }
func (driver Pan123) Delete(path string, account *model.Account) error { func (driver Pan123) Delete(path string, account *model.Account) error {
return ErrNotImplement return base.ErrNotImplement
} }
func (driver Pan123) Upload(file *model.FileStream, account *model.Account) error { func (driver Pan123) Upload(file *model.FileStream, account *model.Account) error {
return ErrNotImplement return base.ErrNotImplement
} }
var _ Driver = (*Pan123)(nil) var _ base.Driver = (*Pan123)(nil)

View File

@ -1,4 +1,4 @@
package drivers package _89
import ( import (
"crypto/rand" "crypto/rand"
@ -9,6 +9,7 @@ import (
"encoding/pem" "encoding/pem"
"fmt" "fmt"
"github.com/Xhofe/alist/conf" "github.com/Xhofe/alist/conf"
"github.com/Xhofe/alist/drivers/base"
"github.com/Xhofe/alist/model" "github.com/Xhofe/alist/model"
"github.com/Xhofe/alist/utils" "github.com/Xhofe/alist/utils"
"github.com/go-resty/resty/v2" "github.com/go-resty/resty/v2"
@ -312,6 +313,6 @@ func b64tohex(a string) string {
} }
func init() { func init() {
RegisterDriver(&Cloud189{}) base.RegisterDriver(&Cloud189{})
client189Map = make(map[string]*resty.Client, 0) client189Map = make(map[string]*resty.Client, 0)
} }

View File

@ -1,8 +1,9 @@
package drivers package _89
import ( import (
"fmt" "fmt"
"github.com/Xhofe/alist/conf" "github.com/Xhofe/alist/conf"
"github.com/Xhofe/alist/drivers/base"
"github.com/Xhofe/alist/model" "github.com/Xhofe/alist/model"
"github.com/Xhofe/alist/utils" "github.com/Xhofe/alist/utils"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
@ -12,46 +13,46 @@ import (
type Cloud189 struct {} type Cloud189 struct {}
func (driver Cloud189) Config() DriverConfig { func (driver Cloud189) Config() base.DriverConfig {
return DriverConfig{ return base.DriverConfig{
Name: "189Cloud", Name: "189Cloud",
OnlyProxy: false, OnlyProxy: false,
} }
} }
func (driver Cloud189) Items() []Item { func (driver Cloud189) Items() []base.Item {
return []Item{ return []base.Item{
{ {
Name: "username", Name: "username",
Label: "username", Label: "username",
Type: TypeString, Type: base.TypeString,
Required: true, Required: true,
Description: "account username/phone number", Description: "account username/phone number",
}, },
{ {
Name: "password", Name: "password",
Label: "password", Label: "password",
Type: TypeString, Type: base.TypeString,
Required: true, Required: true,
Description: "account password", Description: "account password",
}, },
{ {
Name: "root_folder", Name: "root_folder",
Label: "root folder file_id", Label: "root folder file_id",
Type: TypeString, Type: base.TypeString,
Required: true, Required: true,
}, },
{ {
Name: "order_by", Name: "order_by",
Label: "order_by", Label: "order_by",
Type: TypeSelect, Type: base.TypeSelect,
Values: "name,size,lastOpTime,createdDate", Values: "name,size,lastOpTime,createdDate",
Required: true, Required: true,
}, },
{ {
Name: "order_direction", Name: "order_direction",
Label: "desc", Label: "desc",
Type: TypeSelect, Type: base.TypeSelect,
Values: "true,false", Values: "true,false",
Required: true, Required: true,
}, },
@ -97,7 +98,7 @@ func (driver Cloud189) File(path string, account *model.Account) (*model.File, e
return &file, nil return &file, nil
} }
} }
return nil, ErrPathNotFound return nil, base.ErrPathNotFound
} }
func (driver Cloud189) Files(path string, account *model.Account) ([]model.File, error) { func (driver Cloud189) Files(path string, account *model.Account) ([]model.File, error) {
@ -132,7 +133,7 @@ func (driver Cloud189) Link(path string, account *model.Account) (string, error)
return "", err return "", err
} }
if file.Type == conf.FOLDER { if file.Type == conf.FOLDER {
return "", ErrNotFile return "", base.ErrNotFile
} }
client, ok := client189Map[account.Name] client, ok := client189Map[account.Name]
if !ok { if !ok {
@ -161,7 +162,7 @@ func (driver Cloud189) Link(path string, account *model.Account) (string, error)
if resp.ResCode != 0 { if resp.ResCode != 0 {
return "", fmt.Errorf(resp.ResMessage) return "", fmt.Errorf(resp.ResMessage)
} }
res, err := NoRedirectClient.R().Get(resp.FileDownloadUrl) res, err := base.NoRedirectClient.R().Get(resp.FileDownloadUrl)
if err != nil { if err != nil {
return "", err return "", err
} }
@ -194,28 +195,28 @@ func (driver Cloud189) Proxy(ctx *gin.Context, account *model.Account) {
} }
func (driver Cloud189) Preview(path string, account *model.Account) (interface{}, error) { func (driver Cloud189) Preview(path string, account *model.Account) (interface{}, error) {
return nil, ErrNotSupport return nil, base.ErrNotSupport
} }
func (driver Cloud189) MakeDir(path string, account *model.Account) error { func (driver Cloud189) MakeDir(path string, account *model.Account) error {
return ErrNotImplement return base.ErrNotImplement
} }
func (driver Cloud189) Move(src string, dst string, account *model.Account) error { func (driver Cloud189) Move(src string, dst string, account *model.Account) error {
return ErrNotImplement return base.ErrNotImplement
} }
func (driver Cloud189) Copy(src string, dst string, account *model.Account) error { func (driver Cloud189) Copy(src string, dst string, account *model.Account) error {
return ErrNotImplement return base.ErrNotImplement
} }
func (driver Cloud189) Delete(path string, account *model.Account) error { func (driver Cloud189) Delete(path string, account *model.Account) error {
return ErrNotImplement return base.ErrNotImplement
} }
func (driver Cloud189) Upload(file *model.FileStream, account *model.Account) error { func (driver Cloud189) Upload(file *model.FileStream, account *model.Account) error {
return ErrNotImplement return base.ErrNotImplement
} }
var _ Driver = (*Cloud189)(nil) var _ base.Driver = (*Cloud189)(nil)

View File

@ -1,8 +1,9 @@
package drivers package alidrive
import ( import (
"fmt" "fmt"
"github.com/Xhofe/alist/conf" "github.com/Xhofe/alist/conf"
"github.com/Xhofe/alist/drivers/base"
"github.com/Xhofe/alist/model" "github.com/Xhofe/alist/model"
"github.com/Xhofe/alist/utils" "github.com/Xhofe/alist/utils"
"github.com/go-resty/resty/v2" "github.com/go-resty/resty/v2"
@ -75,7 +76,7 @@ func (driver AliDrive) GetFiles(fileId string, account *model.Account) ([]AliFil
SetResult(&resp). SetResult(&resp).
SetError(&e). SetError(&e).
SetHeader("authorization", "Bearer\t"+account.AccessToken). SetHeader("authorization", "Bearer\t"+account.AccessToken).
SetBody(Json{ SetBody(base.Json{
"drive_id": account.DriveId, "drive_id": account.DriveId,
"fields": "*", "fields": "*",
"image_thumbnail_process": "image/resize,w_400/format,jpeg", "image_thumbnail_process": "image/resize,w_400/format,jpeg",
@ -127,16 +128,16 @@ func (driver AliDrive) GetFile(path string, account *model.Account) (*AliFile, e
} }
} }
} }
return nil, ErrPathNotFound return nil, base.ErrPathNotFound
} }
func (driver AliDrive) RefreshToken(account *model.Account) error { func (driver AliDrive) RefreshToken(account *model.Account) error {
url := "https://auth.aliyundrive.com/v2/account/token" url := "https://auth.aliyundrive.com/v2/account/token"
var resp TokenResp var resp base.TokenResp
var e AliRespError var e AliRespError
_, err := aliClient.R(). _, err := aliClient.R().
//ForceContentType("application/json"). //ForceContentType("application/json").
SetBody(Json{"refresh_token": account.RefreshToken, "grant_type": "refresh_token"}). SetBody(base.Json{"refresh_token": account.RefreshToken, "grant_type": "refresh_token"}).
SetResult(&resp). SetResult(&resp).
SetError(&e). SetError(&e).
Post(url) Post(url)
@ -156,7 +157,7 @@ func (driver AliDrive) RefreshToken(account *model.Account) error {
} }
func init() { func init() {
RegisterDriver(&AliDrive{}) base.RegisterDriver(&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").

View File

@ -1,8 +1,9 @@
package drivers package alidrive
import ( import (
"fmt" "fmt"
"github.com/Xhofe/alist/conf" "github.com/Xhofe/alist/conf"
"github.com/Xhofe/alist/drivers/base"
"github.com/Xhofe/alist/model" "github.com/Xhofe/alist/model"
"github.com/Xhofe/alist/utils" "github.com/Xhofe/alist/utils"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
@ -13,45 +14,45 @@ import (
type AliDrive struct{} type AliDrive struct{}
func (driver AliDrive) Config() DriverConfig { func (driver AliDrive) Config() base.DriverConfig {
return DriverConfig{ return base.DriverConfig{
Name: "AliDrive", Name: "AliDrive",
OnlyProxy: false, OnlyProxy: false,
} }
} }
func (driver AliDrive) Items() []Item { func (driver AliDrive) Items() []base.Item {
return []Item{ return []base.Item{
{ {
Name: "order_by", Name: "order_by",
Label: "order_by", Label: "order_by",
Type: TypeSelect, Type: base.TypeSelect,
Values: "name,size,updated_at,created_at", Values: "name,size,updated_at,created_at",
Required: false, Required: false,
}, },
{ {
Name: "order_direction", Name: "order_direction",
Label: "order_direction", Label: "order_direction",
Type: TypeSelect, Type: base.TypeSelect,
Values: "ASC,DESC", Values: "ASC,DESC",
Required: false, Required: false,
}, },
{ {
Name: "refresh_token", Name: "refresh_token",
Label: "refresh token", Label: "refresh token",
Type: TypeString, Type: base.TypeString,
Required: true, Required: true,
}, },
{ {
Name: "root_folder", Name: "root_folder",
Label: "root folder file_id", Label: "root folder file_id",
Type: TypeString, Type: base.TypeString,
Required: false, Required: false,
}, },
{ {
Name: "limit", Name: "limit",
Label: "limit", Label: "limit",
Type: TypeNumber, Type: base.TypeNumber,
Required: false, Required: false,
Description: ">0 and <=200", Description: ">0 and <=200",
}, },
@ -72,7 +73,7 @@ func (driver AliDrive) Save(account *model.Account, old *model.Account) error {
if err != nil { if err != nil {
return err return err
} }
var resp Json var resp base.Json
_, _ = aliClient.R().SetResult(&resp). _, _ = aliClient.R().SetResult(&resp).
SetBody("{}"). SetBody("{}").
SetHeader("authorization", "Bearer\t"+account.AccessToken). SetHeader("authorization", "Bearer\t"+account.AccessToken).
@ -123,7 +124,7 @@ func (driver AliDrive) File(path string, account *model.Account) (*model.File, e
return &file, nil return &file, nil
} }
} }
return nil, ErrPathNotFound return nil, base.ErrPathNotFound
} }
func (driver AliDrive) Files(path string, account *model.Account) ([]model.File, error) { func (driver AliDrive) Files(path string, account *model.Account) ([]model.File, error) {
@ -157,12 +158,12 @@ func (driver AliDrive) Link(path string, account *model.Account) (string, error)
if err != nil { if err != nil {
return "", err return "", err
} }
var resp Json var resp base.Json
var e AliRespError var e AliRespError
_, err = aliClient.R().SetResult(&resp). _, err = aliClient.R().SetResult(&resp).
SetError(&e). SetError(&e).
SetHeader("authorization", "Bearer\t"+account.AccessToken). SetHeader("authorization", "Bearer\t"+account.AccessToken).
SetBody(Json{ SetBody(base.Json{
"drive_id": account.DriveId, "drive_id": account.DriveId,
"file_id": file.Id, "file_id": file.Id,
"expire_sec": 14400, "expire_sec": 14400,
@ -214,10 +215,10 @@ func (driver AliDrive) Preview(path string, account *model.Account) (interface{}
return nil, err return nil, err
} }
// office // office
var resp Json var resp base.Json
var e AliRespError var e AliRespError
var url string var url string
req := Json{ req := base.Json{
"drive_id": account.DriveId, "drive_id": account.DriveId,
"file_id": file.FileId, "file_id": file.FileId,
} }
@ -233,7 +234,7 @@ func (driver AliDrive) Preview(path string, account *model.Account) (interface{}
req["category"] = "live_transcoding" req["category"] = "live_transcoding"
} }
default: default:
return nil, ErrNotSupport return nil, base.ErrNotSupport
} }
_, err = aliClient.R().SetResult(&resp).SetError(&e). _, err = aliClient.R().SetResult(&resp).SetError(&e).
SetHeader("authorization", "Bearer\t"+account.AccessToken). SetHeader("authorization", "Bearer\t"+account.AccessToken).
@ -248,23 +249,23 @@ func (driver AliDrive) Preview(path string, account *model.Account) (interface{}
} }
func (driver AliDrive) MakeDir(path string, account *model.Account) error { func (driver AliDrive) MakeDir(path string, account *model.Account) error {
return ErrNotImplement return base.ErrNotImplement
} }
func (driver AliDrive) Move(src string, dst string, account *model.Account) error { func (driver AliDrive) Move(src string, dst string, account *model.Account) error {
return ErrNotImplement return base.ErrNotImplement
} }
func (driver AliDrive) Copy(src string, dst string, account *model.Account) error { func (driver AliDrive) Copy(src string, dst string, account *model.Account) error {
return ErrNotImplement return base.ErrNotImplement
} }
func (driver AliDrive) Delete(path string, account *model.Account) error { func (driver AliDrive) Delete(path string, account *model.Account) error {
return ErrNotImplement return base.ErrNotImplement
} }
func (driver AliDrive) Upload(file *model.FileStream, account *model.Account) error { func (driver AliDrive) Upload(file *model.FileStream, account *model.Account) error {
return ErrNotImplement return base.ErrNotImplement
} }
var _ Driver = (*AliDrive)(nil) var _ base.Driver = (*AliDrive)(nil)

11
drivers/all.go Normal file
View File

@ -0,0 +1,11 @@
package drivers
import (
_ "github.com/Xhofe/alist/drivers/123"
_ "github.com/Xhofe/alist/drivers/189"
_ "github.com/Xhofe/alist/drivers/alidrive"
_ "github.com/Xhofe/alist/drivers/google"
_ "github.com/Xhofe/alist/drivers/lanzou"
_ "github.com/Xhofe/alist/drivers/native"
_ "github.com/Xhofe/alist/drivers/onedrive"
)

View File

@ -1,9 +1,10 @@
package drivers package base
import ( import (
"github.com/Xhofe/alist/model" "github.com/Xhofe/alist/model"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/go-resty/resty/v2" "github.com/go-resty/resty/v2"
log "github.com/sirupsen/logrus"
"net/http" "net/http"
) )
@ -48,7 +49,7 @@ type TokenResp struct {
var driversMap = map[string]Driver{} var driversMap = map[string]Driver{}
func RegisterDriver(driver Driver) { func RegisterDriver(driver Driver) {
//log.Infof("register driver: [%s]", driver.Config().Name) log.Infof("register driver: [%s]", driver.Config().Name)
driversMap[driver.Config().Name] = driver driversMap[driver.Config().Name] = driver
} }

View File

@ -1,4 +1,4 @@
package drivers package base
import "fmt" import "fmt"

View File

@ -1,8 +1,9 @@
package drivers package google
import ( import (
"fmt" "fmt"
"github.com/Xhofe/alist/conf" "github.com/Xhofe/alist/conf"
"github.com/Xhofe/alist/drivers/base"
"github.com/Xhofe/alist/model" "github.com/Xhofe/alist/model"
"github.com/Xhofe/alist/utils" "github.com/Xhofe/alist/utils"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
@ -12,37 +13,37 @@ import (
type GoogleDrive struct{} type GoogleDrive struct{}
func (driver GoogleDrive) Config() DriverConfig { func (driver GoogleDrive) Config() base.DriverConfig {
return DriverConfig{ return base.DriverConfig{
Name: "GoogleDrive", Name: "GoogleDrive",
OnlyProxy: true, OnlyProxy: true,
} }
} }
func (driver GoogleDrive) Items() []Item { func (driver GoogleDrive) Items() []base.Item {
return []Item{ return []base.Item{
{ {
Name: "client_id", Name: "client_id",
Label: "client id", Label: "client id",
Type: TypeString, Type: base.TypeString,
Required: true, Required: true,
}, },
{ {
Name: "client_secret", Name: "client_secret",
Label: "client secret", Label: "client secret",
Type: TypeString, Type: base.TypeString,
Required: true, Required: true,
}, },
{ {
Name: "refresh_token", Name: "refresh_token",
Label: "refresh token", Label: "refresh token",
Type: TypeString, Type: base.TypeString,
Required: true, Required: true,
}, },
{ {
Name: "root_folder", Name: "root_folder",
Label: "root folder file_id", Label: "root folder file_id",
Type: TypeString, Type: base.TypeString,
Required: false, Required: false,
}, },
} }
@ -86,7 +87,7 @@ func (driver GoogleDrive) File(path string, account *model.Account) (*model.File
return &file, nil return &file, nil
} }
} }
return nil, ErrPathNotFound return nil, base.ErrPathNotFound
} }
func (driver GoogleDrive) Files(path string, account *model.Account) ([]model.File, error) { func (driver GoogleDrive) Files(path string, account *model.Account) ([]model.File, error) {
@ -121,7 +122,7 @@ func (driver GoogleDrive) Link(path string, account *model.Account) (string, err
return "", err return "", err
} }
if file.Type == conf.FOLDER { if file.Type == conf.FOLDER {
return "", ErrNotFile return "", base.ErrNotFile
} }
link := fmt.Sprintf("https://www.googleapis.com/drive/v3/files/%s?includeItemsFromAllDrives=true&supportsAllDrives=true", file.Id) link := fmt.Sprintf("https://www.googleapis.com/drive/v3/files/%s?includeItemsFromAllDrives=true&supportsAllDrives=true", file.Id)
var e GoogleError var e GoogleError
@ -165,27 +166,27 @@ func (driver GoogleDrive) Proxy(c *gin.Context, account *model.Account) {
} }
func (driver GoogleDrive) Preview(path string, account *model.Account) (interface{}, error) { func (driver GoogleDrive) Preview(path string, account *model.Account) (interface{}, error) {
return nil, ErrNotSupport return nil, base.ErrNotSupport
} }
func (driver GoogleDrive) MakeDir(path string, account *model.Account) error { func (driver GoogleDrive) MakeDir(path string, account *model.Account) error {
return ErrNotImplement return base.ErrNotImplement
} }
func (driver GoogleDrive) Move(src string, dst string, account *model.Account) error { func (driver GoogleDrive) Move(src string, dst string, account *model.Account) error {
return ErrNotImplement return base.ErrNotImplement
} }
func (driver GoogleDrive) Copy(src string, dst string, account *model.Account) error { func (driver GoogleDrive) Copy(src string, dst string, account *model.Account) error {
return ErrNotImplement return base.ErrNotImplement
} }
func (driver GoogleDrive) Delete(path string, account *model.Account) error { func (driver GoogleDrive) Delete(path string, account *model.Account) error {
return ErrNotImplement return base.ErrNotImplement
} }
func (driver GoogleDrive) Upload(file *model.FileStream, account *model.Account) error { func (driver GoogleDrive) Upload(file *model.FileStream, account *model.Account) error {
return ErrNotImplement return base.ErrNotImplement
} }
var _ Driver = (*GoogleDrive)(nil) var _ base.Driver = (*GoogleDrive)(nil)

View File

@ -1,8 +1,9 @@
package drivers package google
import ( import (
"fmt" "fmt"
"github.com/Xhofe/alist/conf" "github.com/Xhofe/alist/conf"
"github.com/Xhofe/alist/drivers/base"
"github.com/Xhofe/alist/model" "github.com/Xhofe/alist/model"
"github.com/Xhofe/alist/utils" "github.com/Xhofe/alist/utils"
"github.com/go-resty/resty/v2" "github.com/go-resty/resty/v2"
@ -20,7 +21,7 @@ type GoogleTokenError struct {
func (driver GoogleDrive) RefreshToken(account *model.Account) error { func (driver GoogleDrive) RefreshToken(account *model.Account) error {
url := "https://www.googleapis.com/oauth2/v4/token" url := "https://www.googleapis.com/oauth2/v4/token"
var resp TokenResp var resp base.TokenResp
var e GoogleTokenError var e GoogleTokenError
_, err := googleClient.R().SetResult(&resp).SetError(&e). _, err := googleClient.R().SetResult(&resp).SetError(&e).
SetFormData(map[string]string{ SetFormData(map[string]string{
@ -152,6 +153,6 @@ func (driver GoogleDrive) GetFiles(id string, account *model.Account) ([]GoogleF
//} //}
func init() { func init() {
RegisterDriver(&GoogleDrive{}) base.RegisterDriver(&GoogleDrive{})
googleClient.SetRetryCount(3) googleClient.SetRetryCount(3)
} }

View File

@ -1,8 +1,9 @@
package drivers package lanzou
import ( import (
"fmt" "fmt"
"github.com/Xhofe/alist/conf" "github.com/Xhofe/alist/conf"
"github.com/Xhofe/alist/drivers/base"
"github.com/Xhofe/alist/model" "github.com/Xhofe/alist/model"
"github.com/Xhofe/alist/utils" "github.com/Xhofe/alist/utils"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
@ -12,42 +13,42 @@ import (
type Lanzou struct{} type Lanzou struct{}
func (driver Lanzou) Config() DriverConfig { func (driver Lanzou) Config() base.DriverConfig {
return DriverConfig{ return base.DriverConfig{
Name: "Lanzou", Name: "Lanzou",
OnlyProxy: false, OnlyProxy: false,
} }
} }
func (driver Lanzou) Items() []Item { func (driver Lanzou) Items() []base.Item {
return []Item{ return []base.Item{
{ {
Name: "onedrive_type", Name: "onedrive_type",
Label: "lanzou type", Label: "lanzou type",
Type: TypeSelect, Type: base.TypeSelect,
Required: true, Required: true,
Values: "cookie,url", Values: "cookie,url",
}, },
{ {
Name: "access_token", Name: "access_token",
Label: "cookie", Label: "cookie",
Type: TypeString, Type: base.TypeString,
Description: "about 15 days valid", Description: "about 15 days valid",
}, },
{ {
Name: "root_folder", Name: "root_folder",
Label: "root folder file_id", Label: "root folder file_id",
Type: TypeString, Type: base.TypeString,
}, },
{ {
Name: "site_url", Name: "site_url",
Label: "share url", Label: "share url",
Type: TypeString, Type: base.TypeString,
}, },
{ {
Name: "password", Name: "password",
Label: "share password", Label: "share password",
Type: TypeString, Type: base.TypeString,
}, },
} }
} }
@ -85,7 +86,7 @@ func (driver Lanzou) File(path string, account *model.Account) (*model.File, err
return &file, nil return &file, nil
} }
} }
return nil, ErrPathNotFound return nil, base.ErrPathNotFound
} }
func (driver Lanzou) Files(path string, account *model.Account) ([]model.File, error) { func (driver Lanzou) Files(path string, account *model.Account) ([]model.File, error) {
@ -157,27 +158,27 @@ func (driver Lanzou) Proxy(c *gin.Context, account *model.Account) {
} }
func (driver Lanzou) Preview(path string, account *model.Account) (interface{}, error) { func (driver Lanzou) Preview(path string, account *model.Account) (interface{}, error) {
return nil, ErrNotSupport return nil, base.ErrNotSupport
} }
func (driver *Lanzou) MakeDir(path string, account *model.Account) error { func (driver *Lanzou) MakeDir(path string, account *model.Account) error {
return ErrNotImplement return base.ErrNotImplement
} }
func (driver *Lanzou) Move(src string, dst string, account *model.Account) error { func (driver *Lanzou) Move(src string, dst string, account *model.Account) error {
return ErrNotImplement return base.ErrNotImplement
} }
func (driver *Lanzou) Copy(src string, dst string, account *model.Account) error { func (driver *Lanzou) Copy(src string, dst string, account *model.Account) error {
return ErrNotImplement return base.ErrNotImplement
} }
func (driver *Lanzou) Delete(path string, account *model.Account) error { func (driver *Lanzou) Delete(path string, account *model.Account) error {
return ErrNotImplement return base.ErrNotImplement
} }
func (driver *Lanzou) Upload(file *model.FileStream, account *model.Account) error { func (driver *Lanzou) Upload(file *model.FileStream, account *model.Account) error {
return ErrNotImplement return base.ErrNotImplement
} }
var _ Driver = (*Lanzou)(nil) var _ base.Driver = (*Lanzou)(nil)

View File

@ -1,8 +1,9 @@
package drivers package lanzou
import ( import (
"fmt" "fmt"
"github.com/Xhofe/alist/conf" "github.com/Xhofe/alist/conf"
"github.com/Xhofe/alist/drivers/base"
"github.com/Xhofe/alist/model" "github.com/Xhofe/alist/model"
"github.com/Xhofe/alist/utils" "github.com/Xhofe/alist/utils"
"github.com/go-resty/resty/v2" "github.com/go-resty/resty/v2"
@ -231,7 +232,7 @@ func (driver *Lanzou) GetLink(downId string) (string, error) {
} }
func init() { func init() {
RegisterDriver(&Lanzou{}) base.RegisterDriver(&Lanzou{})
lanzouClient. lanzouClient.
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")

View File

@ -1,8 +1,9 @@
package drivers package native
import ( import (
"fmt" "fmt"
"github.com/Xhofe/alist/conf" "github.com/Xhofe/alist/conf"
"github.com/Xhofe/alist/drivers/base"
"github.com/Xhofe/alist/model" "github.com/Xhofe/alist/model"
"github.com/Xhofe/alist/utils" "github.com/Xhofe/alist/utils"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
@ -16,32 +17,32 @@ import (
type Native struct{} type Native struct{}
func (driver Native) Config() DriverConfig { func (driver Native) Config() base.DriverConfig {
return DriverConfig{ return base.DriverConfig{
Name: "Native", Name: "Native",
OnlyProxy: true, OnlyProxy: true,
} }
} }
func (driver Native) Items() []Item { func (driver Native) Items() []base.Item {
return []Item{ return []base.Item{
{ {
Name: "root_folder", Name: "root_folder",
Label: "root folder path", Label: "root folder path",
Type: TypeString, Type: base.TypeString,
Required: true, Required: true,
}, },
{ {
Name: "order_by", Name: "order_by",
Label: "order_by", Label: "order_by",
Type: TypeSelect, Type: base.TypeSelect,
Values: "name,size,updated_at", Values: "name,size,updated_at",
Required: false, Required: false,
}, },
{ {
Name: "order_direction", Name: "order_direction",
Label: "order_direction", Label: "order_direction",
Type: TypeSelect, Type: base.TypeSelect,
Values: "ASC,DESC", Values: "ASC,DESC",
Required: false, Required: false,
}, },
@ -67,7 +68,7 @@ func (driver Native) Save(account *model.Account, old *model.Account) error {
func (driver Native) File(path string, account *model.Account) (*model.File, error) { func (driver Native) File(path string, account *model.Account) (*model.File, error) {
fullPath := filepath.Join(account.RootFolder, path) fullPath := filepath.Join(account.RootFolder, path)
if !utils.Exists(fullPath) { if !utils.Exists(fullPath) {
return nil, ErrPathNotFound return nil, base.ErrPathNotFound
} }
f, err := os.Stat(fullPath) f, err := os.Stat(fullPath)
if err != nil { if err != nil {
@ -91,7 +92,7 @@ func (driver Native) File(path string, account *model.Account) (*model.File, err
func (driver Native) Files(path string, account *model.Account) ([]model.File, error) { func (driver Native) Files(path string, account *model.Account) ([]model.File, error) {
fullPath := filepath.Join(account.RootFolder, path) fullPath := filepath.Join(account.RootFolder, path)
if !utils.Exists(fullPath) { if !utils.Exists(fullPath) {
return nil, ErrPathNotFound return nil, base.ErrPathNotFound
} }
files := make([]model.File, 0) files := make([]model.File, 0)
rawFiles, err := ioutil.ReadDir(fullPath) rawFiles, err := ioutil.ReadDir(fullPath)
@ -156,7 +157,7 @@ func (driver Native) Proxy(c *gin.Context, account *model.Account) {
} }
func (driver Native) Preview(path string, account *model.Account) (interface{}, error) { func (driver Native) Preview(path string, account *model.Account) (interface{}, error) {
return nil, ErrNotSupport return nil, base.ErrNotSupport
} }
func (driver Native) MakeDir(path string, account *model.Account) error { func (driver Native) MakeDir(path string, account *model.Account) error {
@ -181,7 +182,7 @@ func (driver Native) Copy(src string, dst string, account *model.Account) error
dstFile, err := driver.File(dst, account) dstFile, err := driver.File(dst, account)
if err == nil { if err == nil {
if !dstFile.IsDir() { if !dstFile.IsDir() {
return ErrNotSupport return base.ErrNotSupport
} }
} }
if srcFile.IsDir() { if srcFile.IsDir() {
@ -226,4 +227,4 @@ func (driver Native) Upload(file *model.FileStream, account *model.Account) erro
return err return err
} }
var _ Driver = (*Native)(nil) var _ base.Driver = (*Native)(nil)

View File

@ -1,7 +1,8 @@
package drivers package native
import ( import (
"fmt" "fmt"
"github.com/Xhofe/alist/drivers/base"
"io" "io"
"io/ioutil" "io/ioutil"
"os" "os"
@ -69,5 +70,5 @@ func (driver *Native) CopyDir(src string, dst string) error {
} }
func init() { func init() {
RegisterDriver(&Native{}) base.RegisterDriver(&Native{})
} }

View File

@ -1,8 +1,9 @@
package drivers package onedrive
import ( import (
"fmt" "fmt"
"github.com/Xhofe/alist/conf" "github.com/Xhofe/alist/conf"
"github.com/Xhofe/alist/drivers/base"
"github.com/Xhofe/alist/model" "github.com/Xhofe/alist/model"
"github.com/Xhofe/alist/utils" "github.com/Xhofe/alist/utils"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
@ -14,19 +15,19 @@ import (
type Onedrive struct{} type Onedrive struct{}
func (driver Onedrive) Config() DriverConfig { func (driver Onedrive) Config() base.DriverConfig {
return DriverConfig{ return base.DriverConfig{
Name: "Onedrive", Name: "Onedrive",
OnlyProxy: false, OnlyProxy: false,
} }
} }
func (driver Onedrive) Items() []Item { func (driver Onedrive) Items() []base.Item {
return []Item{ return []base.Item{
{ {
Name: "zone", Name: "zone",
Label: "zone", Label: "zone",
Type: TypeSelect, Type: base.TypeSelect,
Required: true, Required: true,
Values: "global,cn,us,de", Values: "global,cn,us,de",
Description: "", Description: "",
@ -34,57 +35,57 @@ func (driver Onedrive) Items() []Item {
{ {
Name: "onedrive_type", Name: "onedrive_type",
Label: "onedrive type", Label: "onedrive type",
Type: TypeSelect, Type: base.TypeSelect,
Required: true, Required: true,
Values: "onedrive,sharepoint", Values: "onedrive,sharepoint",
}, },
{ {
Name: "client_id", Name: "client_id",
Label: "client id", Label: "client id",
Type: TypeString, Type: base.TypeString,
Required: true, Required: true,
}, },
{ {
Name: "client_secret", Name: "client_secret",
Label: "client secret", Label: "client secret",
Type: TypeString, Type: base.TypeString,
Required: true, Required: true,
}, },
{ {
Name: "redirect_uri", Name: "redirect_uri",
Label: "redirect uri", Label: "redirect uri",
Type: TypeString, Type: base.TypeString,
Required: true, Required: true,
}, },
{ {
Name: "refresh_token", Name: "refresh_token",
Label: "refresh token", Label: "refresh token",
Type: TypeString, Type: base.TypeString,
Required: true, Required: true,
}, },
{ {
Name: "site_id", Name: "site_id",
Label: "site id", Label: "site id",
Type: TypeString, Type: base.TypeString,
Required: false, Required: false,
}, },
{ {
Name: "root_folder", Name: "root_folder",
Label: "root folder path", Label: "root folder path",
Type: TypeString, Type: base.TypeString,
Required: false, Required: false,
}, },
{ {
Name: "order_by", Name: "order_by",
Label: "order_by", Label: "order_by",
Type: TypeSelect, Type: base.TypeSelect,
Values: "name,size,lastModifiedDateTime", Values: "name,size,lastModifiedDateTime",
Required: false, Required: false,
}, },
{ {
Name: "order_direction", Name: "order_direction",
Label: "order_direction", Label: "order_direction",
Type: TypeSelect, Type: base.TypeSelect,
Values: "asc,desc", Values: "asc,desc",
Required: false, Required: false,
}, },
@ -148,7 +149,7 @@ func (driver Onedrive) File(path string, account *model.Account) (*model.File, e
return &file, nil return &file, nil
} }
} }
return nil, ErrPathNotFound return nil, base.ErrPathNotFound
} }
func (driver Onedrive) Files(path string, account *model.Account) ([]model.File, error) { func (driver Onedrive) Files(path string, account *model.Account) ([]model.File, error) {
@ -205,27 +206,27 @@ func (driver Onedrive) Proxy(c *gin.Context, account *model.Account) {
} }
func (driver Onedrive) Preview(path string, account *model.Account) (interface{}, error) { func (driver Onedrive) Preview(path string, account *model.Account) (interface{}, error) {
return nil, ErrNotSupport return nil, base.ErrNotSupport
} }
func (driver Onedrive) MakeDir(path string, account *model.Account) error { func (driver Onedrive) MakeDir(path string, account *model.Account) error {
return ErrNotImplement return base.ErrNotImplement
} }
func (driver Onedrive) Move(src string, dst string, account *model.Account) error { func (driver Onedrive) Move(src string, dst string, account *model.Account) error {
return ErrNotImplement return base.ErrNotImplement
} }
func (driver Onedrive) Copy(src string, dst string, account *model.Account) error { func (driver Onedrive) Copy(src string, dst string, account *model.Account) error {
return ErrNotImplement return base.ErrNotImplement
} }
func (driver Onedrive) Delete(path string, account *model.Account) error { func (driver Onedrive) Delete(path string, account *model.Account) error {
return ErrNotImplement return base.ErrNotImplement
} }
func (driver Onedrive) Upload(file *model.FileStream, account *model.Account) error { func (driver Onedrive) Upload(file *model.FileStream, account *model.Account) error {
return ErrNotImplement return base.ErrNotImplement
} }
var _ Driver = (*Onedrive)(nil) var _ base.Driver = (*Onedrive)(nil)

View File

@ -1,8 +1,9 @@
package drivers package onedrive
import ( import (
"fmt" "fmt"
"github.com/Xhofe/alist/conf" "github.com/Xhofe/alist/conf"
"github.com/Xhofe/alist/drivers/base"
"github.com/Xhofe/alist/model" "github.com/Xhofe/alist/model"
"github.com/Xhofe/alist/utils" "github.com/Xhofe/alist/utils"
"github.com/go-resty/resty/v2" "github.com/go-resty/resty/v2"
@ -73,7 +74,7 @@ type OneTokenErr struct {
func (driver Onedrive) RefreshToken(account *model.Account) error { func (driver Onedrive) RefreshToken(account *model.Account) error {
url := driver.GetMetaUrl(account, true, "") + "/common/oauth2/v2.0/token" url := driver.GetMetaUrl(account, true, "") + "/common/oauth2/v2.0/token"
var resp TokenResp var resp base.TokenResp
var e OneTokenErr var e OneTokenErr
_, err := oneClient.R().SetResult(&resp).SetError(&e).SetFormData(map[string]string{ _, err := oneClient.R().SetResult(&resp).SetError(&e).SetFormData(map[string]string{
"grant_type": "refresh_token", "grant_type": "refresh_token",
@ -185,6 +186,6 @@ func (driver Onedrive) GetFile(account *model.Account, path string) (*OneFile, e
} }
func init() { func init() {
RegisterDriver(&Onedrive{}) base.RegisterDriver(&Onedrive{})
oneClient.SetRetryCount(3) oneClient.SetRetryCount(3)
} }

View File

@ -2,7 +2,7 @@ package server
import ( import (
"fmt" "fmt"
"github.com/Xhofe/alist/drivers" "github.com/Xhofe/alist/drivers/base"
"github.com/Xhofe/alist/model" "github.com/Xhofe/alist/model"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
@ -25,7 +25,7 @@ func CreateAccount(c *gin.Context) {
ErrorResp(c, err, 400) ErrorResp(c, err, 400)
return return
} }
driver, ok := drivers.GetDriver(req.Type) driver, ok := base.GetDriver(req.Type)
if !ok { if !ok {
ErrorResp(c, fmt.Errorf("no [%s] driver", req.Type), 400) ErrorResp(c, fmt.Errorf("no [%s] driver", req.Type), 400)
return return
@ -51,7 +51,7 @@ func SaveAccount(c *gin.Context) {
ErrorResp(c, err, 400) ErrorResp(c, err, 400)
return return
} }
driver, ok := drivers.GetDriver(req.Type) driver, ok := base.GetDriver(req.Type)
if !ok { if !ok {
ErrorResp(c, fmt.Errorf("no [%s] driver", req.Type), 400) ErrorResp(c, fmt.Errorf("no [%s] driver", req.Type), 400)
return return

View File

@ -2,7 +2,7 @@ package server
import ( import (
"fmt" "fmt"
"github.com/Xhofe/alist/drivers" "github.com/Xhofe/alist/drivers/base"
"github.com/Xhofe/alist/model" "github.com/Xhofe/alist/model"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
@ -15,7 +15,7 @@ type Resp struct {
Data interface{} `json:"data"` Data interface{} `json:"data"`
} }
func ParsePath(rawPath string) (*model.Account, string, drivers.Driver, error) { func ParsePath(rawPath string) (*model.Account, string, base.Driver, error) {
var path, name string var path, name string
switch model.AccountsCount() { switch model.AccountsCount() {
case 0: case 0:
@ -32,7 +32,7 @@ func ParsePath(rawPath string) (*model.Account, string, drivers.Driver, error) {
if !ok { if !ok {
return nil, "", nil, fmt.Errorf("no [%s] account", name) return nil, "", nil, fmt.Errorf("no [%s] account", name)
} }
driver, ok := drivers.GetDriver(account.Type) driver, ok := base.GetDriver(account.Type)
if !ok { if !ok {
return nil, "", nil, fmt.Errorf("no [%s] driver", account.Type) return nil, "", nil, fmt.Errorf("no [%s] driver", account.Type)
} }

View File

@ -1,10 +1,10 @@
package server package server
import ( import (
"github.com/Xhofe/alist/drivers" "github.com/Xhofe/alist/drivers/base"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
func GetDrivers(c *gin.Context) { func GetDrivers(c *gin.Context) {
SuccessResp(c, drivers.GetDrivers()) SuccessResp(c, base.GetDrivers())
} }

View File

@ -8,7 +8,7 @@ import (
"context" "context"
"fmt" "fmt"
"github.com/Xhofe/alist/conf" "github.com/Xhofe/alist/conf"
"github.com/Xhofe/alist/drivers" "github.com/Xhofe/alist/drivers/base"
"github.com/Xhofe/alist/model" "github.com/Xhofe/alist/model"
"github.com/Xhofe/alist/utils" "github.com/Xhofe/alist/utils"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
@ -22,7 +22,7 @@ import (
type FileSystem struct{} type FileSystem struct{}
func ParsePath(rawPath string) (*model.Account, string, drivers.Driver, error) { func ParsePath(rawPath string) (*model.Account, string, base.Driver, error) {
var path, name string var path, name string
switch model.AccountsCount() { switch model.AccountsCount() {
case 0: case 0:
@ -39,7 +39,7 @@ func ParsePath(rawPath string) (*model.Account, string, drivers.Driver, error) {
if !ok { if !ok {
return nil, "", nil, fmt.Errorf("no [%s] account", name) return nil, "", nil, fmt.Errorf("no [%s] account", name)
} }
driver, ok := drivers.GetDriver(account.Type) driver, ok := base.GetDriver(account.Type)
if !ok { if !ok {
return nil, "", nil, fmt.Errorf("no [%s] driver", account.Type) return nil, "", nil, fmt.Errorf("no [%s] driver", account.Type)
} }