1 import { AuthUser } from '@app/core'
2 import { User } from '@app/core/users/user.model'
3 import { durationToString, getAbsoluteAPIUrl } from '@app/helpers'
9 Video as VideoServerModel,
14 } from '@shared/models'
15 import { environment } from '../../../../environments/environment'
16 import { Actor } from '../account/actor.model'
18 export class Video implements VideoServerModel {
19 byVideoChannel: string
22 accountAvatarUrl: string
23 videoChannelAvatarUrl: string
28 originallyPublishedAt: Date | string
29 category: VideoConstant<number>
30 licence: VideoConstant<number>
31 language: VideoConstant<string>
32 privacy: VideoConstant<VideoPrivacy>
57 originInstanceUrl: string
58 originInstanceHost: string
60 waitTranscoding?: boolean
61 state?: VideoConstant<VideoState>
62 scheduledUpdate?: VideoScheduleUpdate
64 blockedReason?: string
88 static buildClientUrl (videoUUID: string) {
89 return '/videos/watch/' + videoUUID
92 constructor (hash: VideoServerModel, translations = {}) {
93 const absoluteAPIUrl = getAbsoluteAPIUrl()
95 this.createdAt = new Date(hash.createdAt.toString())
96 this.publishedAt = new Date(hash.publishedAt.toString())
97 this.category = hash.category
98 this.licence = hash.licence
99 this.language = hash.language
100 this.privacy = hash.privacy
101 this.waitTranscoding = hash.waitTranscoding
102 this.state = hash.state
103 this.description = hash.description
105 this.duration = hash.duration
106 this.durationLabel = durationToString(hash.duration)
109 this.uuid = hash.uuid
111 this.isLocal = hash.isLocal
112 this.name = hash.name
114 this.thumbnailPath = hash.thumbnailPath
115 this.thumbnailUrl = hash.thumbnailUrl || (absoluteAPIUrl + hash.thumbnailPath)
117 this.previewPath = hash.previewPath
118 this.previewUrl = hash.previewUrl || (absoluteAPIUrl + hash.previewPath)
120 this.embedPath = hash.embedPath
121 this.embedUrl = hash.embedUrl || (environment.embedUrl + hash.embedPath)
125 this.views = hash.views
126 this.likes = hash.likes
127 this.dislikes = hash.dislikes
129 this.nsfw = hash.nsfw
131 this.account = hash.account
132 this.channel = hash.channel
134 this.byAccount = Actor.CREATE_BY_STRING(hash.account.name, hash.account.host)
135 this.byVideoChannel = Actor.CREATE_BY_STRING(hash.channel.name, hash.channel.host)
136 this.accountAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.account)
137 this.videoChannelAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.channel)
139 this.category.label = peertubeTranslate(this.category.label, translations)
140 this.licence.label = peertubeTranslate(this.licence.label, translations)
141 this.language.label = peertubeTranslate(this.language.label, translations)
142 this.privacy.label = peertubeTranslate(this.privacy.label, translations)
144 this.scheduledUpdate = hash.scheduledUpdate
145 this.originallyPublishedAt = hash.originallyPublishedAt ? new Date(hash.originallyPublishedAt.toString()) : null
147 if (this.state) this.state.label = peertubeTranslate(this.state.label, translations)
149 this.blacklisted = hash.blacklisted
150 this.blockedReason = hash.blacklistedReason
152 this.userHistory = hash.userHistory
154 this.originInstanceHost = this.account.host
155 this.originInstanceUrl = 'https://' + this.originInstanceHost
158 isVideoNSFWForUser (user: User, serverConfig: ServerConfig) {
159 // Video is not NSFW, skip
160 if (this.nsfw === false) return false
162 // Return user setting if logged in
163 if (user) return user.nsfwPolicy !== 'display'
165 // Return default instance config
166 return serverConfig.instance.defaultNSFWPolicy !== 'display'
169 isRemovableBy (user: AuthUser) {
170 return user && this.isLocal === true && (this.account.name === user.username || user.hasRight(UserRight.REMOVE_ANY_VIDEO))
173 isBlockableBy (user: AuthUser) {
174 return this.blacklisted !== true && user && user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) === true
177 isUnblockableBy (user: AuthUser) {
178 return this.blacklisted === true && user && user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) === true
181 isUpdatableBy (user: AuthUser) {
182 return user && this.isLocal === true && (this.account.name === user.username || user.hasRight(UserRight.UPDATE_ANY_VIDEO))
185 canBeDuplicatedBy (user: AuthUser) {
186 return user && this.isLocal === false && user.hasRight(UserRight.MANAGE_VIDEOS_REDUNDANCIES)