services

package
v0.0.0-...-f825cef Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 13, 2025 License: AGPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Handshake    WebSocketMsgType = "handshake"
	Swap         WebSocketMsgType = "swap"
	Event        WebSocketMsgType = "event"
	MediaChanged WebSocketMsgType = "media-change"

	ManagersChanged WebSocketEventType = "refresh-managers"
	PlaylistChanged WebSocketEventType = "refresh-playlist"
)
View Source
const DefaultPagingLimit = 10
View Source
const PlaylistAddOrderGap = 1 << 10

Variables

View Source
var AlreadyPlaylistManagerError = errors.New("This user is already a playlist manager.")
View Source
var AlreadyPlaylistOwnerError = errors.New("This user (you) is already the playlist owner.")
View Source
var GenericError = errors.New("Internal server error.")
View Source
var NoCurrentMediaError = errors.New("No current media.")
View Source
var UserNotFoundError = errors.New("User not found.")

Functions

func AddMedia

func AddMedia(tx *db.Tx, entry media.MediaListEntry) (id int, hasErr bool)

func AddPlaylistItems

func AddPlaylistItems(tx *db.Tx, playlist int, mediaIds []int, beginOrder, deltaOrder int) (ids []int, hasErr bool)

func AddPlaylistManager

func AddPlaylistManager(tx *db.Tx, playlist int, username string) (hasErr bool)

func AddToPlaylist

func AddToPlaylist(tx *db.Tx, playlist int, canonInfo media.MediaCanonicalizeInfo, pos PlaylistAddPosition) (hasErr bool)

func CheckPlaylistExists

func CheckPlaylistExists(tx *db.Tx, id int) (hasRow bool, hasErr bool)

func CheckPlaylistItemExists

func CheckPlaylistItemExists(tx *db.Tx, playlist, id int) (hasRow bool, hasErr bool)

func CheckUserExists

func CheckUserExists(tx *db.Tx, username string) (hasRow bool, hasErr bool)

func ConfirmMail

func ConfirmMail(tx *db.Tx, identifier, username string) (hasErr bool)

func CreatePlaylist

func CreatePlaylist(tx *db.Tx, username string, name string) (id int, hasError bool)

func DeletePlaylist

func DeletePlaylist(tx *db.Tx, username string, id int) (hasErr bool)

func DeletePlaylistItem

func DeletePlaylistItem(tx *db.Tx, playlist int, id int) (hasErr bool)

func DeletePlaylistManager

func DeletePlaylistManager(tx *db.Tx, playlist int, username string) (hasErr bool)

func EnumeratePlaylistManagers

func EnumeratePlaylistManagers(tx *db.Tx, playlist int) (managers []string, hasErr bool)

excluding owner

func GetCurrentMedia

func GetCurrentMedia(tx *db.Tx, playlist int) (itemId sql.NullInt32, hasErr bool)

func GetMediaId

func GetMediaId(tx *db.Tx, url string) (id int, hasRow, hasErr bool)

func GetMediaSimpleInfo

func GetMediaSimpleInfo(tx *db.Tx, url string) (id int, title, artist string, hasRow, hasErr bool)

func GetNextPlaylistItem

func GetNextPlaylistItem(tx *db.Tx, playlist, prevOrder int) (id int, order int, hasRow, hasErr bool)

func GetPlaylistItemOrder

func GetPlaylistItemOrder(tx *db.Tx, id int) (order int, hasErr bool)

func GetPlaylistOwner

func GetPlaylistOwner(tx *db.Tx, playlist int) (owner string, hasErr bool)

func IsPlaylistManager

func IsPlaylistManager(tx *db.Tx, username string, playlist int) (isManager, hasError bool)

func IsPlaylistOwner

func IsPlaylistOwner(tx *db.Tx, username string, playlist int) (isOwner, hasErr bool)

func LocalRebalance

func LocalRebalance(tx *db.Tx, playlist int, startOrder int, endOrder int, beforeItem int, numInsertions int) (begin int, delta int, hasErr bool)

func LogIn

func LogIn(tx *db.Tx, username, password string) (signedToken string, timeout time.Duration, hasErr bool)

func MoveItems

func MoveItems(tx *db.Tx, playlist int, items []int, dir MoveDirection) (numAffected int, hasErr bool)

func NewWebSocketErrorHandler

func NewWebSocketErrorHandler(title string, wsId string) errs.ErrorHandler

func NotifyMediaChanged

func NotifyMediaChanged(tx *db.Tx, playlist int, socketId string) (callback func(), hasErr bool)

func PlaylistUpdateCurrent

func PlaylistUpdateCurrent(tx *db.Tx, handler errs.ErrorHandler, playlist int, sign, sortOrder string) (callback func(), hasErr bool)

func Register

func Register(tx *db.Tx, email *mail.Address, username, password string) (hasErr bool)

func RenamePlaylist

func RenamePlaylist(tx *db.Tx, username string, id int, name string) (hasErr bool)

func ResetPassword

