]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/video/video-details.model.ts
Refactor video miniatures
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / video / video-details.model.ts
CommitLineData
22a16e36 1import { UserRight, VideoConstant, VideoDetails as VideoDetailsServerModel, VideoFile, VideoState } from '../../../../../shared'
47564bbe
C
2import { AuthUser } from '../../core'
3import { Video } from '../../shared/video/video.model'
ad9e39fb 4import { Account } from '@app/shared/account/account.model'
22a16e36 5import { VideoChannel } from '@app/shared/video-channel/video-channel.model'
09209296
C
6import { VideoStreamingPlaylist } from '../../../../../shared/models/videos/video-streaming-playlist.model'
7import { VideoStreamingPlaylistType } from '../../../../../shared/models/videos/video-streaming-playlist.type'
404b54e1
C
8
9export class VideoDetails extends Video implements VideoDetailsServerModel {
09700934 10 descriptionPath: string
2422c46b 11 support: string
09700934 12 channel: VideoChannel
404b54e1 13 tags: string[]
404b54e1 14 files: VideoFile[]
b1fa3eba 15 account: Account
09700934 16 commentsEnabled: boolean
7f2cfe3a 17 downloadEnabled: boolean
09700934 18
2186386c
C
19 waitTranscoding: boolean
20 state: VideoConstant<VideoState>
21
6a9e1d42
C
22 likesPercent: number
23 dislikesPercent: number
404b54e1 24
09209296
C
25 trackerUrls: string[]
26
27 streamingPlaylists: VideoStreamingPlaylist[]
28
7ce44a74
C
29 constructor (hash: VideoDetailsServerModel, translations = {}) {
30 super(hash, translations)
404b54e1 31
2de96f4d 32 this.descriptionPath = hash.descriptionPath
404b54e1 33 this.files = hash.files
22a16e36 34 this.channel = new VideoChannel(hash.channel)
ad9e39fb 35 this.account = new Account(hash.account)
d48ff09d 36 this.tags = hash.tags
07fa4c97 37 this.support = hash.support
47564bbe 38 this.commentsEnabled = hash.commentsEnabled
7f2cfe3a 39 this.downloadEnabled = hash.downloadEnabled
6a9e1d42 40
09209296
C
41 this.trackerUrls = hash.trackerUrls
42 this.streamingPlaylists = hash.streamingPlaylists
43
20b40b19 44 this.buildLikeAndDislikePercents()
404b54e1
C
45 }
46
954605a8 47 isRemovableBy (user: AuthUser) {
09700934 48 return user && this.isLocal === true && (this.account.name === user.username || user.hasRight(UserRight.REMOVE_ANY_VIDEO))
404b54e1
C
49 }
50
954605a8 51 isBlackistableBy (user: AuthUser) {
191764f3
C
52 return this.blacklisted !== true && user && user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) === true
53 }
54
55 isUnblacklistableBy (user: AuthUser) {
56 return this.blacklisted === true && user && user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) === true
404b54e1
C
57 }
58
954605a8 59 isUpdatableBy (user: AuthUser) {
09700934 60 return user && this.isLocal === true && (this.account.name === user.username || user.hasRight(UserRight.UPDATE_ANY_VIDEO))
404b54e1 61 }
20b40b19
C
62
63 buildLikeAndDislikePercents () {
64 this.likesPercent = (this.likes / (this.likes + this.dislikes)) * 100
65 this.dislikesPercent = (this.dislikes / (this.likes + this.dislikes)) * 100
66 }
09209296
C
67
68 getHlsPlaylist () {
69 return this.streamingPlaylists.find(p => p.type === VideoStreamingPlaylistType.HLS)
70 }
404b54e1 71}