Skip to content

Commit 0d93a6a

Browse files
committed
feat: driver manage
1 parent 84eb978 commit 0d93a6a

File tree

10 files changed

+153
-11
lines changed

10 files changed

+153
-11
lines changed

cmd/alist.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/alist-org/alist/v3/bootstrap"
77
"github.com/alist-org/alist/v3/cmd/args"
88
"github.com/alist-org/alist/v3/conf"
9+
_ "github.com/alist-org/alist/v3/drivers"
910
"github.com/gin-gonic/gin"
1011
log "github.com/sirupsen/logrus"
1112
"os"

drivers/all.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package drivers
2+
3+
import (
4+
_ "github.com/alist-org/alist/v3/drivers/local"
5+
)

drivers/local/driver.go

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,93 @@
11
package local
2+
3+
import (
4+
"context"
5+
"errors"
6+
"github.com/alist-org/alist/v3/internal/driver"
7+
"github.com/alist-org/alist/v3/internal/model"
8+
"github.com/alist-org/alist/v3/pkg/utils"
9+
)
10+
11+
type Driver struct {
12+
model.Account
13+
Addition
14+
}
15+
16+
func (d Driver) Config() driver.Config {
17+
return config
18+
}
19+
20+
func (d *Driver) Init(ctx context.Context, account model.Account) error {
21+
addition := d.Account.Addition
22+
err := utils.Json.UnmarshalFromString(addition, d.Addition)
23+
if err != nil {
24+
return errors.New("error")
25+
}
26+
return nil
27+
}
28+
29+
func (d *Driver) Update(ctx context.Context, account model.Account) error {
30+
//TODO implement me
31+
panic("implement me")
32+
}
33+
34+
func (d *Driver) Drop(ctx context.Context) error {
35+
//TODO implement me
36+
panic("implement me")
37+
}
38+
39+
func (d *Driver) GetAccount() model.Account {
40+
//TODO implement me
41+
panic("implement me")
42+
}
43+
44+
func (d *Driver) File(ctx context.Context, path string) (*driver.FileInfo, error) {
45+
//TODO implement me
46+
panic("implement me")
47+
}
48+
49+
func (d *Driver) List(ctx context.Context, path string) ([]driver.FileInfo, error) {
50+
//TODO implement me
51+
panic("implement me")
52+
}
53+
54+
func (d *Driver) Link(ctx context.Context, args driver.LinkArgs) (*driver.Link, error) {
55+
//TODO implement me
56+
panic("implement me")
57+
}
58+
59+
func (d *Driver) MakeDir(ctx context.Context, path string) error {
60+
//TODO implement me
61+
panic("implement me")
62+
}
63+
64+
func (d *Driver) Move(ctx context.Context, src, dst string) error {
65+
//TODO implement me
66+
panic("implement me")
67+
}
68+
69+
func (d *Driver) Rename(ctx context.Context, src, dst string) error {
70+
//TODO implement me
71+
panic("implement me")
72+
}
73+
74+
func (d *Driver) Copy(ctx context.Context, src, dst string) error {
75+
//TODO implement me
76+
panic("implement me")
77+
}
78+
79+
func (d *Driver) Remove(ctx context.Context, path string) error {
80+
//TODO implement me
81+
panic("implement me")
82+
}
83+
84+
func (d *Driver) Put(ctx context.Context, stream driver.FileStream, parentPath string) error {
85+
//TODO implement me
86+
panic("implement me")
87+
}
88+
89+
var _ driver.Driver = (*Driver)(nil)
90+
91+
func init() {
92+
driver.RegisterDriver(config.Name, New)
93+
}

drivers/local/meta.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package local
2+
3+
import "github.com/alist-org/alist/v3/internal/driver"
4+
5+
type Addition struct {
6+
RootFolder string `json:"root_folder" type:"string" desc:"root folder path" default:"/"`
7+
}
8+
9+
var config = driver.Config{
10+
Name: "Local",
11+
OnlyLocal: true,
12+
LocalSort: true,
13+
}
14+
15+
func New() driver.Driver {
16+
return &Driver{}
17+
}

internal/driver/addition.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
package driver
22

3-
type Addition interface {
3+
type Additional interface {
4+
}
5+
6+
type Item struct {
7+
Name string `json:"name"`
8+
Type string `json:"type"`
9+
Default string `json:"default"`
10+
Values string `json:"values"`
11+
Required bool `json:"required"`
12+
Desc string `json:"desc"`
413
}

internal/driver/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ package driver
33
type Config struct {
44
Name string
55
LocalSort bool
6+
OnlyLocal bool
7+
OnlyProxy bool
68
}

internal/driver/driver.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,18 @@ import (
66
)
77

88
type Driver interface {
9+
Other
910
Reader
1011
Writer
11-
Other
12+
}
13+
14+
type Other interface {
15+
Config() Config
16+
Init(ctx context.Context, account model.Account) error
17+
Update(ctx context.Context, account model.Account) error
18+
Drop(ctx context.Context) error
19+
// GetAccount transform additional field to string and assign to account's addition
20+
GetAccount() model.Account
1221
}
1322

1423
type Reader interface {
@@ -25,12 +34,3 @@ type Writer interface {
2534
Remove(ctx context.Context, path string) error
2635
Put(ctx context.Context, stream FileStream, parentPath string) error
2736
}
28-
29-
type Other interface {
30-
Init(ctx context.Context, account model.Account) error
31-
Update(ctx context.Context, account model.Account) error
32-
Drop(ctx context.Context) error
33-
// GetAccount transform additional field to string and assign to account's addition
34-
GetAccount() model.Account
35-
Config() Config
36-
}

internal/driver/manage.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package driver
2+
3+
import (
4+
log "github.com/sirupsen/logrus"
5+
)
6+
7+
type New func() Driver
8+
9+
var driversMap = map[string]New{}
10+
11+
func RegisterDriver(name string, new New) {
12+
log.Infof("register driver: [%s]", name)
13+
driversMap[name] = new
14+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package operations

internal/model/account.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ type Account struct {
77
Driver string `json:"driver"`
88
Status string `json:"status"`
99
Addition string `json:"addition"`
10+
Remark string `json:"remark"`
1011
Sort
1112
Proxy
1213
}

0 commit comments

Comments
 (0)