1 import { User } from '../'
2 import { UserRight, 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'
9 import { AuthUser } from '@app/core'
11 export class Video implements VideoServerModel {
12 byVideoChannel: string
15 accountAvatarUrl: string
16 videoChannelAvatarUrl: string
21 originallyPublishedAt: Date | string
22 category: VideoConstant<number>
23 licence: VideoConstant<number>
24 language: VideoConstant<string>
25 privacy: VideoConstant<VideoPrivacy>
45 originInstanceUrl: string
46 originInstanceHost: string
48 waitTranscoding?: boolean
49 state?: VideoConstant<VideoState>
50 scheduledUpdate?: VideoScheduleUpdate
52 blacklistedReason?: string
76 static buildClientUrl (videoUUID: string) {
77 return '/videos/watch/' + videoUUID
80 constructor (hash: VideoServerModel, translations = {}) {
81 const absoluteAPIUrl = getAbsoluteAPIUrl()
83 this.createdAt = new Date(hash.createdAt.toString())
84 this.publishedAt = new Date(hash.publishedAt.toString())
85 this.category = hash.category
86 this.licence = hash.licence
87 this.language = hash.language
88 this.privacy = hash.privacy
89 this.waitTranscoding = hash.waitTranscoding
90 this.state = hash.state
91 this.description = hash.description
93 this.duration = hash.duration
94 this.durationLabel = durationToString(hash.duration)
99 this.isLocal = hash.isLocal
100 this.name = hash.name
102 this.thumbnailPath = hash.thumbnailPath
103 this.thumbnailUrl = absoluteAPIUrl + hash.thumbnailPath
105 this.previewPath = hash.previewPath
106 this.previewUrl = absoluteAPIUrl + hash.previewPath
108 this.embedPath = hash.embedPath
109 this.embedUrl = absoluteAPIUrl + hash.embedPath
111 this.views = hash.views
112 this.likes = hash.likes
113 this.dislikes = hash.dislikes
115 this.nsfw = hash.nsfw
117 this.account = hash.account
118 this.channel = hash.channel
120 this.byAccount = Actor.CREATE_BY_STRING(hash.account.name, hash.account.host)
121 this.byVideoChannel = Actor.CREATE_BY_STRING(hash.channel.name, hash.channel.host)
122 this.accountAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.account)
123 this.videoChannelAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.channel)
125 this.category.label = peertubeTranslate(this.category.label, translations)
126 this.licence.label = peertubeTranslate(this.licence.label, translations)
127 this.language.label = peertubeTranslate(this.language.label, translations)
128 this.privacy.label = peertubeTranslate(this.privacy.label, translations)
130 this.scheduledUpdate = hash.scheduledUpdate
131 this.originallyPublishedAt = hash.originallyPublishedAt ? new Date(hash.originallyPublishedAt.toString()) : null
133 if (this.state) this.state.label = peertubeTranslate(this.state.label, translations)
135 this.blacklisted = hash.blacklisted
136 this.blacklistedReason = hash.blacklistedReason
138 this.userHistory = hash.userHistory
140 this.originInstanceHost = this.account.host
141 this.originInstanceUrl = 'https://' + this.originInstanceHost
144 isVideoNSFWForUser (user: User, serverConfig: ServerConfig) {
145 // Video is not NSFW, skip
146 if (this.nsfw === false) return false
148 // Return user setting if logged in
149 if (user) return user.nsfwPolicy !== 'display'
151 // Return default instance config
152 return serverConfig.instance.defaultNSFWPolicy !== 'display'
155 isRemovableBy (user: AuthUser) {
156 return user && this.isLocal === true && (this.account.name === user.username || user.hasRight(UserRight.REMOVE_ANY_VIDEO))
159 isBlackistableBy (user: AuthUser) {
160 return this.blacklisted !== true && user && user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) === true
163 isUnblacklistableBy (user: AuthUser) {
164 return this.blacklisted === true && user && user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) === true
167 isUpdatableBy (user: AuthUser) {
168 return user && this.isLocal === true && (this.account.name === user.username || user.hasRight(UserRight.UPDATE_ANY_VIDEO))
171 canBeDuplicatedBy (user: AuthUser) {
172 return user && this.isLocal === false && user.hasRight(UserRight.MANAGE_VIDEOS_REDUNDANCIES)