mirror of https://github.com/Xhofe/alist
✨ account index
parent
04e89754f7
commit
d78b64ee3c
|
@ -172,6 +172,11 @@ func initSettings() {
|
||||||
Type: "string",
|
Type: "string",
|
||||||
Description: "music cover image",
|
Description: "music cover image",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Key: "site beian",
|
||||||
|
Type: "string",
|
||||||
|
Description: "chinese beian info",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for k, v := range settingsMap {
|
for k, v := range settingsMap {
|
||||||
|
|
|
@ -79,6 +79,13 @@ func (a AliDrive) Items() []Item {
|
||||||
Type: "string",
|
Type: "string",
|
||||||
Required: false,
|
Required: false,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Name: "limit",
|
||||||
|
Label: "limit",
|
||||||
|
Type: "number",
|
||||||
|
Required: false,
|
||||||
|
Description: ">0 and <=200",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
|
|
||||||
type Account struct {
|
type Account struct {
|
||||||
Name string `json:"name" gorm:"primaryKey" validate:"required"`
|
Name string `json:"name" gorm:"primaryKey" validate:"required"`
|
||||||
|
Index int `json:"index" validate:"required"`
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
Username string `json:"username"`
|
Username string `json:"username"`
|
||||||
Password string `json:"password"`
|
Password string `json:"password"`
|
||||||
|
@ -71,9 +72,13 @@ func GetAccount(name string) (Account, bool) {
|
||||||
return account, ok
|
return account, ok
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetAccountFiles() []*File {
|
func GetAccountFiles() ([]*File, error) {
|
||||||
files := make([]*File, 0)
|
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{
|
files = append(files, &File{
|
||||||
Name: v.Name,
|
Name: v.Name,
|
||||||
Size: 0,
|
Size: 0,
|
||||||
|
@ -81,13 +86,13 @@ func GetAccountFiles() []*File {
|
||||||
UpdatedAt: v.UpdatedAt,
|
UpdatedAt: v.UpdatedAt,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return files
|
return files, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetAccounts() []Account {
|
func GetAccounts() ([]Account, error) {
|
||||||
accounts := make([]Account, 0)
|
var accounts []Account
|
||||||
for _, v := range accountsMap {
|
if err := conf.DB.Order("`index`").Find(&accounts).Error; err != nil {
|
||||||
accounts = append(accounts, v)
|
return nil, err
|
||||||
}
|
}
|
||||||
return accounts
|
return accounts, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,11 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetAccounts(ctx *fiber.Ctx) error {
|
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 {
|
func SaveAccount(ctx *fiber.Ctx) error {
|
||||||
|
@ -32,11 +36,11 @@ func SaveAccount(ctx *fiber.Ctx) error {
|
||||||
} else {
|
} else {
|
||||||
if ok {
|
if ok {
|
||||||
err = driver.Save(&req, &old)
|
err = driver.Save(&req, &old)
|
||||||
}else {
|
} else {
|
||||||
err = driver.Save(&req, nil)
|
err = driver.Save(&req, nil)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ErrorResp(ctx,err,500)
|
return ErrorResp(ctx, err, 500)
|
||||||
}
|
}
|
||||||
return SuccessResp(ctx)
|
return SuccessResp(ctx)
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,10 +29,14 @@ func Path(ctx *fiber.Ctx) error {
|
||||||
// TODO hide or ignore?
|
// TODO hide or ignore?
|
||||||
}
|
}
|
||||||
if model.AccountsCount() > 1 && req.Path == "/" {
|
if model.AccountsCount() > 1 && req.Path == "/" {
|
||||||
|
files, err := model.GetAccountFiles()
|
||||||
|
if err != nil {
|
||||||
|
return ErrorResp(ctx, err, 500)
|
||||||
|
}
|
||||||
return ctx.JSON(Resp{
|
return ctx.JSON(Resp{
|
||||||
Code: 200,
|
Code: 200,
|
||||||
Message: "folder",
|
Message: "folder",
|
||||||
Data: model.GetAccountFiles(),
|
Data: files,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
account, path, driver, err := ParsePath(req.Path)
|
account, path, driver, err := ParsePath(req.Path)
|
||||||
|
|
Loading…
Reference in New Issue