mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-03 20:47:35 +03:00
Use new simplified uuid.NewString()
syntax
This commit is contained in:
parent
b47ec02f02
commit
861b406575
10 changed files with 17 additions and 32 deletions
|
@ -40,9 +40,8 @@ func (p *players) Register(ctx context.Context, id, client, typ, ip string) (*mo
|
|||
if err == nil {
|
||||
log.Debug("Found player by name", "id", plr.ID, "client", client, "username", userName)
|
||||
} else {
|
||||
r, _ := uuid.NewRandom()
|
||||
plr = &model.Player{
|
||||
ID: r.String(),
|
||||
ID: uuid.NewString(),
|
||||
Name: fmt.Sprintf("%s (%s)", client, userName),
|
||||
UserName: userName,
|
||||
Client: client,
|
||||
|
|
|
@ -29,8 +29,7 @@ func upAddDefaultTranscodings(tx *sql.Tx) error {
|
|||
}
|
||||
|
||||
for _, t := range consts.DefaultTranscodings {
|
||||
r, _ := uuid.NewRandom()
|
||||
_, err := stmt.Exec(r.String(), t["name"], t["targetFormat"], t["defaultBitRate"], t["command"])
|
||||
_, err := stmt.Exec(uuid.NewString(), t["name"], t["targetFormat"], t["defaultBitRate"], t["command"])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -92,8 +92,7 @@ var _ = Describe("MediaRepository", func() {
|
|||
})
|
||||
|
||||
It("delete tracks by id", func() {
|
||||
random, _ := uuid.NewRandom()
|
||||
id := random.String()
|
||||
id := uuid.NewString()
|
||||
Expect(mr.Put(&model.MediaFile{ID: id})).To(BeNil())
|
||||
|
||||
Expect(mr.Delete(id)).To(BeNil())
|
||||
|
|
|
@ -78,9 +78,8 @@ func AssertPlayQueue(expected, actual *model.PlayQueue) {
|
|||
func aPlayQueue(userId, current string, position int64, items ...model.MediaFile) *model.PlayQueue {
|
||||
createdAt := time.Now()
|
||||
updatedAt := createdAt.Add(time.Minute)
|
||||
id, _ := uuid.NewRandom()
|
||||
return &model.PlayQueue{
|
||||
ID: id.String(),
|
||||
ID: uuid.NewString(),
|
||||
UserID: userId,
|
||||
Current: current,
|
||||
Position: position,
|
||||
|
|
|
@ -37,8 +37,7 @@ func (r sqlRepository) annUpsert(values map[string]interface{}, itemIDs ...strin
|
|||
c, err := r.executeSQL(upd)
|
||||
if c == 0 || err == orm.ErrNoRows {
|
||||
for _, itemID := range itemIDs {
|
||||
id, _ := uuid.NewRandom()
|
||||
values["ann_id"] = id.String()
|
||||
values["ann_id"] = uuid.NewString()
|
||||
values["user_id"] = userId(r.ctx)
|
||||
values["item_type"] = r.tableName
|
||||
values["item_id"] = itemID
|
||||
|
@ -68,9 +67,8 @@ func (r sqlRepository) IncPlayCount(itemID string, ts time.Time) error {
|
|||
c, err := r.executeSQL(upd)
|
||||
|
||||
if c == 0 || err == orm.ErrNoRows {
|
||||
id, _ := uuid.NewRandom()
|
||||
values := map[string]interface{}{}
|
||||
values["ann_id"] = id.String()
|
||||
values["ann_id"] = uuid.NewString()
|
||||
values["user_id"] = userId(r.ctx)
|
||||
values["item_type"] = r.tableName
|
||||
values["item_id"] = itemID
|
||||
|
|
|
@ -186,8 +186,7 @@ func (r sqlRepository) put(id string, m interface{}) (newId string, err error) {
|
|||
}
|
||||
// If does not have an id OR could not update (new record with predefined id)
|
||||
if id == "" {
|
||||
rand, _ := uuid.NewRandom()
|
||||
id = rand.String()
|
||||
id = uuid.NewString()
|
||||
values["id"] = id
|
||||
}
|
||||
// It is a insert. if there was a created_at, add it back to args
|
||||
|
|
|
@ -44,8 +44,7 @@ func (r *userRepository) GetAll(options ...model.QueryOptions) (model.Users, err
|
|||
|
||||
func (r *userRepository) Put(u *model.User) error {
|
||||
if u.ID == "" {
|
||||
id, _ := uuid.NewRandom()
|
||||
u.ID = id.String()
|
||||
u.ID = uuid.NewString()
|
||||
}
|
||||
u.UpdatedAt = time.Now()
|
||||
values, _ := toSqlArgs(*u)
|
||||
|
|
|
@ -112,11 +112,10 @@ func CreateAdmin(ds model.DataStore) func(w http.ResponseWriter, r *http.Request
|
|||
}
|
||||
|
||||
func createDefaultUser(ctx context.Context, ds model.DataStore, username, password string) error {
|
||||
id, _ := uuid.NewRandom()
|
||||
log.Warn("Creating initial user", "user", username)
|
||||
now := time.Now()
|
||||
initialUser := model.User{
|
||||
ID: id.String(),
|
||||
ID: uuid.NewString(),
|
||||
UserName: username,
|
||||
Name: strings.Title(username),
|
||||
Email: "",
|
||||
|
|
|
@ -154,9 +154,8 @@ func (b *broker) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
func (b *broker) subscribe(r *http.Request) client {
|
||||
user, _ := request.UserFrom(r.Context())
|
||||
id, _ := uuid.NewRandom()
|
||||
c := client{
|
||||
id: id.String(),
|
||||
id: uuid.NewString(),
|
||||
username: user.UserName,
|
||||
address: r.RemoteAddr,
|
||||
userAgent: r.UserAgent(),
|
||||
|
|
|
@ -26,7 +26,7 @@ func initialSetup(ds model.DataStore) {
|
|||
}
|
||||
|
||||
if conf.Server.DevAutoCreateAdminPassword != "" {
|
||||
if err = createInitialAdminUser(ds); err != nil {
|
||||
if err = createInitialAdminUser(ds, conf.Server.DevAutoCreateAdminPassword); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
@ -36,22 +36,18 @@ func initialSetup(ds model.DataStore) {
|
|||
})
|
||||
}
|
||||
|
||||
func createInitialAdminUser(ds model.DataStore) error {
|
||||
func createInitialAdminUser(ds model.DataStore, initialPassword string) error {
|
||||
users := ds.User(context.TODO())
|
||||
c, err := users.CountAll()
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("Could not access User table: %s", err))
|
||||
}
|
||||
if c == 0 {
|
||||
id, _ := uuid.NewRandom()
|
||||
random, _ := uuid.NewRandom()
|
||||
initialPassword := random.String()
|
||||
if conf.Server.DevAutoCreateAdminPassword != "" {
|
||||
initialPassword = conf.Server.DevAutoCreateAdminPassword
|
||||
}
|
||||
log.Warn("Creating initial admin user. This should only be used for development purposes!!", "user", consts.DevInitialUserName, "password", initialPassword)
|
||||
id := uuid.NewString()
|
||||
log.Warn("Creating initial admin user. This should only be used for development purposes!!",
|
||||
"user", consts.DevInitialUserName, "password", initialPassword, "id", id)
|
||||
initialUser := model.User{
|
||||
ID: id.String(),
|
||||
ID: id,
|
||||
UserName: consts.DevInitialUserName,
|
||||
Name: consts.DevInitialName,
|
||||
Email: "",
|
||||
|
@ -72,9 +68,8 @@ func createJWTSecret(ds model.DataStore) error {
|
|||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
jwtSecret, _ := uuid.NewRandom()
|
||||
log.Warn("Creating JWT secret, used for encrypting UI sessions")
|
||||
err = properties.Put(consts.JWTSecretKey, jwtSecret.String())
|
||||
err = properties.Put(consts.JWTSecretKey, uuid.NewString())
|
||||
if err != nil {
|
||||
log.Error("Could not save JWT secret in DB", err)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue