1 import { Account } from '@app/shared/account/account.model'
2 import { User } from '../'
3 import { Video as VideoServerModel, VideoPrivacy } from '../../../../../shared'
4 import { Avatar } from '../../../../../shared/models/avatars/avatar.model'
5 import { VideoConstant } from '../../../../../shared/models/videos/video.model'
6 import { getAbsoluteAPIUrl } from '../misc/utils'
7 import { ServerConfig } from '../../../../../shared/models'
9 export class Video implements VideoServerModel {
14 category: VideoConstant<number>
15 licence: VideoConstant<number>
16 language: VideoConstant<string>
17 privacy: VideoConstant<VideoPrivacy>
47 private static createDurationString (duration: number) {
48 const hours = Math.floor(duration / 3600)
49 const minutes = Math.floor(duration % 3600 / 60)
50 const seconds = duration % 60
52 const minutesPadding = minutes >= 10 ? '' : '0'
53 const secondsPadding = seconds >= 10 ? '' : '0'
54 const displayedHours = hours > 0 ? hours.toString() + ':' : ''
56 return displayedHours + minutesPadding +
57 minutes.toString() + ':' + secondsPadding + seconds.toString()
60 constructor (hash: VideoServerModel) {
61 const absoluteAPIUrl = getAbsoluteAPIUrl()
63 this.createdAt = new Date(hash.createdAt.toString())
64 this.publishedAt = new Date(hash.publishedAt.toString())
65 this.category = hash.category
66 this.licence = hash.licence
67 this.language = hash.language
68 this.privacy = hash.privacy
69 this.description = hash.description
70 this.duration = hash.duration
71 this.durationLabel = Video.createDurationString(hash.duration)
74 this.isLocal = hash.isLocal
76 this.thumbnailPath = hash.thumbnailPath
77 this.thumbnailUrl = absoluteAPIUrl + hash.thumbnailPath
78 this.previewPath = hash.previewPath
79 this.previewUrl = absoluteAPIUrl + hash.previewPath
80 this.embedPath = hash.embedPath
81 this.embedUrl = absoluteAPIUrl + hash.embedPath
82 this.views = hash.views
83 this.likes = hash.likes
84 this.dislikes = hash.dislikes
86 this.account = hash.account
88 this.by = Account.CREATE_BY_STRING(hash.account.name, hash.account.host)
91 isVideoNSFWForUser (user: User, serverConfig: ServerConfig) {
92 // Video is not NSFW, skip
93 if (this.nsfw === false) return false
95 // Return user setting if logged in
96 if (user) return user.nsfwPolicy !== 'display'
98 // Return default instance config
99 return serverConfig.instance.defaultNSFWPolicy !== 'display'