Documentation ¶
Index ¶
- Variables
- func BuildTvheadendDvrUpdateRecordingOpts(idnode tvheadend.Idnode, opts UpdateRecording) (*tvheadend.DvrUpdateRecordingOpts, error)
- func MapTvheadendIconUrlToPiconID(iconUrl string) int
- type AuthContext
- type Channel
- type ChannelService
- type Clock
- type CreateRecording
- type CreateRecordingByEvent
- type EpgChannel
- type EpgContentType
- type EpgEvent
- type EpgEventsResult
- type EpgService
- type GetEpgEventsQueryParams
- type GetEpgQueryParams
- type GetRecordingsParams
- type InvalidOrExpiredTokenError
- type ListResult
- type PaginationQueryParams
- type PaginationSortQueryParams
- type PasswordAuthenticator
- type PiconService
- type Recording
- type RecordingListResult
- type RecordingService
- type Session
- type SessionManager
- type SessionRepository
- type SortQueryParams
- type StreamingService
- type Token
- type TokenRepository
- type TokenService
- type TwoFactorAuthService
- type TwoFactorSettings
- type TwoFactorSettingsRepository
- type UpdateRecording
- type User
- type UserQueryParams
- type UserRepository
Constants ¶
This section is empty.
Variables ¶
var ( ErrExpiredTokenLifetime = errors.New("expired token lifetime") ErrExpiredInactiveTokenLifetime = errors.New("expired inactive token lifetime") ErrTokenInvalid = errors.New("token invalid") ErrInvalidUsernameOrPassword = errors.New("invalid username or password") ErrConfirmationPasswordInvalid = errors.New("confirmation password is invalid") ErrTwoFactorRequired = errors.New("two factor auth is required") ErrTwoFactorCodeInvalid = errors.New("invalid two factor code provided") ErrTwoFactorAuthAlreadyEnabled = errors.New("two factor auth is already enabled") ErrTwoFactorAuthNotEnabled = errors.New("two factor auth is not enabled") ErrTwoFactorAuthSetupNotRunning = errors.New("two factor auth setup not running") )
var ( ErrPaginationInvalidLimit = errors.New("pagination limit invalid") ErrPaginationInvalidOffset = errors.New("pagination offset invalid") ErrSortInvalidDirection = errors.New("sort direction invalid") )
var ( ErrRecordingNotFound = errors.New("recording not found") ErrGetRecordingsInvalidStatus = errors.New("get recording status invalid") ErrCreateRecordingInvalidEventID = errors.New("recording event id invalid") ErrRecordingInvalidTitle = errors.New("recording invalid title") ErrRecordingInvalidChannelID = errors.New("recording invalid channel id") ErrRecordingInvalidStartDate = errors.New("recording invalid start date") ErrRecordingInvalidEndDate = errors.New("recording invalid end date") ErrRecordingInvalidEventID = errors.New("recording invalid event id") )
var ( ErrUsernameAlreadyExists = errors.New("username already exists") ErrEmailAlreadyExists = errors.New("email already exists") )
var (
ErrChannelNotFound = errors.New("channel not found")
)
var (
ErrEpgEventNotFound = errors.New("epg event not found")
)
var (
ErrPiconNotFound = errors.New("picon not found")
)
var (
ErrUnexpectedError = errors.New("unexpected error")
)
Functions ¶
func BuildTvheadendDvrUpdateRecordingOpts ¶
func BuildTvheadendDvrUpdateRecordingOpts( idnode tvheadend.Idnode, opts UpdateRecording, ) (*tvheadend.DvrUpdateRecordingOpts, error)
BuildTvheadendDvrUpdateRecordingOpts builds tvheadend.DvrUpdateRecordingOpts from an existing recording idnode and UpdateRecording.
Types ¶
type AuthContext ¶
type AuthContext struct { UserID int64 // SessionID is the session id for authorizations via session tokens. SessionID *int64 // ForwardAuth is true if the request was forwarded from a reverse proxy. ForwardAuth bool }
AuthContext represent the authenticated context for a user and a session.
type Channel ¶
type Channel struct { ID string `json:"id"` Enabled bool `json:"enabled"` Name string `json:"name"` Number int `json:"number"` PiconID int `json:"piconId"` }
Channel defines a channel in tvheadend.
type ChannelService ¶
type ChannelService interface { // GetAll returns a list of channels. GetAll(ctx context.Context, params PaginationSortQueryParams) ([]*Channel, error) // Get returns a channel by id. Get(ctx context.Context, id string) (*Channel, error) }
ChannelService provides access to channel resources from the tvheadend server.
type CreateRecording ¶
type CreateRecording struct { // Title title of the recording. Title string `json:"title"` // ExtraText optional extraText of the recording. ExtraText string `json:"extraText"` // ChannelID the channel id for the recording. ChannelID string `json:"channelId"` // StartAt start date of the recording as unix timestamp. StartsAt int64 `json:"startsAt"` // EndsAt end date of the recording as unix timestamp. EndsAt int64 `json:"endsAt"` // Comment optional comment of the recording. Comment string `json:"comment"` // StartPadding optional padding in minutes to record // before the recording starts. StartPadding int `json:"startPadding"` // EndPadding optional padding in minutes to record // after the recording ends. EndPadding int `json:"endPadding"` // Priority priority of the recording. Priority int `json:"priority"` // ConfigID configuration id of the dvr config. ConfigID string `json:"configId"` }
CreateRecording recording defines options to manually create a recording timer.
func (*CreateRecording) MapToTvheadendOpts ¶
func (c *CreateRecording) MapToTvheadendOpts() tvheadend.DvrCreateRecordingOpts
MapToTvheadendOpts maps CreateRecording to tvheadend.DvrCreateRecordingOpts.
func (*CreateRecording) Validate ¶
func (r *CreateRecording) Validate() error
Validate validates the minimum requirements of CreateRecording.
type CreateRecordingByEvent ¶
type CreateRecordingByEvent struct { EventID int64 `json:"eventId"` ConfigID string `json:"configId"` }
CreateRecordingByEvent defines options to create a recording by an epg event.
func (*CreateRecordingByEvent) Validate ¶
func (o *CreateRecordingByEvent) Validate() error
Validate validates the minimum requirements of CreateRecordingByEvent.
type EpgChannel ¶
type EpgChannel struct { ChannelID string `json:"channelId"` ChannelName string `json:"channelName"` ChannelNumber int64 `json:"channelNumber"` PiconID int `json:"piconId"` Events []*EpgEvent `json:"events"` }
EpgChannel defines a channel with epg events from tvheadend.
func BuildEpgResult ¶
func BuildEpgResult(grid tvheadend.EpgEventGrid, params SortQueryParams) []*EpgChannel
BuildEpgResult builds the epg result for a given tvheadend.EpgEventGrid and sorts th channels by the given SortQueryParams.
type EpgContentType ¶
EpgContentType defines a epg content type from tvheadend.
type EpgEvent ¶
type EpgEvent struct { ID int64 `json:"id"` AudioDesc bool `json:"audioDesc"` ChannelID string `json:"channelId"` ChannelName string `json:"channelName"` ChannelNumber int64 `json:"channelNumber"` PiconID int `json:"piconId"` Description string `json:"description"` EndsAt int64 `json:"endsAt"` HD bool `json:"hd"` NextEventID int `json:"nextEventId"` StartsAt int64 `json:"startsAt"` Subtitle string `json:"subtitle"` Subtitled bool `json:"subtitled"` Title string `json:"title"` Widescreen bool `json:"widescreen"` DvrUUID string `json:"dvrUuid,omitempty"` DvrState string `json:"dvrState,omitempty"` }
EpgEvent defines a epg event from tvheadend.
func BuildEpgEvent ¶
func BuildEpgEvent(src tvheadend.EpgEventGridEntry) EpgEvent
BuildEpgEvent maps a epg grid event entry from Tvheadend to a EpgEvent model.
type EpgEventsResult ¶
type EpgEventsResult = ListResult[*EpgEvent]
EpgEventsResult defines a ListResult of epg events.
func BuildEpgEventsResult ¶
func BuildEpgEventsResult(src tvheadend.EpgEventGrid, offset int64) EpgEventsResult
BuildEpgEventsResult builds the EpgEventsResult model for a given tvheadend.EpgEventGrid.
type EpgService ¶
type EpgService interface { // GetEpg returns the epg (events for each channel). GetEpg(ctx context.Context, params GetEpgQueryParams) ([]*EpgChannel, error) // GetEvents returns a list of epg events. GetEvents(ctx context.Context, params GetEpgEventsQueryParams) (*EpgEventsResult, error) // GetEvent returns a epg event. GetEvent(ctx context.Context, id int64) (*EpgEvent, error) // GetRelatedEvents returns a list of epg related events for a given event. GetRelatedEvents( ctx context.Context, eventId int64, params PaginationSortQueryParams, ) (*EpgEventsResult, error) // GetContentTypes returns a list of epg content types. GetContentTypes(ctx context.Context) ([]*EpgContentType, error) }
EpgService provides access to epg resources from the tvheadend server.
type GetEpgEventsQueryParams ¶
type GetEpgEventsQueryParams struct { PaginationSortQueryParams Title string `schema:"title"` FullText bool `schema:"fullText"` Language string `schema:"lang"` NowPlaying bool `schema:"nowPlaying"` // Channel name or id of the channel. Channel string `schema:"channel"` ContentType string `schema:"contentType"` DurationMin int64 `schema:"durationMin"` DurationMax int64 `schema:"durationMax"` StartsAt int64 `schema:"startsAt"` EndsAt int64 `schema:"endsAt"` }
GetEpgEventsQueryParams defines query params to paginate, sort and filter the epg.
func (*GetEpgEventsQueryParams) MapToTvheadendQuery ¶
func (p *GetEpgEventsQueryParams) MapToTvheadendQuery( sortKeyMapping map[string]string, ) (*tvheadend.Query, error)
MapToTvheadendQuery maps a GetEpgEventsQueryParams model to a tvheadend query model.
type GetEpgQueryParams ¶
type GetEpgQueryParams struct { SortQueryParams StartsAt int64 `schema:"startsAt"` EndsAt int64 `schema:"endsAt"` }
func (*GetEpgQueryParams) MapToTvheadendQuery ¶
func (p *GetEpgQueryParams) MapToTvheadendQuery( sortKeyMapping map[string]string, ) (*tvheadend.Query, error)
MapToTvheadendQuery maps a GetEpgQueryParams model to a tvheadend query model.
type GetRecordingsParams ¶
type GetRecordingsParams struct { PaginationSortQueryParams // upcoming, finished, failed, removed Status string `schema:"status"` }
GetRecordingsParams defines query params to paginate, sort and filter the recordings.
func (*GetRecordingsParams) Validate ¶
func (o *GetRecordingsParams) Validate() error
Validate validates the minimum requirements of GetRecordingsParams.
type InvalidOrExpiredTokenError ¶
type InvalidOrExpiredTokenError struct { // Reason is the reason why the token is invalid or expired. Reason error }
InvalidOrExpiredTokenError is returned when a token / session is invalid or expired.
func (InvalidOrExpiredTokenError) Error ¶
func (InvalidOrExpiredTokenError) Error() string
type ListResult ¶
type ListResult[T any] struct { Entries []T `json:"entries"` Total int64 `json:"total"` Offset int64 `json:"offset"` }
ListResult defines a generic result of multiple entries combined with the number of total results and the offset.
type PaginationQueryParams ¶
type PaginationQueryParams struct { // (Optional) Limit the result. Limit int64 `schema:"limit"` // (Optional) Offset the result. Offset int64 `schema:"offset"` }
PaginationQueryParams defines query params to paginate the result.
func (*PaginationQueryParams) MapToTvheadendQuery ¶
func (p *PaginationQueryParams) MapToTvheadendQuery() tvheadend.Query
func (*PaginationQueryParams) Validate ¶
func (p *PaginationQueryParams) Validate() error
type PaginationSortQueryParams ¶
type PaginationSortQueryParams struct { PaginationQueryParams SortQueryParams }
PaginationSortQueryParams defines query params to paginate and sort the result.
func (*PaginationSortQueryParams) MapToTvheadendQuery ¶
func (p *PaginationSortQueryParams) MapToTvheadendQuery( sortKeyMapping map[string]string, ) tvheadend.Query
func (*PaginationSortQueryParams) Validate ¶
func (p *PaginationSortQueryParams) Validate() error
type PasswordAuthenticator ¶
type PasswordAuthenticator interface { // Login logs in a user via login, password and optional totp code. Login(ctx context.Context, login string, username string, totp *string) (*User, error) // ConfirmPassword confirms the password of a user. ConfirmPassword(ctx context.Context, userID int64, password string) error }
PasswordAuthenticator defines operations to log in users via login and password.
type PiconService ¶
type Recording ¶
type Recording struct { ChannelID string `json:"channelId"` // ID of the event when the recordings was created by event. EventID int64 `json:"eventId,omitempty"` ChannelName string `json:"channelName"` PiconID int `json:"piconId"` CreatedAt int64 `json:"createdAt"` Duration int64 `json:"duration"` Enabled bool `json:"enabled"` Filename string `json:"filename"` ID string `json:"id"` LangTitle map[string]string `json:"langTitle"` Title string `json:"title"` Subtitle string `json:"subtitle"` Description string `json:"description"` ExtraText string `json:"extraText"` // OriginalStartsAt time stamp of the original start date // without StartPadding. OriginalStartsAt int64 `json:"originalStartsAt"` // OriginalEndsAt time stamp of the original end date // without theEndPadding. OriginalEndsAt int64 `json:"originalEndsAt"` // StartAt start date of the recording as unix timestamp. StartsAt int64 `json:"startsAt"` // EndsAt end date of the recording as unix timestamp. EndsAt int64 `json:"endsAt"` // StartPadding optional padding in minutes to record // before the recording starts. StartPadding int `json:"startPadding"` // EndPadding optional padding in minutes to record // after the recording ends. EndPadding int `json:"endPadding"` Status string `json:"status"` }
Recording defines a dvr entry from tvheadend. TODO: extend necessary fields.
func MapToTvheadendDvrGridEntryToRecording ¶
func MapToTvheadendDvrGridEntryToRecording(entry tvheadend.DvrGridEntry) Recording
MapToTvheadendDvrGridEntryToRecording maps a tvheadend.DvrGridEntry to a Recording.
type RecordingListResult ¶
type RecordingListResult = ListResult[*Recording]
RecordingListResult defines a ListResult of recordings.
type RecordingService ¶
type RecordingService interface { // CreateByEvent creates a new recording by an epg event. CreateByEvent(ctx context.Context, opts CreateRecordingByEvent) error // CreateByEvent creates a new recording by an epg event. Create(ctx context.Context, opts CreateRecording) error // GetAll returns a list of recordings. GetAll(ctx context.Context, params GetRecordingsParams) (*RecordingListResult, error) // Get returns a recording by its id. Get(ctx context.Context, id string) (*Recording, error) // Stop gracefully stops a running recording. Stop(ctx context.Context, id string) error // BatchStop gracefully stops running recordings. BatchStop(ctx context.Context, ids []string) error // Cancel deletes a upcoming recording or aborts a running recording. Cancel(ctx context.Context, id string) error // BatchCancel deletes multiple upcoming recordings or aborts running recordings. BatchCancel(ctx context.Context, ids []string) error // Remove removes a finished recording from disk. Remove(ctx context.Context, id string) error // BatchRemove removes multiple recordings from disk. BatchRemove(ctx context.Context, ids []string) error // MoveFinished moves a recording to finished status. MoveFinished(ctx context.Context, id string) error // MoveFailed moves a recording to failed status. MoveFailed(ctx context.Context, id string) error // UpdateRecording updates a recording. UpdateRecording(ctx context.Context, id string, opts UpdateRecording) error }
RecordingService provides access to recording resources from the tvheadend server.
type Session ¶
type Session struct { ID int64 `json:"id"` UserId int64 `json:"userId"` HashedToken string `json:"-"` ClientIP string `json:"clientIp"` UserAgent string `json:"userAgent"` CreatedAt int64 `json:"createdAt"` LastUsedAt int64 `json:"lastUsedAt"` RotatedAt int64 `json:"-"` }
Session defines a representation for a session of a user.
type SessionManager ¶
type SessionManager interface { // Validate validates a session and updates the last usage and rotates the token if needed. // The rotated token is returned as second return value when the token was rotated. Validate(ctx context.Context, token string) (*AuthContext, *string, error) // Create creates a new session for a user with a client ip and a user agent. Create(ctx context.Context, userId int64, clientIp string, userAgent string) (string, error) // Revoke revokes a specific session. Revoke(ctx context.Context, sessionID int64, userID int64) error }
SessionManager defines operations to manage a session of a user.
type SessionRepository ¶
type SessionRepository interface { // Find returns a sessions. Find(ctx context.Context, hashedToken string) (*Session, error) // FindByUser returns a list of sessions for a user. FindByUser(ctx context.Context, userID int64) ([]*Session, error) // Create persists a new session. Create(ctx context.Context, session *Session) error // Create persists a updated session. Update(ctx context.Context, session *Session) error // Delete deletes a session. Delete(ctx context.Context, sessionID int64, userID int64) error // DeleteExpired deletes all expired sessions. DeleteExpired( ctx context.Context, expirationDate int64, inactiveExpirationDate int64, ) (int64, error) }
SessionRepository defines CRUD operations for working with sessions.
type SortQueryParams ¶
type SortQueryParams struct { // (Optional) Sort key. SortKey string `schema:"sort_key"` // (Optional) Sort direction. SortDirection string `schema:"sort_dir"` }
SortQueryParams defines query params to sort the result.
func (*SortQueryParams) MapToTvheadendQuery ¶
func (p *SortQueryParams) MapToTvheadendQuery(sortKeyMapping map[string]string) tvheadend.Query
func (*SortQueryParams) Validate ¶
func (p *SortQueryParams) Validate() error
type StreamingService ¶
type StreamingService interface { // GetChannelStream returns a raw http response of the channel stream. GetChannelStream( ctx context.Context, channelNumber int64, profile string, ) (*http.Response, error) // GetRecordingStream returns a raw http response of the recording stream. GetRecordingStream(ctx context.Context, recordingId string) (*http.Response, error) }
type TokenRepository ¶
type TokenRepository interface { // FindByToken returns a Token by a the hashed token. FindByToken(ctx context.Context, token string) (*Token, error) // FindByUser returns all token for a user. FindByUser(ctx context.Context, userID int64) ([]*Token, error) // Create persists a new Token. Create(ctx context.Context, token *Token) error // Delete deletes a Token. Delete(ctx context.Context, token *Token) error }
TokenRepository defines CRUD operations working with Tokens.
type TokenService ¶
type TokenService interface { // Create creates a new token for a user. Create(ctx context.Context, userID int64, name string) (string, error) // Validate validates a token. Validate(ctx context.Context, token string) (*AuthContext, error) // Revoke revokes a token. Revoke(ctx context.Context, id int64) error }
TokenService defines operations to manage tokens for a user.
type TwoFactorAuthService ¶
type TwoFactorAuthService interface { // GetSettings returns the current two factor settings for a user. GetSettings(ctx context.Context, userId int64) (*TwoFactorSettings, error) // Setup starts the setup process for two factor auth for a user. Setup(ctx context.Context, userId int64) (string, error) // Deactivate deactivates two factor auth for a user. Deactivate(ctx context.Context, userId int64, code string) error // Activate activates two factor auth for a user. Activate(ctx context.Context, userID int64, code string) error // Verify verifies a two factor code for a user. Verify(ctx context.Context, userId int64, code *string) error }
TwoFactorAuthService defines operations to manage two factor auth for a user.
type TwoFactorSettings ¶
type TwoFactorSettings struct { UserID int64 `json:"-"` Secret string `json:"-"` Enabled bool `json:"enabled"` CreatedAt int64 `json:"-"` UpdatedAt int64 `json:"-"` }
TwoFactorSettings defines the two factor settings of a user.
type TwoFactorSettingsRepository ¶
type TwoFactorSettingsRepository interface { // Find returns two factor settings by a user id. Find(ctx context.Context, userID int64) (*TwoFactorSettings, error) // Create persists new two factor settings. Create(ctx context.Context, settings *TwoFactorSettings) error // Delete deletes two factor settings. Delete(ctx context.Context, settings *TwoFactorSettings) error Update(ctx context.Context, settings *TwoFactorSettings) error Save(ctx context.Context, settings *TwoFactorSettings) error }
TwoFactorSettingsRepository defines CRUD operations working with TwoFactorSettings.
type UpdateRecording ¶
type UpdateRecording struct { // Title title of the recording. Title *string `json:"title"` // ExtraText optional extraText of the recording. ExtraText *string `json:"extraText"` // StartAt start date of the recording as unix timestamp. StartsAt *int64 `json:"startsAt"` // EndsAt end date of the recording as unix timestamp. EndsAt *int64 `json:"endsAt"` // Comment optional comment of the recording. Comment *string `json:"comment"` // StartPadding optional padding in minutes to record // before the recording starts. StartPadding *int `json:"startPadding"` // EndPadding optional padding in minutes to record // after the recording ends. EndPadding *int `json:"endPadding"` // Priority priority of the recording. Priority *int `json:"priority"` // Enabled enabled status of the recording. Enabled *bool `json:"enabled"` // Episode episode of the recording. Episode *string `json:"episode"` }
UpdateRecording recording defines options to update a recording timer. The values are pointers because they are optional to provide.
func (*UpdateRecording) Validate ¶
func (r *UpdateRecording) Validate() error
type User ¶
type User struct { ID int64 `json:"id"` Username string `json:"username"` // PasswordHash hash of the users password PasswordHash string `json:"-"` Email string `json:"email"` DisplayName string `json:"displayName"` CreatedAt int64 `json:"createdAt"` UpdatedAt int64 `json:"updatedAt"` }
User represents a user.
type UserQueryParams ¶
type UserQueryParams struct { // (Optional) Limit the result. Limit int64 // (Optional) Offset the result. // Can only be used together with Limit. Offset int64 }
UserQueryParams defines user query parameters.
type UserRepository ¶
type UserRepository interface { // FindById returns a user by id. FindById(ctx context.Context, id int64) (*User, error) // FindByUsername returns a user by username. FindByUsername(ctx context.Context, user string) (*User, error) // Find returns a list of users paginated by UserQueryParams. Find(ctx context.Context, params UserQueryParams) ([]*User, error) // Create persists a new user. Create(ctx context.Context, user *User) error // Update persists an updated user. Update(ctx context.Context, user *User) error // Delete deletes a user. Delete(ctx context.Context, user *User) error }