account index

pull/548/head
微凉 2021-11-03 10:37:33 +08:00
parent 04e89754f7
commit d78b64ee3c
5 changed files with 37 additions and 12 deletions

View File

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

View File

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

View File

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

View File

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

View File

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