diff --git a/bootstrap/setting.go b/bootstrap/setting.go index fa236f2f..e364e129 100644 --- a/bootstrap/setting.go +++ b/bootstrap/setting.go @@ -3,6 +3,7 @@ package bootstrap import ( "github.com/Xhofe/alist/conf" "github.com/Xhofe/alist/model" + "github.com/Xhofe/alist/utils" log "github.com/sirupsen/logrus" "gorm.io/gorm" "strings" @@ -27,7 +28,7 @@ func InitSettings() { }, { Key: "password", - Value: "alist", + Value: utils.RandomStr(8), Description: "password", Type: "string", Access: model.PRIVATE, @@ -235,6 +236,9 @@ func InitSettings() { if err != nil { if err == gorm.ErrRecordNotFound { err = model.SaveSetting(v) + if v.Key == "password" { + log.Infof("Initial password: %s", v.Value) + } if err != nil { log.Fatalf("failed write setting: %s", err.Error()) } diff --git a/drivers/139/139.go b/drivers/139/139.go index 081612cf..fb6a412b 100644 --- a/drivers/139/139.go +++ b/drivers/139/139.go @@ -17,7 +17,7 @@ import ( func (driver Cloud139) Request(pathname string, method int, headers, query, form map[string]string, data interface{}, resp interface{}, account *model.Account) ([]byte, error) { url := "https://yun.139.com" + pathname req := base.RestyClient.R() - randStr := randomStr(16) + randStr := utils.RandomStr(16) ts := time.Now().Format("2006-01-02 15:04:05") log.Debugf("%+v", data) body, err := utils.Json.Marshal(data) diff --git a/drivers/139/util.go b/drivers/139/util.go index 0e2a5b79..8d513ab3 100644 --- a/drivers/139/util.go +++ b/drivers/139/util.go @@ -5,7 +5,6 @@ import ( "github.com/Xhofe/alist/drivers/base" "github.com/Xhofe/alist/model" "github.com/Xhofe/alist/utils" - "math/rand" "net/url" "sort" "strconv" @@ -13,16 +12,6 @@ import ( "time" ) -func randomStr(n int) string { - builder := strings.Builder{} - t := "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" - for i := 0; i < n; i++ { - r := rand.Intn(len(t)) - builder.WriteString(t[r : r+1]) - } - return builder.String() -} - func encodeURIComponent(str string) string { r := url.QueryEscape(str) r = strings.Replace(r, "+", "%20", -1) diff --git a/utils/random.go b/utils/random.go new file mode 100644 index 00000000..9fd9c7fe --- /dev/null +++ b/utils/random.go @@ -0,0 +1,16 @@ +package utils + +import ( + "math/rand" + "strings" +) + +func RandomStr(n int) string { + builder := strings.Builder{} + t := "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" + for i := 0; i < n; i++ { + r := rand.Intn(len(t)) + builder.WriteString(t[r : r+1]) + } + return builder.String() +}