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