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

89 lines
2.7 KiB
TypeScript
Raw Normal View History

2017-12-01 18:56:26 +01:00
import { User } from '../'
2017-12-11 17:36:46 +01:00
import { Video as VideoServerModel } from '../../../../../shared'
2017-12-14 17:38:41 +01:00
import { Account } from '../../../../../shared/models/actors'
2017-12-11 17:36:46 +01:00
import { environment } from '../../../environments/environment'
2017-12-29 19:10:13 +01:00
import { getAbsoluteAPIUrl } from '../misc/utils'
2017-04-04 21:37:03 +02:00
2017-06-11 11:02:35 +02:00
export class Video implements VideoServerModel {
2017-12-06 17:15:59 +01:00
accountName: string
by: string
createdAt: Date
2017-09-12 12:53:55 +02:00
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
thumbnailPath: string
thumbnailUrl: string
2017-07-12 12:16:13 +02:00
previewPath: string
previewUrl: string
2017-10-16 10:05:49 +02:00
embedPath: string
embedUrl: string
views: number
likes: number
dislikes: number
nsfw: boolean
2017-12-06 17:15:59 +01:00
account: Account
2016-05-23 12:15:03 +02:00
2017-11-15 11:00:25 +01:00
private static createByString (account: string, serverHost: string) {
return account + '@' + serverHost
2016-05-23 12:15:03 +02:00
}
private static createDurationString (duration: number) {
const minutes = Math.floor(duration / 60)
const seconds = duration % 60
const minutesPadding = minutes >= 10 ? '' : '0'
const secondsPadding = seconds >= 10 ? '' : '0'
2016-05-27 17:49:18 +02:00
return minutesPadding + minutes.toString() + ':' + secondsPadding + seconds.toString()
2016-05-27 17:49:18 +02:00
}
2017-10-25 16:43:19 +02:00
constructor (hash: VideoServerModel) {
2017-12-29 19:10:13 +01:00
const absoluteAPIUrl = getAbsoluteAPIUrl()
2017-10-17 16:22:14 +02:00
2017-12-06 17:15:59 +01:00
this.accountName = hash.accountName
this.createdAt = new Date(hash.createdAt.toString())
this.categoryLabel = hash.categoryLabel
this.category = hash.category
this.licenceLabel = hash.licenceLabel
this.licence = hash.licence
this.languageLabel = hash.languageLabel
this.language = hash.language
this.description = hash.description
this.duration = hash.duration
this.durationLabel = Video.createDurationString(hash.duration)
this.id = hash.id
this.uuid = hash.uuid
this.isLocal = hash.isLocal
this.name = hash.name
2017-11-15 11:00:25 +01:00
this.serverHost = hash.serverHost
this.thumbnailPath = hash.thumbnailPath
2017-10-17 16:22:14 +02:00
this.thumbnailUrl = absoluteAPIUrl + hash.thumbnailPath
2017-07-12 12:16:13 +02:00
this.previewPath = hash.previewPath
2017-10-17 16:22:14 +02:00
this.previewUrl = absoluteAPIUrl + hash.previewPath
2017-10-16 10:05:49 +02:00
this.embedPath = hash.embedPath
2017-10-17 16:22:14 +02:00
this.embedUrl = absoluteAPIUrl + hash.embedPath
this.views = hash.views
this.likes = hash.likes
this.dislikes = hash.dislikes
this.nsfw = hash.nsfw
2016-05-27 17:49:18 +02:00
2017-12-06 17:15:59 +01:00
this.by = Video.createByString(hash.accountName, hash.serverHost)
}
isVideoNSFWForUser (user: User) {
2017-04-04 21:37:03 +02:00
// If the video is NSFW and the user is not logged in, or the user does not want to display NSFW videos...
return (this.nsfw && (!user || user.displayNSFW === false))
2017-04-04 21:37:03 +02:00
}
}