model

package
v1.4.9 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2023 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FILETYPE_INVALID = iota
	// Deprecated: vods can now be downloaded from the edge server using the signed playlist url + ?download=1.
	FILETYPE_VOD
	FILETYPE_ATTACHMENT
	FILETYPE_IMAGE_JPG
	FILETYPE_THUMB_COMB
	FILETYPE_THUMB_CAM
	FILETYPE_THUMB_PRES
	FILETYPE_THUMB_LG_COMB
	FILETYPE_THUMB_LG_CAM
	FILETYPE_THUMB_LG_PRES
	FILETYPE_THUMB_LG_CAM_PRES // generated from CAM and PRES, preferred over the others
)
View Source
const (
	TargetAll      = iota + 1 //TargetAll Is any user, regardless if logged in or not
	TargetUser                //TargetUser Are all users that are logged in
	TargetStudent             //TargetStudent Are all users that are logged in and are students
	TargetLecturer            //TargetLecturer Are all users that are logged in and are lecturers
	TargetAdmin               //TargetAdmin Are all users that are logged in and are admins

)
View Source
const (
	VideoTypeCombined     VideoType = "COMB"
	VideoTypePresentation           = "PRES"
	VideoTypeCamera                 = "CAM"
)
View Source
const (
	AdminType    = 1
	LecturerType = 2
	GenericType  = 3
	StudentType  = 4
)
View Source
const TokenScopeAdmin = "admin"

Variables

View Source
var (
	ErrReplyToReply       = errors.New("reply to reply not allowed")
	ErrReplyToWrongStream = errors.New("reply to message from different stream not allowed")
	ErrReplyToNoMsg       = errors.New("reply to message not found")

	ErrMessageTooLong = errors.New("message too long")
	ErrMessageNoText  = errors.New("message has no text")
	ErrCooledDown     = errors.New("user is cooled down")
)
View Source
var (
	ErrUsernameTooLong = errors.New("username is too long")
	ErrUsernameNoText  = errors.New("username has no text")
)
View Source
var (
	ErrInvalidHash         = errors.New("the encoded hash is not in the correct format")
	ErrIncompatibleVersion = errors.New("incompatible version of argon2")
)

Functions

func GenerateFromPassword

func GenerateFromPassword(password string) (encodedHash string, err error)

func ParsableTimeFormat

func ParsableTimeFormat(time time.Time) string

ParsableTimeFormat returns a JavaScript friendly formatted date string

Types

type Audit

type Audit struct {
	gorm.Model

	User    *User // if nil -> system
	UserID  *uint
	Message string
	Type    AuditType
}

func (Audit) Json

func (a Audit) Json() gin.H

Json converts the audit into a json object consumed by apis

type AuditType

type AuditType uint
const (
	AuditInfo AuditType = iota + 1
	AuditWarning
	AuditError
	AuditCourseCreate
	AuditCourseEdit
	AuditCourseDelete
	AuditStreamCreate
	AuditStreamEdit
	AuditStreamDelete
	AuditCameraMoved
)

func GetAllAuditTypes

func GetAllAuditTypes() []AuditType

func (AuditType) String

func (t AuditType) String() string

String returns a string representation of the AuditType

type Bookmark

type Bookmark struct {
	gorm.Model

	Description string `gorm:"not null" json:"description"`
	Hours       uint   `gorm:"not null" json:"hours"`
	Minutes     uint   `gorm:"not null" json:"minutes"`
	Seconds     uint   `gorm:"not null" json:"seconds"`
	UserID      uint   `gorm:"not null" json:"-"`
	StreamID    uint   `gorm:"not null" json:"-"`
}

type CameraPreset

type CameraPreset struct {
	Name          string `gorm:"not null"`
	PresetID      int    `gorm:"primaryKey;autoIncrement:false"`
	Image         string
	LectureHallID uint `gorm:"primaryKey;autoIncrement:false"`
	IsDefault     bool // this will be selected if there's no preference
}

type CameraPresetPreference

type CameraPresetPreference struct {
	LectureHallID uint `json:"lecture_hall_id"`
	PresetID      int  `json:"preset_id"`
}

type CameraType

type CameraType uint
const (
	Axis CameraType = iota + 1
	Panasonic
)

type Chat

