add show current password

This commit is contained in:
微凉 2021-11-16 15:00:56 +08:00
parent 5e982980dc
commit 07155cfd01
4 changed files with 34 additions and 17 deletions

View File

@ -5,6 +5,7 @@ import (
"fmt"
"github.com/Xhofe/alist/bootstrap"
"github.com/Xhofe/alist/conf"
"github.com/Xhofe/alist/model"
"github.com/Xhofe/alist/server"
"github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus"
@ -14,15 +15,28 @@ func init() {
flag.StringVar(&conf.ConfigFile, "conf", "data/config.json", "config file")
flag.BoolVar(&conf.Debug, "debug", false, "start with debug mode")
flag.BoolVar(&conf.Version, "version", false, "print version info")
flag.BoolVar(&conf.Password, "password", false, "print current password")
flag.Parse()
}
func Init() {
func Init() bool {
bootstrap.InitLog()
bootstrap.InitConf()
bootstrap.InitCron()
bootstrap.InitModel()
if conf.Password {
pass, err := model.GetSettingByKey("password")
if err != nil {
log.Errorf(err.Error())
return false
}
log.Infof("current password: %s", pass.Value)
return false
}
bootstrap.InitSettings()
bootstrap.InitAccounts()
bootstrap.InitCache()
return true
}
func main() {
@ -30,7 +44,9 @@ func main() {
fmt.Printf("Built At: %s\nGo Version: %s\nAuthor: %s\nCommit ID: %s\nVersion: %s\n", conf.BuiltAt, conf.GoVersion, conf.GitAuthor, conf.GitCommit, conf.GitTag)
return
}
Init()
if !Init() {
return
}
if !conf.Debug {
gin.SetMode(gin.ReleaseMode)
}

View File

@ -77,13 +77,9 @@ func InitModel() {
if err != nil {
log.Fatalf("failed to auto migrate")
}
// TODO init filetype
initAccounts()
initSettings()
}
func initAccounts() {
func InitAccounts() {
log.Infof("init accounts...")
var accounts []model.Account
if err := conf.DB.Find(&accounts).Error; err != nil {
@ -98,12 +94,14 @@ func initAccounts() {
err := driver.Save(&accounts[i], nil)
if err != nil {
log.Errorf("init account [%s] error:[%s]", account.Name, err.Error())
} else {
log.Infof("success init account: %s, type: %s", account.Name, account.Type)
}
}
}
}
func initSettings() {
func InitSettings() {
log.Infof("init settings...")
version := model.SettingItem{
Key: "version",
@ -207,15 +205,15 @@ func initSettings() {
Description: "check parent folder password",
},
{
Key: "customize style",
Value: "",
Type: "text",
Key: "customize style",
Value: "",
Type: "text",
Description: "customize style, don't need add <style></style>",
},
{
Key: "customize script",
Value: "",
Type: "text",
Key: "customize script",
Value: "",
Type: "text",
Description: "customize script, don't need add <script></script>",
},
}

View File

@ -20,6 +20,7 @@ var (
Conf *Config
Debug bool
Version bool
Password bool
DB *gorm.DB
Cache *cache.Cache
@ -37,9 +38,9 @@ var (
// settings
var (
RawIndexHtml string
IndexHtml string
CheckParent bool
RawIndexHtml string
IndexHtml string
CheckParent bool
//CustomizeStyle string
//CustomizeScript string
//Favicon string

View File

@ -5,6 +5,7 @@ import (
"github.com/Xhofe/alist/drivers"
"github.com/Xhofe/alist/model"
"github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus"
"strings"
)
@ -39,6 +40,7 @@ func ParsePath(rawPath string) (*model.Account, string, drivers.Driver, error) {
}
func ErrorResp(c *gin.Context, err error, code int) {
log.Error(err.Error())
c.JSON(200, Resp{
Code: code,
Message: err.Error(),