1 import { User } from '../'
2 import { Video as VideoServerModel } from '../../../../../shared'
3 import { Account } from '../../../../../shared/models/accounts'
4 import { environment } from '../../../environments/environment'
6 export class Video implements VideoServerModel {
38 private static createByString (account: string, serverHost: string) {
39 return account + '@' + serverHost
42 private static createDurationString (duration: number) {
43 const minutes = Math.floor(duration / 60)
44 const seconds = duration % 60
45 const minutesPadding = minutes >= 10 ? '' : '0'
46 const secondsPadding = seconds >= 10 ? '' : '0'
48 return minutesPadding + minutes.toString() + ':' + secondsPadding + seconds.toString()
51 constructor (hash: VideoServerModel) {
52 let absoluteAPIUrl = environment.apiUrl
53 if (!absoluteAPIUrl) {
54 // The API is on the same domain
55 absoluteAPIUrl = window.location.origin
58 this.accountName = hash.accountName
59 this.createdAt = new Date(hash.createdAt.toString())
60 this.categoryLabel = hash.categoryLabel
61 this.category = hash.category
62 this.licenceLabel = hash.licenceLabel
63 this.licence = hash.licence
64 this.languageLabel = hash.languageLabel
65 this.language = hash.language
66 this.description = hash.description
67 this.duration = hash.duration
68 this.durationLabel = Video.createDurationString(hash.duration)
71 this.isLocal = hash.isLocal
73 this.serverHost = hash.serverHost
75 this.thumbnailPath = hash.thumbnailPath
76 this.thumbnailUrl = absoluteAPIUrl + hash.thumbnailPath
77 this.previewPath = hash.previewPath
78 this.previewUrl = absoluteAPIUrl + hash.previewPath
79 this.embedPath = hash.embedPath
80 this.embedUrl = absoluteAPIUrl + hash.embedPath
81 this.views = hash.views
82 this.likes = hash.likes
83 this.dislikes = hash.dislikes
86 this.by = Video.createByString(hash.accountName, hash.serverHost)
89 isVideoNSFWForUser (user: User) {
90 // If the video is NSFW and the user is not logged in, or the user does not want to display NSFW videos...
91 return (this.nsfw && (!user || user.displayNSFW === false))