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

98 lines
2.9 KiB
TypeScript
Raw Normal View History

2017-10-25 16:43:19 +02:00
import {
2018-01-03 10:12:36 +01:00
UserRight, VideoChannel, VideoDetails as VideoDetailsServerModel, VideoFile, VideoPrivacy,
VideoResolution
2017-10-25 16:43:19 +02:00
} from '../../../../../shared'
2018-01-03 10:12:36 +01:00
import { Account } from '../../../../../shared/models/actors'
import { AuthUser } from '../../core'
import { Video } from '../../shared/video/video.model'
2017-10-25 16:43:19 +02:00
export class VideoDetails extends Video implements VideoDetailsServerModel {
2017-12-06 17:15:59 +01:00
accountName: string
2017-10-25 16:43:19 +02:00
by: string
createdAt: Date
updatedAt: Date
categoryLabel: string
category: number
licenceLabel: string
licence: number
languageLabel: string
language: number
description: string
support: string
2017-10-25 16:43:19 +02:00
duration: number
durationLabel: string
id: number
uuid: string
isLocal: boolean
name: string
2017-11-15 11:00:25 +01:00
serverHost: string
2017-10-25 16:43:19 +02:00
tags: string[]
thumbnailPath: string
thumbnailUrl: string
previewPath: string
previewUrl: string
embedPath: string
embedUrl: string
views: number
likes: number
dislikes: number
nsfw: boolean
descriptionPath: string
2017-10-25 16:43:19 +02:00
files: VideoFile[]
channel: VideoChannel
2017-10-31 11:52:52 +01:00
privacy: VideoPrivacy
privacyLabel: string
2017-12-06 17:15:59 +01:00
account: Account
2017-12-06 18:04:40 +01:00
likesPercent: number
dislikesPercent: number
2018-01-03 10:12:36 +01:00
commentsEnabled: boolean
2017-10-25 16:43:19 +02:00
constructor (hash: VideoDetailsServerModel) {
super(hash)
2017-10-31 11:52:52 +01:00
this.privacy = hash.privacy
this.privacyLabel = hash.privacyLabel
this.descriptionPath = hash.descriptionPath
2017-10-25 16:43:19 +02:00
this.files = hash.files
this.channel = hash.channel
2017-12-06 17:15:59 +01:00
this.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
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
}
getAppropriateMagnetUri (actualDownloadSpeed = 0) {
if (this.files === undefined || this.files.length === 0) return ''
if (this.files.length === 1) return this.files[0].magnetUri
// Find first video that is good for our download speed (remember they are sorted)
let betterResolutionFile = this.files.find(f => actualDownloadSpeed > (f.size / this.duration))
// If the download speed is too bad, return the lowest resolution we have
if (betterResolutionFile === undefined) {
betterResolutionFile = this.files.find(f => f.resolution === VideoResolution.H_240P)
}
return betterResolutionFile.magnetUri
}
isRemovableBy (user: AuthUser) {
2017-12-06 17:15:59 +01:00
return user && this.isLocal === true && (this.accountName === user.username || user.hasRight(UserRight.REMOVE_ANY_VIDEO))
2017-10-25 16:43:19 +02:00
}
isBlackistableBy (user: AuthUser) {
return user && user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) === true && this.isLocal === false
2017-10-25 16:43:19 +02:00
}
isUpdatableBy (user: AuthUser) {
return user && this.isLocal === true && (this.accountName === 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
}