type Chat struct {
	gorm.Model

	UserID           string `gorm:"not null" json:"userId"`
	UserName         string `gorm:"not null" json:"name"`
	Message          string `gorm:"type:text;not null;index:,class:FULLTEXT" json:"-"`
	SanitizedMessage string `gorm:"-" json:"message"` // don't store the sanitized message in the database
	StreamID         uint   `gorm:"not null" json:"-"`
	Admin            bool   `gorm:"not null;default:false" json:"admin"`
	Color            string `gorm:"not null;default:'#368bd6'" json:"color"`

	Visible   sql.NullBool `gorm:"not null;default:true" json:"-"`
	IsVisible bool         `gorm:"-" json:"visible"` // IsVisible is .Bool value of Visible for simplicity

	Reactions []ChatReaction `gorm:"foreignKey:chat_id;" json:"reactions"`

	AddressedToUsers []User `gorm:"many2many:chat_user_addressedto" json:"-"`
	AddressedToIds   []uint `gorm:"-" json:"addressedTo"`

	Replies []Chat        `gorm:"foreignkey:ReplyTo" json:"replies"`
	ReplyTo sql.NullInt64 `json:"replyTo"`

	Resolved bool `gorm:"not null;default:false" json:"resolved"`
}

func (*Chat) AfterFind

func (c *Chat) AfterFind(_ *gorm.DB) (err error)

AfterFind is a GORM hook that sanitizes the message after it's loaded from the database.

func (*Chat) BeforeCreate

func (c *Chat) BeforeCreate(tx *gorm.DB) (err error)

BeforeCreate is a GORM hook that is called before a new chat is created. Messages won't be saved if any of these apply: - message is empty (after trimming) - message is too long (>maxMessageLength) - user is cooled down (user sent > coolDownMessages messages within coolDown) - message is a reply, and:

  • reply is to a reply (not allowed)
  • reply is to a message from a different stream
  • reply is to a message that doesn't exist

func (*Chat) SanitiseMessage

func (c *Chat) SanitiseMessage()

SanitiseMessage sets chat.SanitizedMessage to the sanitized html version of chat.Message, including <a> tags for links

type ChatReaction

type ChatReaction struct {
	ChatID   uint   `gorm:"primaryKey; not null" json:"chatID"`
	UserID   uint   `gorm:"primaryKey; not null" json:"userID"`
	Username string `gorm:"not null" json:"username"`
	Emoji    string `gorm:"primaryKey; not null" json:"emoji"`
}

type Course

type Course struct {
	gorm.Model

	UserID                  uint   `gorm:"not null"` // Owner of the course
	Name                    string `gorm:"not null"`
	Slug                    string `gorm:"not null"` // eg. eidi
	Year                    int    `gorm:"not null"` // eg. 2021
	TeachingTerm            string `gorm:"not null"` // eg. Summer/Winter
	TUMOnlineIdentifier     string
	VODEnabled              bool `gorm:"default:true"`
	DownloadsEnabled        bool `gorm:"default:false"`
	ChatEnabled             bool `gorm:"default:false"`
	AnonymousChatEnabled    bool `gorm:"not null;default:true"`
	ModeratedChatEnabled    bool `gorm:"not null;default:false"`
	VodChatEnabled          bool
	Visibility              string `gorm:"default:loggedin"` // public, loggedin or enrolled
	Streams                 []Stream
	Users                   []User `gorm:"many2many:course_users;"`
	Admins                  []User `gorm:"many2many:course_admins;"`
	Token                   string
	UserCreatedByToken      bool   `gorm:"default:false"`
	CameraPresetPreferences string // json encoded. e.g. [{lectureHallID:1, presetID:4}, ...]
	SourcePreferences       string // json encoded. e.g. [{lectureHallID:1, sourceMode:0}, ...]
	Pinned                  bool   `gorm:"-"` // Used to determine if the course is pinned when loaded for a specific user.

	LivePrivate bool `gorm:"not null; default:false"` // whether Livestreams are private
	VodPrivate  bool `gorm:"not null; default:false"` // Whether VODs are made private after livestreams
}

func (Course) AdminJson

func (c Course) AdminJson(lhs []LectureHall) []gin.H

AdminJson is the JSON representation of a courses streams for the admin panel

func (Course) CanUseSource

func (c Course) CanUseSource(lectureHallID uint, sourceType string) bool

CanUseSource returns whether the specified source type is allowed for the lecture hall id given

func (Course) CompareTo

func (c Course) CompareTo(other Course) bool

CompareTo used for sorting. Falling back to old java habits...

func (Course) GetCameraPresetPreference

