Skip to content

Commit

Permalink
feat: driver manage
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Jun 7, 2022
1 parent 84eb978 commit 0d93a6a
Show file tree
Hide file tree
Showing 10 changed files with 153 additions and 11 deletions.
1 change: 1 addition & 0 deletions cmd/alist.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 5 additions & 0 deletions drivers/all.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package drivers

import (
_ "github.com/alist-org/alist/v3/drivers/local"
)
92 changes: 92 additions & 0 deletions drivers/local/driver.go
Original file line number Diff line number Diff line change
@@ -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)
}
17 changes: 17 additions & 0 deletions drivers/local/meta.go
Original file line number Diff line number Diff line change
@@ -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{}
}
11 changes: 10 additions & 1 deletion internal/driver/addition.go
Original file line number Diff line number Diff line change
@@ -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"`
}
2 changes: 2 additions & 0 deletions internal/driver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ package driver
type Config struct {
Name string
LocalSort bool
OnlyLocal bool
OnlyProxy bool
}
20 changes: 10 additions & 10 deletions internal/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
14 changes: 14 additions & 0 deletions internal/driver/manage.go
Original file line number Diff line number Diff line change
@@ -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
}
1 change: 1 addition & 0 deletions internal/driver/operations/operate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package operations
1 change: 1 addition & 0 deletions internal/model/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 0d93a6a

Please sign in to comment.