feat: improve driver

This commit is contained in:
Noah Hsu
2022-06-07 22:02:41 +08:00
parent 0d93a6aa41
commit 677047c80b
9 changed files with 88 additions and 27 deletions

View File

@ -2,10 +2,12 @@ package local
import (
"context"
"errors"
"fmt"
"github.com/alist-org/alist/v3/internal/driver"
"github.com/alist-org/alist/v3/internal/model"
"github.com/alist-org/alist/v3/pkg/utils"
"os"
"path/filepath"
)
type Driver struct {
@ -18,32 +20,42 @@ func (d Driver) Config() driver.Config {
}
func (d *Driver) Init(ctx context.Context, account model.Account) error {
d.Account = account
addition := d.Account.Addition
err := utils.Json.UnmarshalFromString(addition, d.Addition)
if err != nil {
return errors.New("error")
return fmt.Errorf("error while unmarshal addition: %w", err)
}
return nil
}
func (d *Driver) Update(ctx context.Context, account model.Account) error {
//TODO implement me
panic("implement me")
return d.Init(ctx, account)
}
func (d *Driver) Drop(ctx context.Context) error {
//TODO implement me
panic("implement me")
return nil
}
func (d *Driver) GetAccount() model.Account {
//TODO implement me
panic("implement me")
return d.Account
}
func (d *Driver) File(ctx context.Context, path string) (*driver.FileInfo, error) {
//TODO implement me
panic("implement me")
func (d *Driver) File(ctx context.Context, path string) (driver.FileInfo, error) {
fullPath := filepath.Join(d.RootFolder, path)
if !utils.Exists(fullPath) {
return nil, driver.ErrorObjectNotFound
}
f, err := os.Stat(fullPath)
if err != nil {
return nil, err
}
return model.File{
Name: f.Name(),
Size: uint64(f.Size()),
Modified: f.ModTime(),
IsFolder: f.IsDir(),
}, nil
}
func (d *Driver) List(ctx context.Context, path string) ([]driver.FileInfo, error) {
@ -56,6 +68,11 @@ func (d *Driver) Link(ctx context.Context, args driver.LinkArgs) (*driver.Link,
panic("implement me")
}
func (d Driver) Other(ctx context.Context, data interface{}) (interface{}, error) {
//TODO implement me
panic("implement me")
}
func (d *Driver) MakeDir(ctx context.Context, path string) error {
//TODO implement me
panic("implement me")
@ -87,7 +104,3 @@ func (d *Driver) Put(ctx context.Context, stream driver.FileStream, parentPath s
}
var _ driver.Driver = (*Driver)(nil)
func init() {
driver.RegisterDriver(config.Name, New)
}

View File

@ -15,3 +15,7 @@ var config = driver.Config{
func New() driver.Driver {
return &Driver{}
}
func init() {
driver.RegisterDriver(config, New)
}