1 import { Video as VideoServerModel } from '../../../../../shared'
2 import { User } from '../../shared'
4 export class Video implements VideoServerModel {
30 private static createByString (author: string, podHost: string) {
31 return author + '@' + podHost
34 private static createDurationString (duration: number) {
35 const minutes = Math.floor(duration / 60)
36 const seconds = duration % 60
37 const minutesPadding = minutes >= 10 ? '' : '0'
38 const secondsPadding = seconds >= 10 ? '' : '0'
40 return minutesPadding + minutes.toString() + ':' + secondsPadding + seconds.toString()
46 categoryLabel: string,
60 thumbnailPath: string,
66 this.author = hash.author
67 this.createdAt = new Date(hash.createdAt)
68 this.categoryLabel = hash.categoryLabel
69 this.category = hash.category
70 this.licenceLabel = hash.licenceLabel
71 this.licence = hash.licence
72 this.languageLabel = hash.languageLabel
73 this.language = hash.language
74 this.description = hash.description
75 this.duration = hash.duration
76 this.durationLabel = Video.createDurationString(hash.duration)
78 this.isLocal = hash.isLocal
79 this.magnetUri = hash.magnetUri
81 this.podHost = hash.podHost
83 this.thumbnailPath = hash.thumbnailPath
84 this.thumbnailUrl = API_URL + hash.thumbnailPath
85 this.views = hash.views
86 this.likes = hash.likes
87 this.dislikes = hash.dislikes
90 this.by = Video.createByString(hash.author, hash.podHost)
93 isRemovableBy (user) {
94 return user && this.isLocal === true && (this.author === user.username || user.isAdmin() === true)
97 isBlackistableBy (user) {
98 return user && user.isAdmin() === true && this.isLocal === false
101 isUpdatableBy (user) {
102 return user && this.isLocal === true && user.username === this.author
105 isVideoNSFWForUser (user: User) {
106 // If the video is NSFW and the user is not logged in, or the user does not want to display NSFW videos...
107 return (this.nsfw && (!user || user.displayNSFW === false))
110 patch (values: Object) {
111 Object.keys(values).forEach((key) => {
112 this[key] = values[key]
119 createdAt: this.createdAt,
120 category: this.category,
121 licence: this.licence,
122 language: this.language,
123 description: this.description,
124 duration: this.duration,
126 isLocal: this.isLocal,
127 magnetUri: this.magnetUri,
129 podHost: this.podHost,
131 thumbnailPath: this.thumbnailPath,
134 dislikes: this.dislikes,