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" "fmt"
"github.com/Xhofe/alist/bootstrap" "github.com/Xhofe/alist/bootstrap"
"github.com/Xhofe/alist/conf" "github.com/Xhofe/alist/conf"
"github.com/Xhofe/alist/model"
"github.com/Xhofe/alist/server" "github.com/Xhofe/alist/server"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
@ -14,15 +15,28 @@ func init() {
flag.StringVar(&conf.ConfigFile, "conf", "data/config.json", "config file") flag.StringVar(&conf.ConfigFile, "conf", "data/config.json", "config file")
flag.BoolVar(&conf.Debug, "debug", false, "start with debug mode") flag.BoolVar(&conf.Debug, "debug", false, "start with debug mode")
flag.BoolVar(&conf.Version, "version", false, "print version info") flag.BoolVar(&conf.Version, "version", false, "print version info")
flag.BoolVar(&conf.Password, "password", false, "print current password")
flag.Parse() flag.Parse()
} }
func Init() { func Init() bool {
bootstrap.InitLog() bootstrap.InitLog()
bootstrap.InitConf() bootstrap.InitConf()
bootstrap.InitCron() bootstrap.InitCron()
bootstrap.InitModel() 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() bootstrap.InitCache()
return true
} }
func main() { 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) 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 return
} }
Init() if !Init() {
return
}
if !conf.Debug { if !conf.Debug {
gin.SetMode(gin.ReleaseMode) gin.SetMode(gin.ReleaseMode)
} }

View File

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

View File

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

View File

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