Added backend implementation for queue syncing - #245
Added database user row sync_playqueue
This commit is contained in:
parent
5abe156777
commit
b08bc08ab5
|
@ -0,0 +1,75 @@
|
|||
package migrations
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
|
||||
"github.com/pressly/goose/v3"
|
||||
)
|
||||
|
||||
func init() {
|
||||
goose.AddMigrationContext(upAddSyncPlayqueueColumnToUserTable, downAddSyncPlayqueueColumnToUserTable)
|
||||
}
|
||||
|
||||
func upAddSyncPlayqueueColumnToUserTable(ctx context.Context, tx *sql.Tx) error {
|
||||
_, err := tx.ExecContext(ctx, `
|
||||
create table user_dg_tmp
|
||||
(
|
||||
id varchar(255) not null
|
||||
primary key,
|
||||
user_name varchar(255) default '' not null
|
||||
unique,
|
||||
name varchar(255) default '' not null,
|
||||
email varchar(255) default '' not null,
|
||||
password varchar(255) default '' not null,
|
||||
is_admin bool default FALSE not null,
|
||||
last_login_at datetime,
|
||||
last_access_at datetime,
|
||||
created_at datetime not null,
|
||||
updated_at datetime not null,
|
||||
sync_playqueue bool default FALSE not null
|
||||
);
|
||||
|
||||
insert into user_dg_tmp(id, user_name, name, email, password, is_admin, last_login_at, last_access_at, created_at, updated_at) select id, user_name, name, email, password, is_admin, last_login_at, last_access_at, created_at, updated_at from user;
|
||||
|
||||
drop table user;
|
||||
|
||||
alter table user_dg_tmp rename to user;
|
||||
`)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
notice(tx, "A full rescan needs to be performed to import more tags")
|
||||
return forceFullRescan(tx)
|
||||
}
|
||||
|
||||
func downAddSyncPlayqueueColumnToUserTable(ctx context.Context, tx *sql.Tx) error {
|
||||
_, err := tx.Exec(`
|
||||
create table user_dg_tmp
|
||||
(
|
||||
id varchar(255) not null
|
||||
primary key,
|
||||
user_name varchar(255) default '' not null
|
||||
unique,
|
||||
name varchar(255) default '' not null,
|
||||
email varchar(255) default '' not null,
|
||||
password varchar(255) default '' not null,
|
||||
is_admin bool default FALSE not null,
|
||||
last_login_at datetime,
|
||||
last_access_at datetime,
|
||||
created_at datetime not null,
|
||||
updated_at datetime not null,
|
||||
);
|
||||
|
||||
insert into user_dg_tmp(id, user_name, name, email, password, is_admin, last_login_at, last_access_at, created_at, updated_at) select id, user_name, name, email, password, is_admin, last_login_at, last_access_at, created_at, updated_at from user;
|
||||
|
||||
drop table user;
|
||||
|
||||
alter table user_dg_tmp rename to user;
|
||||
`)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
notice(tx, "A full rescan needs to be performed to import more tags")
|
||||
return forceFullRescan(tx)
|
||||
}
|
|
@ -3,15 +3,16 @@ package model
|
|||
import "time"
|
||||
|
||||
type User struct {
|
||||
ID string `structs:"id" json:"id"`
|
||||
UserName string `structs:"user_name" json:"userName"`
|
||||
Name string `structs:"name" json:"name"`
|
||||
Email string `structs:"email" json:"email"`
|
||||
IsAdmin bool `structs:"is_admin" json:"isAdmin"`
|
||||
LastLoginAt *time.Time `structs:"last_login_at" json:"lastLoginAt"`
|
||||
LastAccessAt *time.Time `structs:"last_access_at" json:"lastAccessAt"`
|
||||
CreatedAt time.Time `structs:"created_at" json:"createdAt"`
|
||||
UpdatedAt time.Time `structs:"updated_at" json:"updatedAt"`
|
||||
ID string `structs:"id" json:"id"`
|
||||
UserName string `structs:"user_name" json:"userName"`
|
||||
Name string `structs:"name" json:"name"`
|
||||
Email string `structs:"email" json:"email"`
|
||||
IsAdmin bool `structs:"is_admin" json:"isAdmin"`
|
||||
SyncPlayqueue bool `structs:"sync_playqueue" json:"syncPlayqueue"`
|
||||
LastLoginAt *time.Time `structs:"last_login_at" json:"lastLoginAt"`
|
||||
LastAccessAt *time.Time `structs:"last_access_at" json:"lastAccessAt"`
|
||||
CreatedAt time.Time `structs:"created_at" json:"createdAt"`
|
||||
UpdatedAt time.Time `structs:"updated_at" json:"updatedAt"`
|
||||
|
||||
// This is only available on the backend, and it is never sent over the wire
|
||||
Password string `structs:"-" json:"-"`
|
||||
|
|
|
@ -73,6 +73,7 @@ func buildAuthPayload(user *model.User) map[string]interface{} {
|
|||
"name": user.Name,
|
||||
"username": user.UserName,
|
||||
"isAdmin": user.IsAdmin,
|
||||
"sync": user.SyncPlayqueue,
|
||||
}
|
||||
if conf.Server.EnableGravatar && user.Email != "" {
|
||||
payload["avatar"] = gravatar.Url(user.Email, 50)
|
||||
|
|
|
@ -322,6 +322,7 @@ type User struct {
|
|||
JukeboxRole bool `xml:"jukeboxRole,attr" json:"jukeboxRole"`
|
||||
ShareRole bool `xml:"shareRole,attr" json:"shareRole"`
|
||||
VideoConversionRole bool `xml:"videoConversionRole,attr" json:"videoConversionRole"`
|
||||
SyncPlayqueue bool `xml:"syncPlayqueue,attr" json:"syncPlayqueue"`
|
||||
Folder []int32 `xml:"folder,omitempty" json:"folder,omitempty"`
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ func (api *Router) GetUser(r *http.Request) (*responses.Subsonic, error) {
|
|||
response.User.Username = loggedUser.UserName
|
||||
response.User.AdminRole = loggedUser.IsAdmin
|
||||
response.User.Email = loggedUser.Email
|
||||
response.User.SyncPlayqueue = loggedUser.SyncPlayqueue
|
||||
response.User.StreamRole = true
|
||||
response.User.ScrobblingEnabled = true
|
||||
response.User.DownloadRole = conf.Server.EnableDownloads
|
||||
|
@ -41,6 +42,7 @@ func (api *Router) GetUsers(r *http.Request) (*responses.Subsonic, error) {
|
|||
user.DownloadRole = conf.Server.EnableDownloads
|
||||
user.ShareRole = conf.Server.EnableSharing
|
||||
user.JukeboxRole = conf.Server.Jukebox.Enabled
|
||||
user.SyncPlayqueue = loggedUser.SyncPlayqueue
|
||||
response := newResponse()
|
||||
response.Users = &responses.Users{User: []responses.User{user}}
|
||||
return response, nil
|
||||
|
|
Loading…
Reference in New Issue