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 originallyPublishedAt: Date | string
21 category: VideoConstant<number>
22 licence: VideoConstant<number>
23 language: VideoConstant<string>
24 privacy: VideoConstant<VideoPrivacy>
44 waitTranscoding?: boolean
45 state?: VideoConstant<VideoState>
46 scheduledUpdate?: VideoScheduleUpdate
48 blacklistedReason?: string
74 static buildClientUrl (videoUUID: string) {
75 return '/videos/watch/' + videoUUID
78 constructor (hash: VideoServerModel, translations = {}) {
79 const absoluteAPIUrl = getAbsoluteAPIUrl()
81 this.createdAt = new Date(hash.createdAt.toString())
82 this.publishedAt = new Date(hash.publishedAt.toString())
83 this.category = hash.category
84 this.licence = hash.licence
85 this.language = hash.language
86 this.privacy = hash.privacy
87 this.waitTranscoding = hash.waitTranscoding
88 this.state = hash.state
89 this.description = hash.description
90 this.duration = hash.duration
91 this.durationLabel = durationToString(hash.duration)
94 this.isLocal = hash.isLocal
96 this.thumbnailPath = hash.thumbnailPath
97 this.thumbnailUrl = absoluteAPIUrl + hash.thumbnailPath
98 this.previewPath = hash.previewPath
99 this.previewUrl = absoluteAPIUrl + hash.previewPath
100 this.embedPath = hash.embedPath
101 this.embedUrl = absoluteAPIUrl + hash.embedPath
102 this.views = hash.views
103 this.likes = hash.likes
104 this.dislikes = hash.dislikes
105 this.nsfw = hash.nsfw
106 this.account = hash.account
107 this.channel = hash.channel
109 this.byAccount = Actor.CREATE_BY_STRING(hash.account.name, hash.account.host)
110 this.byVideoChannel = Actor.CREATE_BY_STRING(hash.channel.name, hash.channel.host)
111 this.accountAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.account)
112 this.videoChannelAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.channel)
114 this.category.label = peertubeTranslate(this.category.label, translations)
115 this.licence.label = peertubeTranslate(this.licence.label, translations)
116 this.language.label = peertubeTranslate(this.language.label, translations)
117 this.privacy.label = peertubeTranslate(this.privacy.label, translations)
119 this.scheduledUpdate = hash.scheduledUpdate
120 this.originallyPublishedAt = hash.originallyPublishedAt ?
121 new Date(hash.originallyPublishedAt.toString())
123 if (this.state) this.state.label = peertubeTranslate(this.state.label, translations)
125 this.blacklisted = hash.blacklisted
126 this.blacklistedReason = hash.blacklistedReason
128 this.userHistory = hash.userHistory
131 isVideoNSFWForUser (user: User, serverConfig: ServerConfig) {
132 // Video is not NSFW, skip
133 if (this.nsfw === false) return false
135 // Return user setting if logged in
136 if (user) return user.nsfwPolicy !== 'display'
138 // Return default instance config
139 return serverConfig.instance.defaultNSFWPolicy !== 'display'