From 07155cfd0119cb51d861c8bfd5ad519a7e97fb33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=AE=E5=87=89?= <927625802@qq.com> Date: Tue, 16 Nov 2021 15:00:56 +0800 Subject: [PATCH] :sparkles: add show current password --- alist.go | 20 ++++++++++++++++++-- bootstrap/model.go | 22 ++++++++++------------ conf/var.go | 7 ++++--- server/common.go | 2 ++ 4 files changed, 34 insertions(+), 17 deletions(-) diff --git a/alist.go b/alist.go index abb15dee..f032e6fe 100644 --- a/alist.go +++ b/alist.go @@ -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) } diff --git a/bootstrap/model.go b/bootstrap/model.go index 8cf4d344..65c44879 100644 --- a/bootstrap/model.go +++ b/bootstrap/model.go @@ -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 ", }, { - Key: "customize script", - Value: "", - Type: "text", + Key: "customize script", + Value: "", + Type: "text", Description: "customize script, don't need add ", }, } diff --git a/conf/var.go b/conf/var.go index 2192491d..f141cf57 100644 --- a/conf/var.go +++ b/conf/var.go @@ -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 diff --git a/server/common.go b/server/common.go index 58f54906..08896f34 100644 --- a/server/common.go +++ b/server/common.go @@ -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(),