chore: rename `index` to `order` of storage

pull/1628/head
Noah Hsu 2022-09-07 15:55:15 +08:00
parent 53fc2f32d8
commit 71d30b6819
6 changed files with 15 additions and 14 deletions

View File

@ -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"}`,

View File

@ -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":"."}`,

View File

@ -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"`

View File

@ -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",

View File

@ -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 != "/" {

View File

@ -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)