feat: add onedrive driver
This commit is contained in:
@ -128,12 +128,13 @@ func getAdditionalItems(t reflect.Type, defaultRoot string) []driver.Item {
|
||||
continue
|
||||
}
|
||||
tag := field.Tag
|
||||
ignore, ok := tag.Lookup("ignore")
|
||||
if ok && ignore == "true" {
|
||||
ignore, ok1 := tag.Lookup("ignore")
|
||||
name, ok2 := tag.Lookup("json")
|
||||
if (ok1 && ignore == "true") || !ok2 {
|
||||
continue
|
||||
}
|
||||
item := driver.Item{
|
||||
Name: tag.Get("json"),
|
||||
Name: name,
|
||||
Type: strings.ToLower(field.Type.Name()),
|
||||
Default: tag.Get("default"),
|
||||
Options: tag.Get("options"),
|
||||
|
@ -2,6 +2,7 @@ package operations
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
@ -49,7 +50,12 @@ func CreateStorage(ctx context.Context, storage model.Storage) error {
|
||||
// already has an id
|
||||
err = storageDriver.Init(ctx, storage)
|
||||
if err != nil {
|
||||
storageDriver.GetStorage().SetStatus(fmt.Sprintf("%+v", err.Error()))
|
||||
MustSaveDriverStorage(storageDriver)
|
||||
return errors.WithMessage(err, "failed init storage but storage is already created")
|
||||
} else {
|
||||
storageDriver.GetStorage().SetStatus("work")
|
||||
MustSaveDriverStorage(storageDriver)
|
||||
}
|
||||
log.Debugf("storage %+v is created", storageDriver)
|
||||
storagesMap.Store(storage.MountPath, storageDriver)
|
||||
@ -204,7 +210,7 @@ func saveDriverStorage(driver driver.Driver) error {
|
||||
return errors.Wrap(err, "error while marshal addition")
|
||||
}
|
||||
storage.Addition = string(bytes)
|
||||
err = db.UpdateStorage(&storage)
|
||||
err = db.UpdateStorage(storage)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "failed update storage in database")
|
||||
}
|
||||
|
@ -25,8 +25,8 @@ func TestCreateStorage(t *testing.T) {
|
||||
storage model.Storage
|
||||
isErr bool
|
||||
}{
|
||||
{storage: model.Storage{Driver: "Local", MountPath: "/local", Addition: `{"root_folder":"."}`}, isErr: false},
|
||||
{storage: model.Storage{Driver: "Local", MountPath: "/local", Addition: `{"root_folder":"."}`}, isErr: true},
|
||||
{storage: model.Storage{Driver: "local", MountPath: "/local", Addition: `{"root_folder":"."}`}, isErr: false},
|
||||
{storage: model.Storage{Driver: "local", MountPath: "/local", Addition: `{"root_folder":"."}`}, isErr: true},
|
||||
{storage: model.Storage{Driver: "None", MountPath: "/none", Addition: `{"root_folder":"."}`}, isErr: true},
|
||||
}
|
||||
for _, storage := range storages {
|
||||
@ -70,11 +70,11 @@ func TestGetBalancedStorage(t *testing.T) {
|
||||
|
||||
func setupStorages(t *testing.T) {
|
||||
var storages = []model.Storage{
|
||||
{Driver: "Local", MountPath: "/a/b", Index: 0, Addition: `{"root_folder":"."}`},
|
||||
{Driver: "Local", MountPath: "/a/c", Index: 1, Addition: `{"root_folder":"."}`},
|
||||
{Driver: "Local", MountPath: "/a/d", Index: 2, Addition: `{"root_folder":"."}`},
|
||||
{Driver: "Local", MountPath: "/a/d/e", Index: 3, Addition: `{"root_folder":"."}`},
|
||||
{Driver: "Local", MountPath: "/a/d/e.balance", Index: 4, Addition: `{"root_folder":"."}`},
|
||||
{Driver: "local", MountPath: "/a/b", Index: 0, Addition: `{"root_folder":"."}`},
|
||||
{Driver: "local", MountPath: "/a/c", Index: 1, Addition: `{"root_folder":"."}`},
|
||||
{Driver: "local", MountPath: "/a/d", Index: 2, Addition: `{"root_folder":"."}`},
|
||||
{Driver: "local", MountPath: "/a/d/e", Index: 3, Addition: `{"root_folder":"."}`},
|
||||
{Driver: "local", MountPath: "/a/d/e.balance", Index: 4, Addition: `{"root_folder":"."}`},
|
||||
}
|
||||
for _, storage := range storages {
|
||||
err := operations.CreateStorage(context.Background(), storage)
|
||||
|
Reference in New Issue
Block a user