func (c Course) GetCameraPresetPreference() []CameraPresetPreference

GetCameraPresetPreference retrieves the camera preset preferences

func (Course) GetLastRecording

func (c Course) GetLastRecording() Stream

GetLastRecording returns the most recent lecture of the course Assumes an ascending order of c.Streams

func (Course) GetLiveStreams

func (c Course) GetLiveStreams() []Stream

GetLiveStreams returns the current live streams of the course or an empty slice if none are live

func (Course) GetNextLecture

func (c Course) GetNextLecture() Stream

GetNextLecture returns the next lecture of the course

func (Course) GetNextLectureDate

func (c Course) GetNextLectureDate() time.Time

GetNextLectureDate returns the next lecture date of the course

func (Course) GetNextLectureDateFormatted

func (c Course) GetNextLectureDateFormatted() string

GetNextLectureDateFormatted returns a JavaScript friendly formatted date string

func (Course) GetRecordings

func (c Course) GetRecordings() []Stream

GetRecordings returns all recording of this course as streams

func (Course) GetSourceModeForLectureHall

func (c Course) GetSourceModeForLectureHall(id uint) SourceMode

GetSourceModeForLectureHall retrieves the source preference for the given lecture hall, returns default SourcePreference if non-existing

func (Course) GetSourcePreference

func (c Course) GetSourcePreference() []SourcePreference

GetSourcePreference retrieves the source preferences

func (Course) GetStreamUrl

func (c Course) GetStreamUrl(stream Stream) string

GetStreamUrl returns the URL of the stream, e.g. /w/MyStream/42

func (Course) GetUrl

func (c Course) GetUrl() string

GetUrl returns the URL of the course, e.g. /course/2022/S/MyCourse

func (Course) HasNextLecture

func (c Course) HasNextLecture() bool

HasNextLecture checks whether there is another upcoming lecture

func (Course) HasRecordings

func (c Course) HasRecordings() bool

HasRecordings returns whether the course has any recordings.

func (Course) HasStreams

func (c Course) HasStreams() bool

HasStreams checks whether the lecture has any streams (recorded, live or upcoming) associated to it

func (Course) IsEnrolled

func (c Course) IsEnrolled() bool

IsEnrolled returns true if visibility is set to 'enrolled' and false if not

func (Course) IsHidden

func (c Course) IsHidden() bool

IsHidden returns true if visibility is set to 'hidden' and false if not

func (Course) IsLive

func (c Course) IsLive() bool

IsLive returns whether the course has a lecture that is live

func (Course) IsLoggedIn

func (c Course) IsLoggedIn() bool

IsLoggedIn returns true if visibility is set to 'loggedin' and false if not

func (Course) IsNextLectureSelfStream

func (c Course) IsNextLectureSelfStream() bool

IsNextLectureSelfStream checks whether the next lecture is a self stream

func (Course) IsNextLectureStartingSoon

func (c Course) IsNextLectureStartingSoon() bool

IsNextLectureStartingSoon checks whether the course has a lecture that starts soon

func (Course) NextLectureHasReachedTimeSlot

func (c Course) NextLectureHasReachedTimeSlot() bool

NextLectureHasReachedTimeSlot returns whether the courses next lecture arrived at its timeslot

func (Course) NumStreams

func (c Course) NumStreams() int

NumStreams returns the number of streams for the course that are VoDs or live

func (Course) NumUsers

func (c Course) NumUsers() int

NumUsers returns the number of users enrolled in the course

func (*Course) SetCameraPresetPreference

func (c *Course) SetCameraPresetPreference(pref []CameraPresetPreference)

SetCameraPresetPreference updates the camera preset preferences

func (*Course) SetSourcePreference

func (c *Course) SetSourcePreference(pref []SourcePreference)

SetSourcePreference updates the source preferences

func (Course) StreamTimes

func (c Course) StreamTimes() []string

func (*Course) ToDTO

func (c *Course) ToDTO() CourseDTO

type CourseDTO

type CourseDTO struct {
	ID               uint
	Name             string
	Slug             string
	Visibility       string
	TeachingTerm     string
	Year             int
	DownloadsEnabled bool
	NextLecture      StreamDTO
	LastRecording    StreamDTO
	Streams          []StreamDTO
	IsAdmin          bool // Set in API handler
}

type DownloadableVod

type DownloadableVod struct {
	FriendlyName, DownloadURL string
}

type Email

