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-constant.model'
5 import { durationToString, getAbsoluteAPIUrl } from '../misc/utils'
6 import { peertubeTranslate, ServerConfig } from '../../../../../shared/models'
7 import { Actor } from '@app/shared/actor/actor.model'
8 import { VideoScheduleUpdate } from '../../../../../shared/models/videos/video-schedule-update.model'
10 export class Video implements VideoServerModel {
11 byVideoChannel: string
14 accountAvatarUrl: string
15 videoChannelAvatarUrl: string
20 category: VideoConstant<number>
21 licence: VideoConstant<number>
22 language: VideoConstant<string>
23 privacy: VideoConstant<VideoPrivacy>
43 waitTranscoding?: boolean
44 state?: VideoConstant<VideoState>
45 scheduledUpdate?: VideoScheduleUpdate
47 blacklistedReason?: string
73 static buildClientUrl (videoUUID: string) {
74 return '/videos/watch/' + videoUUID
77 constructor (hash: VideoServerModel, translations = {}) {
78 const absoluteAPIUrl = getAbsoluteAPIUrl()
80 this.createdAt = new Date(hash.createdAt.toString())
81 this.publishedAt = new Date(hash.publishedAt.toString())
82 this.category = hash.category
83 this.licence = hash.licence
84 this.language = hash.language
85 this.privacy = hash.privacy
86 this.waitTranscoding = hash.waitTranscoding
87 this.state = hash.state
88 this.description = hash.description
89 this.duration = hash.duration
90 this.durationLabel = durationToString(hash.duration)
93 this.isLocal = hash.isLocal
95 this.thumbnailPath = hash.thumbnailPath
96 this.thumbnailUrl = absoluteAPIUrl + hash.thumbnailPath
97 this.previewPath = hash.previewPath
98 this.previewUrl = absoluteAPIUrl + hash.previewPath
99 this.embedPath = hash.embedPath
100 this.embedUrl = absoluteAPIUrl + hash.embedPath
101 this.views = hash.views
102 this.likes = hash.likes
103 this.dislikes = hash.dislikes
104 this.nsfw = hash.nsfw
105 this.account = hash.account
106 this.channel = hash.channel
108 this.byAccount = Actor.CREATE_BY_STRING(hash.account.name, hash.account.host)
109 this.byVideoChannel = Actor.CREATE_BY_STRING(hash.channel.name, hash.channel.host)
110 this.accountAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.account)
111 this.videoChannelAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.channel)
113 this.category.label = peertubeTranslate(this.category.label, translations)
114 this.licence.label = peertubeTranslate(this.licence.label, translations)
115 this.language.label = peertubeTranslate(this.language.label, translations)
116 this.privacy.label = peertubeTranslate(this.privacy.label, translations)
118 this.scheduledUpdate = hash.scheduledUpdate
119 if (this.state) this.state.label = peertubeTranslate(this.state.label, translations)
121 this.blacklisted = hash.blacklisted
122 this.blacklistedReason = hash.blacklistedReason
124 this.userHistory = hash.userHistory
127 isVideoNSFWForUser (user: User, serverConfig: ServerConfig) {
128 // Video is not NSFW, skip
129 if (this.nsfw === false) return false
131 // Return user setting if logged in
132 if (user) return user.nsfwPolicy !== 'display'
134 // Return default instance config
135 return serverConfig.instance.defaultNSFWPolicy !== 'display'