feat: driver and account operate

This commit is contained in:
Noah Hsu
2022-06-09 17:11:46 +08:00
parent 5b73b68eb5
commit e1a2ed0436
13 changed files with 209 additions and 44 deletions

View File

@ -2,10 +2,10 @@ package local
import (
"context"
"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"
"github.com/pkg/errors"
"os"
"path/filepath"
)
@ -24,15 +24,11 @@ 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 fmt.Errorf("error while unmarshal addition: %w", err)
return errors.Wrap(err, "error while unmarshal addition")
}
return nil
}
func (d *Driver) Update(ctx context.Context, account model.Account) error {
return d.Init(ctx, account)
}
func (d *Driver) Drop(ctx context.Context) error {
return nil
}
@ -44,7 +40,7 @@ func (d *Driver) GetAddition() driver.Additional {
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
return nil, errors.WithStack(driver.ErrorObjectNotFound)
}
f, err := os.Stat(fullPath)
if err != nil {

View File

@ -1,6 +1,9 @@
package local
import "github.com/alist-org/alist/v3/internal/driver"
import (
"github.com/alist-org/alist/v3/internal/driver"
"github.com/alist-org/alist/v3/internal/operations"
)
type Addition struct {
RootFolder string `json:"root_folder" help:"root folder path" default:"/"`
@ -17,5 +20,5 @@ func New() driver.Driver {
}
func init() {
driver.RegisterDriver(config, New)
operations.RegisterDriver(config, New)
}