mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-04 21:17:37 +03:00
40 lines
934 B
Go
40 lines
934 B
Go
package server
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/deluan/navidrome/consts"
|
|
"github.com/deluan/navidrome/log"
|
|
"github.com/deluan/navidrome/model"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
func initialSetup(ds model.DataStore) {
|
|
_ = ds.WithTx(func(tx model.DataStore) error {
|
|
_, err := ds.Property().Get(consts.InitialSetupFlagKey)
|
|
if err == nil {
|
|
return nil
|
|
}
|
|
log.Warn("Running initial setup")
|
|
if err = createJWTSecret(ds); err != nil {
|
|
return err
|
|
}
|
|
|
|
err = ds.Property().Put(consts.InitialSetupFlagKey, time.Now().String())
|
|
return err
|
|
})
|
|
}
|
|
|
|
func createJWTSecret(ds model.DataStore) error {
|
|
_, err := ds.Property().Get(consts.JWTSecretKey)
|
|
if err == nil {
|
|
return nil
|
|
}
|
|
jwtSecret, _ := uuid.NewRandom()
|
|
log.Warn("Creating JWT secret, used for encrypting UI sessions")
|
|
err = ds.Property().Put(consts.JWTSecretKey, jwtSecret.String())
|
|
if err != nil {
|
|
log.Error("Could not save JWT secret in DB", err)
|
|
}
|
|
return err
|
|
}
|