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
69 static buildClientUrl (videoUUID: string) {
70 return '/videos/watch/' + videoUUID
73 constructor (hash: VideoServerModel, translations = {}) {
74 const absoluteAPIUrl = getAbsoluteAPIUrl()
76 this.createdAt = new Date(hash.createdAt.toString())
77 this.publishedAt = new Date(hash.publishedAt.toString())
78 this.category = hash.category
79 this.licence = hash.licence
80 this.language = hash.language
81 this.privacy = hash.privacy
82 this.waitTranscoding = hash.waitTranscoding
83 this.state = hash.state
84 this.description = hash.description
85 this.duration = hash.duration
86 this.durationLabel = durationToString(hash.duration)
89 this.isLocal = hash.isLocal
91 this.thumbnailPath = hash.thumbnailPath
92 this.thumbnailUrl = absoluteAPIUrl + hash.thumbnailPath
93 this.previewPath = hash.previewPath
94 this.previewUrl = absoluteAPIUrl + hash.previewPath
95 this.embedPath = hash.embedPath
96 this.embedUrl = absoluteAPIUrl + hash.embedPath
97 this.views = hash.views
98 this.likes = hash.likes
99 this.dislikes = hash.dislikes
100 this.nsfw = hash.nsfw
101 this.account = hash.account
102 this.channel = hash.channel
104 this.byAccount = Actor.CREATE_BY_STRING(hash.account.name, hash.account.host)
105 this.byVideoChannel = Actor.CREATE_BY_STRING(hash.channel.name, hash.channel.host)
106 this.accountAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.account)
107 this.videoChannelAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.channel)
109 this.category.label = peertubeTranslate(this.category.label, translations)
110 this.licence.label = peertubeTranslate(this.licence.label, translations)
111 this.language.label = peertubeTranslate(this.language.label, translations)
112 this.privacy.label = peertubeTranslate(this.privacy.label, translations)
114 this.scheduledUpdate = hash.scheduledUpdate
115 if (this.state) this.state.label = peertubeTranslate(this.state.label, translations)
117 this.blacklisted = hash.blacklisted
118 this.blacklistedReason = hash.blacklistedReason
121 isVideoNSFWForUser (user: User, serverConfig: ServerConfig) {
122 // Video is not NSFW, skip
123 if (this.nsfw === false) return false
125 // Return user setting if logged in
126 if (user) return user.nsfwPolicy !== 'display'
128 // Return default instance config
129 return serverConfig.instance.defaultNSFWPolicy !== 'display'