mirror of https://github.com/Xhofe/alist
feat: driver manage
parent
84eb978731
commit
0d93a6aa41
|
@ -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"
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
package drivers
|
||||
|
||||
import (
|
||||
_ "github.com/alist-org/alist/v3/drivers/local"
|
||||
)
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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{}
|
||||
}
|
|
@ -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"`
|
||||
}
|
||||
|
|
|
@ -3,4 +3,6 @@ package driver
|
|||
type Config struct {
|
||||
Name string
|
||||
LocalSort bool
|
||||
OnlyLocal bool
|
||||
OnlyProxy bool
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
package operations
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue