diff --git a/cmd/alist.go b/cmd/alist.go index 3ee752fb2e5..0b6c41f989a 100644 --- a/cmd/alist.go +++ b/cmd/alist.go @@ -6,6 +6,7 @@ import ( "github.com/alist-org/alist/v3/bootstrap" "github.com/alist-org/alist/v3/cmd/args" "github.com/alist-org/alist/v3/conf" + _ "github.com/alist-org/alist/v3/drivers" "github.com/gin-gonic/gin" log "github.com/sirupsen/logrus" "os" diff --git a/drivers/all.go b/drivers/all.go new file mode 100644 index 00000000000..5f13cd707c7 --- /dev/null +++ b/drivers/all.go @@ -0,0 +1,5 @@ +package drivers + +import ( + _ "github.com/alist-org/alist/v3/drivers/local" +) diff --git a/drivers/local/driver.go b/drivers/local/driver.go index 469c3dc0d8c..dcec629188e 100644 --- a/drivers/local/driver.go +++ b/drivers/local/driver.go @@ -1 +1,93 @@ package local + +import ( + "context" + "errors" + "github.com/alist-org/alist/v3/internal/driver" + "github.com/alist-org/alist/v3/internal/model" + "github.com/alist-org/alist/v3/pkg/utils" +) + +type Driver struct { + model.Account + Addition +} + +func (d Driver) Config() driver.Config { + return config +} + +func (d *Driver) Init(ctx context.Context, account model.Account) error { + addition := d.Account.Addition + err := utils.Json.UnmarshalFromString(addition, d.Addition) + if err != nil { + return errors.New("error") + } + return nil +} + +func (d *Driver) Update(ctx context.Context, account model.Account) error { + //TODO implement me + panic("implement me") +} + +func (d *Driver) Drop(ctx context.Context) error { + //TODO implement me + panic("implement me") +} + +func (d *Driver) GetAccount() model.Account { + //TODO implement me + panic("implement me") +} + +func (d *Driver) File(ctx context.Context, path string) (*driver.FileInfo, error) { + //TODO implement me + panic("implement me") +} + +func (d *Driver) List(ctx context.Context, path string) ([]driver.FileInfo, error) { + //TODO implement me + panic("implement me") +} + +func (d *Driver) Link(ctx context.Context, args driver.LinkArgs) (*driver.Link, error) { + //TODO implement me + panic("implement me") +} + +func (d *Driver) MakeDir(ctx context.Context, path string) error { + //TODO implement me + panic("implement me") +} + +func (d *Driver) Move(ctx context.Context, src, dst string) error { + //TODO implement me + panic("implement me") +} + +func (d *Driver) Rename(ctx context.Context, src, dst string) error { + //TODO implement me + panic("implement me") +} + +func (d *Driver) Copy(ctx context.Context, src, dst string) error { + //TODO implement me + panic("implement me") +} + +func (d *Driver) Remove(ctx context.Context, path string) error { + //TODO implement me + panic("implement me") +} + +func (d *Driver) Put(ctx context.Context, stream driver.FileStream, parentPath string) error { + //TODO implement me + panic("implement me") +} + +var _ driver.Driver = (*Driver)(nil) + +func init() { + driver.RegisterDriver(config.Name, New) +} diff --git a/drivers/local/meta.go b/drivers/local/meta.go new file mode 100644 index 00000000000..d7678f5cb7f --- /dev/null +++ b/drivers/local/meta.go @@ -0,0 +1,17 @@ +package local + +import "github.com/alist-org/alist/v3/internal/driver" + +type Addition struct { + RootFolder string `json:"root_folder" type:"string" desc:"root folder path" default:"/"` +} + +var config = driver.Config{ + Name: "Local", + OnlyLocal: true, + LocalSort: true, +} + +func New() driver.Driver { + return &Driver{} +} diff --git a/internal/driver/addition.go b/internal/driver/addition.go index 000a441c0c3..ba1c64733b4 100644 --- a/internal/driver/addition.go +++ b/internal/driver/addition.go @@ -1,4 +1,13 @@ package driver -type Addition interface { +type Additional interface { +} + +type Item struct { + Name string `json:"name"` + Type string `json:"type"` + Default string `json:"default"` + Values string `json:"values"` + Required bool `json:"required"` + Desc string `json:"desc"` } diff --git a/internal/driver/config.go b/internal/driver/config.go index b1db1d109ae..5d5208b63ad 100644 --- a/internal/driver/config.go +++ b/internal/driver/config.go @@ -3,4 +3,6 @@ package driver type Config struct { Name string LocalSort bool + OnlyLocal bool + OnlyProxy bool } diff --git a/internal/driver/driver.go b/internal/driver/driver.go index 9d8791613bd..537b7fc59a7 100644 --- a/internal/driver/driver.go +++ b/internal/driver/driver.go @@ -6,9 +6,18 @@ import ( ) type Driver interface { + Other Reader Writer - Other +} + +type Other interface { + Config() Config + Init(ctx context.Context, account model.Account) error + Update(ctx context.Context, account model.Account) error + Drop(ctx context.Context) error + // GetAccount transform additional field to string and assign to account's addition + GetAccount() model.Account } type Reader interface { @@ -25,12 +34,3 @@ type Writer interface { Remove(ctx context.Context, path string) error Put(ctx context.Context, stream FileStream, parentPath string) error } - -type Other interface { - Init(ctx context.Context, account model.Account) error - Update(ctx context.Context, account model.Account) error - Drop(ctx context.Context) error - // GetAccount transform additional field to string and assign to account's addition - GetAccount() model.Account - Config() Config -} diff --git a/internal/driver/manage.go b/internal/driver/manage.go new file mode 100644 index 00000000000..e243a5b9208 --- /dev/null +++ b/internal/driver/manage.go @@ -0,0 +1,14 @@ +package driver + +import ( + log "github.com/sirupsen/logrus" +) + +type New func() Driver + +var driversMap = map[string]New{} + +func RegisterDriver(name string, new New) { + log.Infof("register driver: [%s]", name) + driversMap[name] = new +} diff --git a/internal/driver/operations/operate.go b/internal/driver/operations/operate.go new file mode 100644 index 00000000000..19c01a9d10b --- /dev/null +++ b/internal/driver/operations/operate.go @@ -0,0 +1 @@ +package operations diff --git a/internal/model/account.go b/internal/model/account.go index 0e86af2c5bb..ddc1d793261 100644 --- a/internal/model/account.go +++ b/internal/model/account.go @@ -7,6 +7,7 @@ type Account struct { Driver string `json:"driver"` Status string `json:"status"` Addition string `json:"addition"` + Remark string `json:"remark"` Sort Proxy }