mirror of
https://github.com/AlistGo/alist.git
synced 2025-12-19 02:50:06 +08:00
* refactor:separate the setting method from the db package to the op package and add the cache
* refactor:separate the meta method from the db package to the op package
* fix:setting not load database data
* refactor:separate the user method from the db package to the op package
* refactor:remove user JoinPath error
* fix:op package user cache
* refactor:fs package list method
* fix:tile virtual paths (close #2743)
* Revert "refactor:remove user JoinPath error"
This reverts commit 4e20daaf9e.
* clean path directly may lead to unknown behavior
* fix: The path of the meta passed in must be prefix of reqPath
* chore: rename all virtualPath to mountPath
* fix: `getStoragesByPath` and `GetStorageVirtualFilesByPath`
is_sub_path:
/a/b isn't subpath of /a/bc
* fix: don't save setting if hook error
Co-authored-by: Noah Hsu <i@nn.ci>
60 lines
1.3 KiB
Go
60 lines
1.3 KiB
Go
package data
|
|
|
|
import (
|
|
"os"
|
|
|
|
"github.com/alist-org/alist/v3/cmd/flags"
|
|
"github.com/alist-org/alist/v3/internal/db"
|
|
"github.com/alist-org/alist/v3/internal/model"
|
|
"github.com/alist-org/alist/v3/internal/op"
|
|
"github.com/alist-org/alist/v3/pkg/utils"
|
|
"github.com/alist-org/alist/v3/pkg/utils/random"
|
|
"github.com/pkg/errors"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
func initUser() {
|
|
admin, err := op.GetAdmin()
|
|
adminPassword := random.String(8)
|
|
envpass := os.Getenv("ALIST_ADMIN_PASSWORD")
|
|
if flags.Dev {
|
|
adminPassword = "admin"
|
|
} else if len(envpass) > 0 {
|
|
adminPassword = envpass
|
|
}
|
|
if err != nil {
|
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
admin = &model.User{
|
|
Username: "admin",
|
|
Password: adminPassword,
|
|
Role: model.ADMIN,
|
|
BasePath: "/",
|
|
}
|
|
if err := op.CreateUser(admin); err != nil {
|
|
panic(err)
|
|
} else {
|
|
utils.Log.Infof("Successfully created the admin user and the initial password is: %s", admin.Password)
|
|
}
|
|
} else {
|
|
panic(err)
|
|
}
|
|
}
|
|
guest, err := op.GetGuest()
|
|
if err != nil {
|
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
guest = &model.User{
|
|
Username: "guest",
|
|
Password: "guest",
|
|
Role: model.GUEST,
|
|
BasePath: "/",
|
|
Permission: 0,
|
|
}
|
|
if err := db.CreateUser(guest); err != nil {
|
|
panic(err)
|
|
}
|
|
} else {
|
|
panic(err)
|
|
}
|
|
}
|
|
}
|