type Email struct {
	gorm.Model

	From    string    `gorm:"not null"`
	To      string    `gorm:"not null"`
	Subject string    `gorm:"not null"`
	Body    string    `gorm:"longtext;not null"`
	Success bool      `gorm:"not null;default:false"`
	Retries int       `gorm:"not null;default:0"`
	LastTry time.Time `gorm:"default:null"`
	Errors  string    `gorm:"longtext;default:null"`
}

Email represents an email to be sent.

type File

type File struct {
	gorm.Model

	StreamID uint   `gorm:"not null"`
	Path     string `gorm:"not null"`
	Filename string
	Type     FileType `gorm:"not null; default: 1"`
}

func (File) GetDownloadFileName

func (f File) GetDownloadFileName() string

func (File) GetFriendlyFileName

func (f File) GetFriendlyFileName() string

func (File) GetVodTypeByName

func (f File) GetVodTypeByName() string

GetVodTypeByName infers the type of a video file based on its name.

func (File) IsThumb

func (f File) IsThumb() bool

func (File) IsURL

func (f File) IsURL() bool

type FileType

type FileType uint

type InfoPage

type InfoPage struct {
	gorm.Model

	Name       string       `gorm:"not null"` // e.g. 'privacy', 'imprint',...
	RawContent string       `gorm:"text; not null"`
	Type       InfoPageType `gorm:"not null; default: 1"`
}

func (InfoPage) Render

func (mt InfoPage) Render() template.HTML

type InfoPageType

type InfoPageType uint
const (
	INFOPAGE_MARKDOWN InfoPageType = iota + 1
)

type IngestServer

type IngestServer struct {
	gorm.Model  `json:"gorm_model"`
	Url         string       `json:"url"`                // e.g. rtmp://user:password@ingest1.huge.server.com
	OutUrl      string       `gorm:"not null"`           // e.g. https://out.server.com/streams/%s/playlist.m3u8 where %s is the stream name
	Workload    int          `json:"workload,omitempty"` // # of streams currently ingesting to this server
	StreamNames []StreamName // array of stream names that will be assigned to this server
}

IngestServer represents a server we ingest our streams to. This is used for load balancing.

type LectureHall

type LectureHall struct {
	gorm.Model

	Name           string `gorm:"not null"` //as in smp (e.g. room_00_13_009A)
	FullName       string `gorm:"not null"` //e.g. '5613.EG.009A (00.13.009A, Seminarraum), Boltzmannstr. 3(5613), 85748 Garching b. München'
	CombIP         string
	PresIP         string
	CamIP          string
	CameraIP       string     // ip of the actual camera (not smp)
	CameraType     CameraType `gorm:"not null; default:1"`
	Streams        []Stream
	CameraPresets  []CameraPreset
	RoomID         int    // used by TUMOnline
	PwrCtrlIp      string // power control api for red live light
	LiveLightIndex int    // id of power outlet for live light
	ExternalURL    string
}

func (LectureHall) NumSources

func (l LectureHall) NumSources() int

func (*LectureHall) ToDTO

func (l *LectureHall) ToDTO() *LectureHallDTO

type LectureHallDTO

type LectureHallDTO struct {
	ID          uint
	Name        string
	ExternalURL string
}

type Model

type Model struct {
	ID        uint           `gorm:"primarykey" json:"id"`
	CreatedAt time.Time      `json:"createdAt"`
	UpdatedAt time.Time      `json:"-"`
	DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}

Model is a base model that can be embedded in other models it's basically the same as gorm.Model but with convenient json annotations

type Notification

type Notification struct {
	Model

	Title  *string            `json:"title,omitempty"`
	Body   string             `json:"-" gorm:"not null"`
	Target NotificationTarget `json:"-" gorm:"not null; default:1"`

	// SanitizedBody is the body of the notification, converted from markdown to HTML
	SanitizedBody string `json:"body" gorm:"-"`
}

Notification is a message (e.g. a feature alert) that is displayed to users

func (*Notification) AfterFind

func (n *Notification) AfterFind(_ *gorm.DB) error

AfterFind populates the SanitizedBody after getting the Notification from the database

func (Notification) GetBodyForGoTemplate

func (n Notification) GetBodyForGoTemplate() template.HTML

type NotificationTarget

type NotificationTarget int

NotificationTarget is a User group the Notification is displayed to

type PlaybackSpeedSetting

type PlaybackSpeedSetting struct {
	Speed   float32 `json:"speed"`
	Enabled bool    `json:"enabled"`
}

