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'
6 import { VideoStreamingPlaylist } from '../../../../../shared/models/videos/video-streaming-playlist.model'
7 import { VideoStreamingPlaylistType } from '../../../../../shared/models/videos/video-streaming-playlist.type'
9 export class VideoDetails extends Video implements VideoDetailsServerModel {
10 descriptionPath: string
16 commentsEnabled: boolean
17 downloadEnabled: boolean
19 waitTranscoding: boolean
20 state: VideoConstant<VideoState>
23 dislikesPercent: number
27 streamingPlaylists: VideoStreamingPlaylist[]
29 constructor (hash: VideoDetailsServerModel, translations = {}) {
30 super(hash, translations)
32 this.descriptionPath = hash.descriptionPath
33 this.files = hash.files
34 this.channel = new VideoChannel(hash.channel)
35 this.account = new Account(hash.account)
37 this.support = hash.support
38 this.commentsEnabled = hash.commentsEnabled
39 this.downloadEnabled = hash.downloadEnabled
41 this.trackerUrls = hash.trackerUrls
42 this.streamingPlaylists = hash.streamingPlaylists
44 this.buildLikeAndDislikePercents()
47 isRemovableBy (user: AuthUser) {
48 return user && this.isLocal === true && (this.account.name === user.username || user.hasRight(UserRight.REMOVE_ANY_VIDEO))
51 isBlackistableBy (user: AuthUser) {
52 return this.blacklisted !== true && user && user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) === true
55 isUnblacklistableBy (user: AuthUser) {
56 return this.blacklisted === true && user && user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) === true
59 isUpdatableBy (user: AuthUser) {
60 return user && this.isLocal === true && (this.account.name === user.username || user.hasRight(UserRight.UPDATE_ANY_VIDEO))
63 buildLikeAndDislikePercents () {
64 this.likesPercent = (this.likes / (this.likes + this.dislikes)) * 100
65 this.dislikesPercent = (this.dislikes / (this.likes + this.dislikes)) * 100
69 return this.streamingPlaylists.find(p => p.type === VideoStreamingPlaylistType.HLS)