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

94 lines
2.6 KiB
TypeScript
Raw Normal View History

2017-12-14 17:38:41 +01:00
import { Account } from '../../../../../shared/models/actors'
2017-12-01 18:56:26 +01:00
import { Video } from '../../shared/video/video.model'
import { AuthUser } from '../../core'
2017-10-25 16:43:19 +02:00
import {
VideoDetails as VideoDetailsServerModel,
VideoFile,
VideoChannel,
VideoResolution,
2017-10-31 11:52:52 +01:00
UserRight,
VideoPrivacy
2017-10-25 16:43:19 +02:00
} from '../../../../../shared'
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
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
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
2017-12-06 18:04:40 +01:00
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
}
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) {
2017-12-06 17:15:59 +01:00
return user && this.isLocal === true && user.username === this.accountName
2017-10-25 16:43:19 +02:00
}
}