type PlaybackSpeedSettings

type PlaybackSpeedSettings []PlaybackSpeedSetting

func (PlaybackSpeedSettings) GetEnabled

func (s PlaybackSpeedSettings) GetEnabled() (res []float32)

type Poll

type Poll struct {
	gorm.Model

	StreamID uint   // used by gorm
	Stream   Stream `gorm:"foreignKey:stream_id;not null;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
	Question string `gorm:"not null" json:"question"`
	Active   bool   `gorm:"not null;default:true" json:"active"`

	PollOptions []PollOption `gorm:"many2many:chat_poll_options" json:"pollOptions"`
}

type PollOption

type PollOption struct {
	gorm.Model

	Answer string `gorm:"not null" json:"answer"`
	Votes  []User `gorm:"many2many:poll_option_user_votes" json:"-"`
}

func (PollOption) GetStatsMap

func (o PollOption) GetStatsMap(votes int64) gin.H
type RegisterLink struct {
	gorm.Model

	UserID         uint   `gorm:"not null"`
	RegisterSecret string `gorm:"not null"`
}

type ServerNotification

type ServerNotification struct {
	gorm.Model

	Text    string    `gorm:"not null"`
	Warn    bool      `gorm:"not null;default:false"` // if false -> Info
	Start   time.Time `gorm:"not null"`
	Expires time.Time `gorm:"not null"`
}

ServerNotification todo: rename to ServerAlert to avoid confusion with Notification

func (ServerNotification) BeforeCreate

func (s ServerNotification) BeforeCreate(tx *gorm.DB) (err error)

func (ServerNotification) FormatExpires

func (s ServerNotification) FormatExpires() string

func (ServerNotification) FormatFrom

func (s ServerNotification) FormatFrom() string

func (ServerNotification) HTML

func (s ServerNotification) HTML() template.HTML
type ShortLink struct {
	gorm.Model

	Link     string `gorm:"type:varchar(256); unique; not null"`
	CourseId uint   `gorm:"not null"`
}

ShortLink friendly name for a link to courses highlight page

type Silence

type Silence struct {
	gorm.Model `json:"omitempty"`

	Start    uint `json:"start"`
	End      uint `json:"end"`
	StreamID uint `json:"stream_id,omitempty"`
}

type SourceMode

type SourceMode int

SourceMode 0 -> COMB, 1-> PRES, 2 -> CAM

type SourcePreference

type SourcePreference struct {
	LectureHallID uint       `json:"lecture_hall_id"`
	SourceMode    SourceMode `json:"source_mode"`
}

type Stat

type Stat struct {
	gorm.Model

	Time     time.Time `gorm:"not null"`
	StreamID uint      `gorm:"not null"`
	Viewers  uint      `gorm:"not null;default:0"`
	Live     bool      `gorm:"not null;default:false"`
}

type Stream

type Stream struct {
	gorm.Model

	Name                  string `gorm:"index:,class:FULLTEXT"`
	Description           string `gorm:"type:text;index:,class:FULLTEXT"`
	CourseID              uint
	Start                 time.Time `gorm:"not null"`
	End                   time.Time `gorm:"not null"`
	ChatEnabled           bool      `gorm:"default:null"`
	RoomName              string
	RoomCode              string
	EventTypeName         string
	TUMOnlineEventID      uint
	SeriesIdentifier      string `gorm:"default:null"`
	StreamKey             string `gorm:"not null"`
	PlaylistUrl           string
	PlaylistUrlPRES       string
	PlaylistUrlCAM        string
	LiveNow               bool      `gorm:"not null"`
	LiveNowTimestamp      time.Time `gorm:"default:null;column:live_now_timestamp"`
	Recording             bool
	Premiere              bool `gorm:"default:null"`
	Ended                 bool `gorm:"default:null"`
	Chats                 []Chat
	Stats                 []Stat
	Units                 []StreamUnit
	VodViews              uint `gorm:"default:0"` // todo: remove me before next semester
	StartOffset           uint `gorm:"default:null"`
	EndOffset             uint `gorm:"default:null"`
	LectureHallID         uint `gorm:"default:null"`
	Silences              []Silence
	Files                 []File `gorm:"foreignKey:StreamID"`
	ThumbInterval         uint32 `gorm:"default:null"`
	StreamName            string
	Duration              sql.NullInt32    `gorm:"default:null"`
	StreamWorkers         []Worker         `gorm:"many2many:stream_workers;"`
	StreamProgresses      []StreamProgress `gorm:"foreignKey:StreamID"`
	VideoSections         []VideoSection
	TranscodingProgresses []TranscodingProgress `gorm:"foreignKey:StreamID"`
	Private               bool                  `gorm:"not null;default:false"`

	Watched bool `gorm:"-"` // Used to determine if stream is watched when loaded for a specific user.
}

func (Stream) Attachments

func (s Stream) Attachments() []File

func (Stream) Color

func (s Stream) Color() string

Color returns the ui color of the stream that indicates it's status

func (Stream) FriendlyDate

func (s Stream) FriendlyDate() string

func (Stream) FriendlyNextDate

func (s Stream) FriendlyNextDate() string

func (Stream) FriendlyTime

func (s Stream) FriendlyTime() string

func (Stream) GetDescriptionHTML

func (s Stream) GetDescriptionHTML() string

func (Stream) GetLGThumbnail

func (s Stream) GetLGThumbnail() (string, error)

func (Stream) GetLGThumbnailForVideoType

func (s Stream) GetLGThumbnailForVideoType(videoType VideoType) (string, error)

func (Stream) GetName

func (s Stream) GetName() string

func (Stream) GetSilencesJson

func (s Stream) GetSilencesJson() string

func (Stream) GetStartInSeconds

func (s Stream) GetStartInSeconds() int

GetStartInSeconds returns the number of seconds until the stream starts (or 0 if it has already started or is a vod)

func (Stream) GetThumbIdForSource

func (s Stream) GetThumbIdForSource(source string) uint

GetThumbIdForSource returns the id of file that stores the thumbnail sprite for a specific source type.

func (Stream) GetVodFiles

func (s Stream) GetVodFiles() []DownloadableVod

GetVodFiles returns all downloadable files that user can see when using the download dropdown for a stream.

func (Stream) HLSUrl

func (s Stream) HLSUrl() string

func (Stream) IsComingUp

func (s Stream) IsComingUp() bool

IsComingUp returns whether the stream begins in 30 minutes

func (Stream) IsConverting

func (s Stream) IsConverting() bool

func (Stream) IsDownloadable

func (s Stream) IsDownloadable() bool

IsDownloadable returns true if the stream is a recording and has at least one stream associated with it.

func (Stream) IsPast

func (s Stream) IsPast() bool

IsPast returns whether the stream end time was reached

func (Stream) IsPlanned

func (s Stream) IsPlanned() bool

IsPlanned returns whether the stream is planned or not

func (Stream) IsSelfStream

func (s Stream) IsSelfStream() bool

IsSelfStream returns whether the stream is a scheduled stream in a lecture hall

func (Stream) IsStartingInMoreThanOneDay

func (s Stream) IsStartingInMoreThanOneDay() bool

IsStartingInMoreThanOneDay returns whether the stream starts in at least 2 days

func (Stream) IsStartingInOneDay

func (s Stream) IsStartingInOneDay() bool

IsStartingInOneDay returns whether the stream starts within 1 day

func (Stream) ParsableLiveNowTimestamp

func (s Stream) ParsableLiveNowTimestamp() string

ParsableLiveNowTimestamp returns a JavaScript friendly formatted date string

func (Stream) ParsableStartTime

func (s Stream) ParsableStartTime() string

ParsableStartTime returns a JavaScript friendly formatted date string

func (Stream) TimeSlotReached

func (s Stream) TimeSlotReached() bool

TimeSlotReached returns whether stream has passed the starting time

func (Stream) ToDTO

func (s Stream) ToDTO() StreamDTO

type StreamDTO

type StreamDTO struct {
	ID          uint
	Name        string
	Description string
	IsRecording bool
	IsPlanned   bool
	IsComingUp  bool
	HLSUrl      string
	Downloads   []DownloadableVod
	Start       time.Time
	End         time.Time
	Duration    int32
}

type StreamName

type StreamName struct {
	gorm.Model

	StreamName     string    `gorm:"type:varchar(64); unique; not null"`
	IsTranscoding  bool      `gorm:"not null;default:false"`
	IngestServerID uint      `gorm:"not null"`
	StreamID       uint      // Is null when the slot is not used
	FreedAt        time.Time `gorm:"not null;default:0"`
}

StreamName is essentially a "streaming slot" used for load balancing

type StreamProgress

type StreamProgress struct {
	Progress float64 `gorm:"not null" json:"progress"`              // The progress of the stream as represented as a floating point value between 0 and 1.
	Watched  bool    `gorm:"not null;default:false" json:"watched"` // Whether the user has marked the stream as watched.

	// We need to use a primary key in order to use ON CONFLICT in dao/progress.go, same as e.g. https://www.sqlite.org/lang_conflict.html.
	StreamID uint `gorm:"primaryKey" json:"streamId"`
	UserID   uint `gorm:"primaryKey" json:"-"`
}

StreamProgress represents the progress of a stream or video. Currently, it is only used for VoDs.

type StreamUnit

type StreamUnit struct {
	gorm.Model

	UnitName        string
	UnitDescription string
	UnitStart       uint `gorm:"not null"`
	UnitEnd         uint `gorm:"not null"`
	StreamID        uint `gorm:"not null"`
}

func (StreamUnit) GetDescriptionHTML

func (s StreamUnit) GetDescriptionHTML() template.HTML

func (StreamUnit) GetRoundedUnitLen

func (s StreamUnit) GetRoundedUnitLen() string

func (StreamUnit) GetUnitDurationMS

func (s StreamUnit) GetUnitDurationMS() uint

type StreamVersion

type StreamVersion string
const (
	COMB StreamVersion = "COMB"
	CAM  StreamVersion = "CAM"
	PRES StreamVersion = "PRES"
)

type Subtitles

type Subtitles struct {
	gorm.Model

	StreamID uint   `gorm:"not null"`
	Content  string `gorm:"not null"` // the .srt content provided by the voice-service
	Language string `gorm:"not null"`
}

Subtitles represents subtitles for a particular stream in a particular language

func (*Subtitles) AfterFind

func (s *Subtitles) AfterFind(tx *gorm.DB) (err error)

AfterFind is currently not implemented for Subtitles

func (*Subtitles) BeforeCreate

func (s *Subtitles) BeforeCreate(tx *gorm.DB) (err error)

BeforeCreate is currently not implemented for Subtitles

func (*Subtitles) TableName

func (*Subtitles) TableName() string

TableName returns the name of the table for the Subtitles model in the database.

type Token

type Token struct {
	gorm.Model
	UserID  uint         // used by gorm
	User    User         `gorm:"foreignKey:user_id;not null;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"` // creator of the token
	Token   string       `json:"token" gorm:"not null"`                                                     // secret token
	Expires sql.NullTime `json:"expires"`                                                                   // expiration date (null if none)
	Scope   string       `json:"scope" gorm:"not null"`                                                     // scope of the token, currently only admin
	LastUse sql.NullTime `json:"last_use"`                                                                  // last time the token was used
}

Token can be used to authenticate instead of a user account

type TranscodingFailure

type TranscodingFailure struct {
	gorm.Model

	StreamID uint `gorm:"not null"`
	Stream   Stream
	Version  StreamVersion `gorm:"not null"`
	Logs     string        `gorm:"not null"`
	ExitCode int
	FilePath string `gorm:"not null"` // the source file that could not be transcoded
	Hostname string `gorm:"not null"` // the hostname of the worker that failed

	// Ignored by gorm:
	FriendlyTime string `gorm:"-"`
}

TranscodingFailure represents a failed transcoding attempt

func (*TranscodingFailure) AfterFind

func (t *TranscodingFailure) AfterFind(tx *gorm.DB) (err error)

type TranscodingProgress

type TranscodingProgress struct {
	StreamID uint          `gorm:"primaryKey" json:"streamID"`
	Version  StreamVersion `gorm:"primaryKey" json:"version"`

	Progress int `gorm:"not null; default:0" json:"progress"`
}

TranscodingProgress is the progress as a percentage of the conversion of a single stream view (e.g. stream 123, COMB view)

type UploadKey

type UploadKey struct {
	gorm.Model
	UploadKey string `gorm:"not null"`
	Stream    Stream
	StreamID  uint
	VideoType VideoType `gorm:"not null"`
}

UploadKey represents a key that is created when a user uploads a file, sent to the worker with the upload request and back to TUM-Live to authenticate the request.

type User

type User struct {
	gorm.Model

	Name                string         `gorm:"type:varchar(80); not null" json:"name"`
	LastName            *string        `json:"-"`
	Email               sql.NullString `gorm:"type:varchar(256); uniqueIndex; default:null" json:"-"`
	MatriculationNumber string         `gorm:"type:varchar(256); uniqueIndex; default:null" json:"-"`
	LrzID               string         `json:"-"`
	Role                uint           `gorm:"default:4" json:"-"` // AdminType = 1, LecturerType = 2, GenericType = 3, StudentType  = 4
	Password            string         `gorm:"default:null" json:"-"`
	Courses             []Course       `gorm:"many2many:course_users" json:"-"` // courses a lecturer invited this user to
	AdministeredCourses []Course       `gorm:"many2many:course_admins"`         // courses this user is an admin of
	PinnedCourses       []Course       `gorm:"many2many:pinned_courses"`

	Settings  []UserSetting `gorm:"foreignkey:UserID"`
	Bookmarks []Bookmark    `gorm:"foreignkey:UserID" json:"-"`
}

func (*User) BeforeCreate

func (u *User) BeforeCreate(tx *gorm.DB) (err error)

BeforeCreate is a GORM hook that is called before a new user is created. Users won't be saved if any of these apply: - username is empty (after trimming) - username is too long (>maxUsernameLength)

func (*User) ComparePasswordAndHash

func (u *User) ComparePasswordAndHash(password string) (match bool, err error)

func (*User) CoursesForSemester

func (u *User) CoursesForSemester(year int, term string, context context.Context) []Course

func (*User) GetLoginString

func (u *User) GetLoginString() string

GetLoginString returns the email if it is set, otherwise the lrzID

func (*User) GetPlaybackSpeeds

func (u *User) GetPlaybackSpeeds() (speeds PlaybackSpeedSettings)

func (User) GetPreferredGreeting

func (u User) GetPreferredGreeting() string

GetPreferredGreeting returns the preferred greeting of the user if set, otherwise Moin

func (User) GetPreferredName

func (u User) GetPreferredName() string

GetPreferredName returns the preferred name of the user if set, otherwise the firstName from TUMOnline

func (*User) IsAdminOfCourse

func (u *User) IsAdminOfCourse(course Course) bool

IsAdminOfCourse checks if the user is an admin of the course

func (*User) IsEligibleToWatchCourse

func (u *User) IsEligibleToWatchCourse(course Course) bool

func (User) PreferredNameChangeAllowed

func (u User) PreferredNameChangeAllowed() bool

PreferredNameChangeAllowed returns false if the user has set a preferred name within the last 3 months, otherwise true

func (*User) SetPassword

func (u *User) SetPassword(password string) (err error)

type UserSetting

type UserSetting struct {
	gorm.Model

	UserID uint            `gorm:"not null"`
	Type   UserSettingType `gorm:"not null"`
	Value  string          `gorm:"not null"` //json encoded setting
}

type UserSettingType

type UserSettingType int
const (
	PreferredName UserSettingType = iota + 1
	Greeting
	CustomPlaybackSpeeds
)

type VideoSection

type VideoSection struct {
	gorm.Model

	Description  string `gorm:"not null;index:,class:FULLTEXT" json:"description"`
	StartHours   uint   `gorm:"not null" json:"startHours"`
	StartMinutes uint   `gorm:"not null" json:"startMinutes"`
	StartSeconds uint   `gorm:"not null" json:"startSeconds"`

	StreamID uint `gorm:"not null" json:"streamID"`
	FileID   uint `gorm:"not null" json:"fileID"`
}

type VideoSeekChunk

type VideoSeekChunk struct {
	ChunkIndex uint `gorm:"primaryKey;autoIncrement:false" json:"chunkIndex"`
	Hits       uint `gorm:"not null" json:"hits"`
	StreamID   uint `gorm:"primaryKey;autoIncrement:false" json:"streamID"`
}

type VideoType

type VideoType string

func (VideoType) Valid

func (v VideoType) Valid() bool

type Worker

type Worker struct {
	WorkerID string `gorm:"primaryKey"`
	Host     string
	Status   string
	Workload uint // How much the worker has to do. +1 per silence detection job, +2 per converting job, +3 per streaming job
	LastSeen time.Time

	// VM stats:
	CPU    string
	Memory string
	Disk   string
	Uptime string

	Version string
}

func (*Worker) IsAlive

func (w *Worker) IsAlive() bool

Directories

Path Synopsis
Package search contains models that won't be added to the database but are persisted in our search backend meilisearch.
Package search contains models that won't be added to the database but are persisted in our search backend meilisearch.

Jump to

Keyboard shortcuts

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