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>
45 private static createDurationString (duration: number) {
46 const hours = Math.floor(duration / 3600)
47 const minutes = Math.floor(duration % 3600 / 60)
48 const seconds = duration % 60
50 const minutesPadding = minutes >= 10 ? '' : '0'
51 const secondsPadding = seconds >= 10 ? '' : '0'
52 const displayedHours = hours > 0 ? hours.toString() + ':' : ''
54 return displayedHours + minutesPadding +
55 minutes.toString() + ':' + secondsPadding + seconds.toString()
58 constructor (hash: VideoServerModel) {
59 const absoluteAPIUrl = getAbsoluteAPIUrl()
61 this.createdAt = new Date(hash.createdAt.toString())
62 this.publishedAt = new Date(hash.publishedAt.toString())
63 this.category = hash.category
64 this.licence = hash.licence
65 this.language = hash.language
66 this.privacy = hash.privacy
67 this.description = hash.description
68 this.duration = hash.duration
69 this.durationLabel = Video.createDurationString(hash.duration)
72 this.isLocal = hash.isLocal
74 this.thumbnailPath = hash.thumbnailPath
75 this.thumbnailUrl = absoluteAPIUrl + hash.thumbnailPath
76 this.previewPath = hash.previewPath
77 this.previewUrl = absoluteAPIUrl + hash.previewPath
78 this.embedPath = hash.embedPath
79 this.embedUrl = absoluteAPIUrl + hash.embedPath
80 this.views = hash.views
81 this.likes = hash.likes
82 this.dislikes = hash.dislikes
84 this.account = hash.account
86 this.by = Account.CREATE_BY_STRING(hash.account.name, hash.account.host)
89 isVideoNSFWForUser (user: User, serverConfig: ServerConfig) {
90 // Video is not NSFW, skip
91 if (this.nsfw === false) return false
93 // Return user setting if logged in
94 if (user) return user.nsfwPolicy !== 'display'
96 // Return default instance config
97 return serverConfig.instance.defaultNSFWPolicy !== 'display'