1 import { User } from '../'
2 import { Video as VideoServerModel, VideoPrivacy, VideoState } from '../../../../../shared'
3 import { Avatar } from '../../../../../shared/models/avatars/avatar.model'
4 import { VideoConstant } from '../../../../../shared/models/videos/video.model'
5 import { getAbsoluteAPIUrl } from '../misc/utils'
6 import { ServerConfig } from '../../../../../shared/models'
7 import { Actor } from '@app/shared/actor/actor.model'
8 import { peertubeTranslate } from '@app/shared/i18n/i18n-utils'
10 export class Video implements VideoServerModel {
12 accountAvatarUrl: string
16 category: VideoConstant<number>
17 licence: VideoConstant<number>
18 language: VideoConstant<string>
19 privacy: VideoConstant<VideoPrivacy>
39 waitTranscoding?: boolean
40 state?: VideoConstant<VideoState>
62 private static createDurationString (duration: number) {
63 const hours = Math.floor(duration / 3600)
64 const minutes = Math.floor((duration % 3600) / 60)
65 const seconds = duration % 60
67 const minutesPadding = minutes >= 10 ? '' : '0'
68 const secondsPadding = seconds >= 10 ? '' : '0'
69 const displayedHours = hours > 0 ? hours.toString() + ':' : ''
71 return displayedHours + minutesPadding + minutes.toString() + ':' + secondsPadding + seconds.toString()
74 constructor (hash: VideoServerModel, translations = {}) {
75 const absoluteAPIUrl = getAbsoluteAPIUrl()
77 this.createdAt = new Date(hash.createdAt.toString())
78 this.publishedAt = new Date(hash.publishedAt.toString())
79 this.category = hash.category
80 this.licence = hash.licence
81 this.language = hash.language
82 this.privacy = hash.privacy
83 this.waitTranscoding = hash.waitTranscoding
84 this.state = hash.state
85 this.description = hash.description
86 this.duration = hash.duration
87 this.durationLabel = Video.createDurationString(hash.duration)
90 this.isLocal = hash.isLocal
92 this.thumbnailPath = hash.thumbnailPath
93 this.thumbnailUrl = absoluteAPIUrl + hash.thumbnailPath
94 this.previewPath = hash.previewPath
95 this.previewUrl = absoluteAPIUrl + hash.previewPath
96 this.embedPath = hash.embedPath
97 this.embedUrl = absoluteAPIUrl + hash.embedPath
98 this.views = hash.views
99 this.likes = hash.likes
100 this.dislikes = hash.dislikes
101 this.nsfw = hash.nsfw
102 this.account = hash.account
104 this.by = Actor.CREATE_BY_STRING(hash.account.name, hash.account.host)
105 this.accountAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.account)
107 this.category.label = peertubeTranslate(this.category.label, translations)
108 this.licence.label = peertubeTranslate(this.licence.label, translations)
109 this.language.label = peertubeTranslate(this.language.label, translations)
110 this.privacy.label = peertubeTranslate(this.privacy.label, translations)
112 if (this.state) this.state.label = peertubeTranslate(this.state.label, translations)
115 isVideoNSFWForUser (user: User, serverConfig: ServerConfig) {
116 // Video is not NSFW, skip
117 if (this.nsfw === false) return false
119 // Return user setting if logged in
120 if (user) return user.nsfwPolicy !== 'display'
122 // Return default instance config
123 return serverConfig.instance.defaultNSFWPolicy !== 'display'