diff --git a/internal/aria2/aria2_test.go b/internal/aria2/aria2_test.go index d55452b1..a20827f4 100644 --- a/internal/aria2/aria2_test.go +++ b/internal/aria2/aria2_test.go @@ -42,7 +42,7 @@ func TestDown(t *testing.T) { err := op.CreateStorage(context.Background(), model.Storage{ ID: 0, MountPath: "/", - Index: 0, + Order: 0, Driver: "Local", Status: "", Addition: `{"root_folder":"../../data"}`, diff --git a/internal/bootstrap/data/dev.go b/internal/bootstrap/data/dev.go index 65cd9717..6104d356 100644 --- a/internal/bootstrap/data/dev.go +++ b/internal/bootstrap/data/dev.go @@ -14,7 +14,7 @@ import ( func initDevData() { err := op.CreateStorage(context.Background(), model.Storage{ MountPath: "/", - Index: 0, + Order: 0, Driver: "Local", Status: "", Addition: `{"root_folder":"."}`, diff --git a/internal/model/storage.go b/internal/model/storage.go index 4a4068e8..2451a89c 100644 --- a/internal/model/storage.go +++ b/internal/model/storage.go @@ -5,7 +5,7 @@ import "time" type Storage struct { ID uint `json:"id" gorm:"primaryKey"` // unique key MountPath string `json:"mount_path" gorm:"unique" binding:"required"` // must be standardized - Index int `json:"index"` // use to sort + Order int `json:"order"` // use to sort Driver string `json:"driver"` // driver used CacheExpiration int `json:"cache_expiration"` // cache expire time Status string `json:"status"` diff --git a/internal/op/driver.go b/internal/op/driver.go index 2a545679..518b9e38 100644 --- a/internal/op/driver.go +++ b/internal/op/driver.go @@ -60,15 +60,12 @@ func getMainItems(config driver.Config) []driver.Item { Required: true, Help: "", }, { - Name: "index", + Name: "order", Type: conf.TypeNumber, Help: "use to sort", }, { Name: "remark", Type: conf.TypeText, - }, { - Name: "down_proxy_url", - Type: conf.TypeText, }} if !config.NoCache { items = append(items, driver.Item{ @@ -100,6 +97,10 @@ func getMainItems(config driver.Config) []driver.Item { Required: true, }) } + items = append(items, driver.Item{ + Name: "down_proxy_url", + Type: conf.TypeText, + }) if config.LocalSort { items = append(items, []driver.Item{{ Name: "order_by", diff --git a/internal/op/storage.go b/internal/op/storage.go index 269bc44d..d7871c64 100644 --- a/internal/op/storage.go +++ b/internal/op/storage.go @@ -268,10 +268,10 @@ func GetStorageVirtualFilesByPath(prefix string) []model.Obj { files := make([]model.Obj, 0) storages := storagesMap.Values() sort.Slice(storages, func(i, j int) bool { - if storages[i].GetStorage().Index == storages[j].GetStorage().Index { + if storages[i].GetStorage().Order == storages[j].GetStorage().Order { return storages[i].GetStorage().MountPath < storages[j].GetStorage().MountPath } - return storages[i].GetStorage().Index < storages[j].GetStorage().Index + return storages[i].GetStorage().Order < storages[j].GetStorage().Order }) prefix = utils.StandardizePath(prefix) if prefix != "/" { diff --git a/internal/op/storage_test.go b/internal/op/storage_test.go index 79f44e57..a6502c5c 100644 --- a/internal/op/storage_test.go +++ b/internal/op/storage_test.go @@ -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", Order: 0, Addition: `{"root_folder":"."}`}, + {Driver: "Local", MountPath: "/a/c", Order: 1, Addition: `{"root_folder":"."}`}, + {Driver: "Local", MountPath: "/a/d", Order: 2, Addition: `{"root_folder":"."}`}, + {Driver: "Local", MountPath: "/a/d/e", Order: 3, Addition: `{"root_folder":"."}`}, + {Driver: "Local", MountPath: "/a/d/e.balance", Order: 4, Addition: `{"root_folder":"."}`}, } for _, storage := range storages { err := op.CreateStorage(context.Background(), storage)