PeerTube/client/src/app/shared/video/video-details.model.ts

59 lines
2.0 KiB
TypeScript
Raw Normal View History

2018-08-21 16:18:59 +02:00
import { UserRight, VideoConstant, VideoDetails as VideoDetailsServerModel, VideoFile, VideoState } from '../../../../../shared'
2018-01-03 10:12:36 +01:00
import { AuthUser } from '../../core'
import { Video } from '../../shared/video/video.model'
2018-05-25 09:57:16 +02:00
import { Account } from '@app/shared/account/account.model'
2018-08-21 16:18:59 +02:00
import { VideoChannel } from '@app/shared/video-channel/video-channel.model'
2017-10-25 16:43:19 +02:00
export class VideoDetails extends Video implements VideoDetailsServerModel {
descriptionPath: string
support: string
channel: VideoChannel
2017-10-25 16:43:19 +02:00
tags: string[]
files: VideoFile[]
2017-12-06 17:15:59 +01:00
account: Account
commentsEnabled: boolean
downloadingEnabled: boolean
waitTranscoding: boolean
state: VideoConstant<VideoState>
2017-12-06 18:04:40 +01:00
likesPercent: number
dislikesPercent: number
2017-10-25 16:43:19 +02:00
2018-06-06 16:46:42 +02:00
constructor (hash: VideoDetailsServerModel, translations = {}) {
super(hash, translations)
2017-10-25 16:43:19 +02:00
this.descriptionPath = hash.descriptionPath
2017-10-25 16:43:19 +02:00
this.files = hash.files
2018-08-21 16:18:59 +02:00
this.channel = new VideoChannel(hash.channel)
2018-05-25 09:57:16 +02:00
this.account = new Account(hash.account)
2017-12-14 10:07:57 +01:00
this.tags = hash.tags
2018-02-20 16:13:05 +01:00
this.support = hash.support
2018-01-03 10:12:36 +01:00
this.commentsEnabled = hash.commentsEnabled
this.downloadingEnabled = hash.downloadingEnabled
2017-12-06 18:04:40 +01:00
2018-02-28 09:49:40 +01:00
this.buildLikeAndDislikePercents()
2017-10-25 16:43:19 +02:00
}
isRemovableBy (user: AuthUser) {
return user && this.isLocal === true && (this.account.name === user.username || user.hasRight(UserRight.REMOVE_ANY_VIDEO))
2017-10-25 16:43:19 +02:00
}
isBlackistableBy (user: AuthUser) {
2018-08-14 09:08:47 +02:00
return this.blacklisted !== true && user && user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) === true
}
isUnblacklistableBy (user: AuthUser) {
return this.blacklisted === true && user && user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) === true
2017-10-25 16:43:19 +02:00
}
isUpdatableBy (user: AuthUser) {
return user && this.isLocal === true && (this.account.name === user.username || user.hasRight(UserRight.UPDATE_ANY_VIDEO))
2017-10-25 16:43:19 +02:00
}
2018-02-28 09:49:40 +01:00
buildLikeAndDislikePercents () {
this.likesPercent = (this.likes / (this.likes + this.dislikes)) * 100
this.dislikesPercent = (this.dislikes / (this.likes + this.dislikes)) * 100
}
2017-10-25 16:43:19 +02:00
}