/
stream-unit.go
45 lines (38 loc) · 966 Bytes
/
stream-unit.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package model
import (
"fmt"
"html/template"
"github.com/microcosm-cc/bluemonday"
"github.com/russross/blackfriday/v2"
"gorm.io/gorm"
)
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 (s StreamUnit) GetUnitDurationMS() uint {
return s.UnitEnd - s.UnitStart
}
func (s StreamUnit) GetRoundedUnitLen() string {
lenS := (s.UnitEnd - s.UnitStart) / 1000
lenM := lenS / 60
lenH := lenM / 60
lenM = lenM % 60
lenS = lenS % 60
if lenH > 0 {
return fmt.Sprintf("%2dh, %2dmin", lenH, lenM)
}
return fmt.Sprintf("%2dmin, %2dsec", lenM, lenS)
}
func (s StreamUnit) GetDescriptionHTML() template.HTML {
unsafe := blackfriday.Run([]byte(s.UnitDescription))
html := bluemonday.
UGCPolicy().
AddTargetBlankToFullyQualifiedLinks(true).
SanitizeBytes(unsafe)
return template.HTML(html)
}