diff --git a/bootstrap/model.go b/bootstrap/model.go index 0fee5124..aa009b04 100644 --- a/bootstrap/model.go +++ b/bootstrap/model.go @@ -172,6 +172,11 @@ func initSettings() { Type: "string", Description: "music cover image", }, + { + Key: "site beian", + Type: "string", + Description: "chinese beian info", + }, }, } for k, v := range settingsMap { diff --git a/drivers/alidrive.go b/drivers/alidrive.go index b51dd559..25f3b11c 100644 --- a/drivers/alidrive.go +++ b/drivers/alidrive.go @@ -79,6 +79,13 @@ func (a AliDrive) Items() []Item { Type: "string", Required: false, }, + { + Name: "limit", + Label: "limit", + Type: "number", + Required: false, + Description: ">0 and <=200", + }, } } diff --git a/model/account.go b/model/account.go index 41edf52e..25bb105b 100644 --- a/model/account.go +++ b/model/account.go @@ -7,6 +7,7 @@ import ( type Account struct { Name string `json:"name" gorm:"primaryKey" validate:"required"` + Index int `json:"index" validate:"required"` Type string `json:"type"` Username string `json:"username"` Password string `json:"password"` @@ -71,9 +72,13 @@ func GetAccount(name string) (Account, bool) { return account, ok } -func GetAccountFiles() []*File { +func GetAccountFiles() ([]*File, error) { files := make([]*File, 0) - for _, v := range accountsMap { + var accounts []Account + if err := conf.DB.Order("`index`").Find(&accounts).Error; err != nil { + return nil, err + } + for _, v := range accounts { files = append(files, &File{ Name: v.Name, Size: 0, @@ -81,13 +86,13 @@ func GetAccountFiles() []*File { UpdatedAt: v.UpdatedAt, }) } - return files + return files, nil } -func GetAccounts() []Account { - accounts := make([]Account, 0) - for _, v := range accountsMap { - accounts = append(accounts, v) +func GetAccounts() ([]Account, error) { + var accounts []Account + if err := conf.DB.Order("`index`").Find(&accounts).Error; err != nil { + return nil, err } - return accounts + return accounts, nil } diff --git a/server/account.go b/server/account.go index 0942f088..a1a6f060 100644 --- a/server/account.go +++ b/server/account.go @@ -9,7 +9,11 @@ import ( ) func GetAccounts(ctx *fiber.Ctx) error { - return SuccessResp(ctx, model.GetAccounts()) + accounts, err := model.GetAccounts() + if err != nil { + return ErrorResp(ctx, err, 500) + } + return SuccessResp(ctx, accounts) } func SaveAccount(ctx *fiber.Ctx) error { @@ -32,11 +36,11 @@ func SaveAccount(ctx *fiber.Ctx) error { } else { if ok { err = driver.Save(&req, &old) - }else { + } else { err = driver.Save(&req, nil) } if err != nil { - return ErrorResp(ctx,err,500) + return ErrorResp(ctx, err, 500) } return SuccessResp(ctx) } diff --git a/server/path.go b/server/path.go index 5e91cff3..3e78816a 100644 --- a/server/path.go +++ b/server/path.go @@ -29,10 +29,14 @@ func Path(ctx *fiber.Ctx) error { // TODO hide or ignore? } if model.AccountsCount() > 1 && req.Path == "/" { + files, err := model.GetAccountFiles() + if err != nil { + return ErrorResp(ctx, err, 500) + } return ctx.JSON(Resp{ Code: 200, Message: "folder", - Data: model.GetAccountFiles(), + Data: files, }) } account, path, driver, err := ParsePath(req.Path)