1 import { Video as VideoServerModel } from '../../../../../shared'
2 import { User } from '../../shared'
4 export class Video implements VideoServerModel {
33 private static createByString (author: string, podHost: string) {
34 return author + '@' + podHost
37 private static createDurationString (duration: number) {
38 const minutes = Math.floor(duration / 60)
39 const seconds = duration % 60
40 const minutesPadding = minutes >= 10 ? '' : '0'
41 const secondsPadding = seconds >= 10 ? '' : '0'
43 return minutesPadding + minutes.toString() + ':' + secondsPadding + seconds.toString()
49 categoryLabel: string,
64 thumbnailPath: string,
71 this.author = hash.author
72 this.createdAt = new Date(hash.createdAt)
73 this.categoryLabel = hash.categoryLabel
74 this.category = hash.category
75 this.licenceLabel = hash.licenceLabel
76 this.licence = hash.licence
77 this.languageLabel = hash.languageLabel
78 this.language = hash.language
79 this.description = hash.description
80 this.duration = hash.duration
81 this.durationLabel = Video.createDurationString(hash.duration)
84 this.isLocal = hash.isLocal
85 this.magnetUri = hash.magnetUri
87 this.podHost = hash.podHost
89 this.thumbnailPath = hash.thumbnailPath
90 this.thumbnailUrl = API_URL + hash.thumbnailPath
91 this.previewPath = hash.previewPath
92 this.previewUrl = API_URL + hash.previewPath
93 this.views = hash.views
94 this.likes = hash.likes
95 this.dislikes = hash.dislikes
98 this.by = Video.createByString(hash.author, hash.podHost)
101 isRemovableBy (user) {
102 return user && this.isLocal === true && (this.author === user.username || user.isAdmin() === true)
105 isBlackistableBy (user) {
106 return user && user.isAdmin() === true && this.isLocal === false
109 isUpdatableBy (user) {
110 return user && this.isLocal === true && user.username === this.author
113 isVideoNSFWForUser (user: User) {
114 // If the video is NSFW and the user is not logged in, or the user does not want to display NSFW videos...
115 return (this.nsfw && (!user || user.displayNSFW === false))
118 patch (values: Object) {
119 Object.keys(values).forEach((key) => {
120 this[key] = values[key]
127 createdAt: this.createdAt,
128 category: this.category,
129 licence: this.licence,
130 language: this.language,
131 description: this.description,
132 duration: this.duration,
134 isLocal: this.isLocal,
135 magnetUri: this.magnetUri,
137 podHost: this.podHost,
139 thumbnailPath: this.thumbnailPath,
142 dislikes: this.dislikes,