1 import { UserRight, VideoConstant, VideoDetails as VideoDetailsServerModel, VideoFile, VideoState } from '../../../../../shared'
2 import { AuthUser } from '../../core'
3 import { Video } from '../../shared/video/video.model'
4 import { Account } from '@app/shared/account/account.model'
5 import { VideoChannel } from '@app/shared/video-channel/video-channel.model'
7 export class VideoDetails extends Video implements VideoDetailsServerModel {
8 descriptionPath: string
14 commentsEnabled: boolean
16 waitTranscoding: boolean
17 state: VideoConstant<VideoState>
20 dislikesPercent: number
22 constructor (hash: VideoDetailsServerModel, translations = {}) {
23 super(hash, translations)
25 this.descriptionPath = hash.descriptionPath
26 this.files = hash.files
27 this.channel = new VideoChannel(hash.channel)
28 this.account = new Account(hash.account)
30 this.support = hash.support
31 this.commentsEnabled = hash.commentsEnabled
33 this.buildLikeAndDislikePercents()
36 isRemovableBy (user: AuthUser) {
37 return user && this.isLocal === true && (this.account.name === user.username || user.hasRight(UserRight.REMOVE_ANY_VIDEO))
40 isBlackistableBy (user: AuthUser) {
41 return this.blacklisted !== true && user && user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) === true
44 isUnblacklistableBy (user: AuthUser) {
45 return this.blacklisted === true && user && user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) === true
48 isUpdatableBy (user: AuthUser) {
49 return user && this.isLocal === true && (this.account.name === user.username || user.hasRight(UserRight.UPDATE_ANY_VIDEO))
52 buildLikeAndDislikePercents () {
53 this.likesPercent = (this.likes / (this.likes + this.dislikes)) * 100
54 this.dislikesPercent = (this.dislikes / (this.likes + this.dislikes)) * 100