func ResetPassword(tx *db.Tx, identifier, email, password string) (hasErr bool)

func ResetPasswordRequestValid

func ResetPasswordRequestValid(tx *db.Tx, identifier, email string) (hasErr bool)

func SendNextRequest

func SendNextRequest(tx *db.Tx, handler errs.ErrorHandler, playlist int, username string) (callback func(), hasErr bool)

func SendRecoveryEmail

func SendRecoveryEmail(tx *db.Tx, email *mail.Address) (hasErr bool)

func SetCurrentMedia

func SetCurrentMedia(tx *db.Tx, playlist int, itemId sql.NullInt32) (hasErr bool)

func SetMediaAltMetadata

func SetMediaAltMetadata(tx *db.Tx, title, artist string, playlist, media int) (hasErr bool)

func WebSocketEvent

func WebSocketEvent(socketId, event string)

func WebSocketMediaChange

func WebSocketMediaChange(playlist int, socketId string, payload MediaChangedPayload)

func WebSocketPlaylistEvent

func WebSocketPlaylistEvent(playlist int, event WebSocketEventType)

func WebSocketSwap

func WebSocketSwap(socketId string, html template.HTML)

func WebSocketToast

func WebSocketToast(socketId string, kind html.ToastKind, title template.HTML, description template.HTML) error

Types

type MediaChangedPayload

type MediaChangedPayload struct {
	Type        media.MediaKind `json:"type"`
	Url         string          `json:"url"`
	AspectRatio string          `json:"aspectRatio"`
}

type MoveDirection

type MoveDirection int
const (
	MoveUp   MoveDirection = 1
	MoveDown MoveDirection = -1
)

type MoveItem

type MoveItem struct {
	// contains filtered or unexported fields
}

type Pagination

type Pagination[T any] struct {
	Items      []T
	NextOffset int
	PrevOffset int
	NextPage   int
	PrevPage   int
	Page       int
}

func EnumeratePlaylistItems

func EnumeratePlaylistItems(tx *db.Tx, playlist int, pageNum int) (page Pagination[QueuePlaylistItem], hasError bool)

func NewPagination

func NewPagination[T any](offset int, items []T) Pagination[T]

func SearchPlaylists

func SearchPlaylists(tx *db.Tx, username string, query string, filter PlaylistFilter, offset int) (page Pagination[QueriedPlaylist], hasError bool)

type PlaylistAddPosition

type PlaylistAddPosition string
const (
	AddToStart PlaylistAddPosition = "add-to-start"
	AddToEnd   PlaylistAddPosition = "add-to-end"
	QueueNext  PlaylistAddPosition = "queue-next"
)

func ParsePlaylistAddPosition

func ParsePlaylistAddPosition(pos string) (PlaylistAddPosition, error)

type PlaylistFilter

type PlaylistFilter string
const (
	All     PlaylistFilter = "all"
	Owned   PlaylistFilter = "owned"
	Managed PlaylistFilter = "managed"
)

func ParsePlaylistFilter

func ParsePlaylistFilter(filter string) (PlaylistFilter, error)

type PlaylistState

type PlaylistState struct {
	// contains filtered or unexported fields
}

func (*PlaylistState) Add

func (p *PlaylistState) Add(conn *websocket.Conn, username, id string)

func (*PlaylistState) Broadcast

func (p *PlaylistState) Broadcast(msg WebSocketMsg)

func (*PlaylistState) NumManagerWatching

func (p *PlaylistState) NumManagerWatching() int

func (*PlaylistState) Remove

func (p *PlaylistState) Remove(username, id string) bool

type QueriedPlaylist

type QueriedPlaylist struct {
	Id               int
	Name             string
	OwnerUsername    string
	CreatedTimestamp time.Time
	ItemCount        int
	TotalLength      time.Duration
	CurrentPlaying   string
}

type QueuePlaylistItem

type QueuePlaylistItem struct {
	Title    string
	Artist   string
	URL      string
	Duration time.Duration
	Id       int
	Index    int
}

type WebSocketConnection

type WebSocketConnection struct {
	Conn     *websocket.Conn
	Username string
}

type WebSocketEventType

type WebSocketEventType string

type WebSocketManager

type WebSocketManager struct {
	// contains filtered or unexported fields
}

func GetManager

func GetManager() *WebSocketManager

func (*WebSocketManager) Add

func (manager *WebSocketManager) Add(conn *websocket.Conn, playlist int, username string) string

func (*WebSocketManager) BroadcastPlaylist

func (manager *WebSocketManager) BroadcastPlaylist(id int, msg WebSocketMsg)

func (*WebSocketManager) Remove

func (manager *WebSocketManager) Remove(playlist int, username string, id string)

func (*WebSocketManager) SendId

func (manager *WebSocketManager) SendId(id string, msg WebSocketMsg)

type WebSocketMsg

type WebSocketMsg struct {
	Type    WebSocketMsgType `json:"type"`
	Payload interface{}      `json:"payload"`
}

type WebSocketMsgType

type WebSocketMsgType string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL