1 import { User } from '../'
2 import { Video as VideoServerModel, VideoPrivacy } from '../../../../../shared'
3 import { Avatar } from '../../../../../shared/models/avatars/avatar.model'
4 import { VideoConstant } from '../../../../../shared/models/videos/video.model'
5 import { getAbsoluteAPIUrl } from '../misc/utils'
6 import { ServerConfig } from '../../../../../shared/models'
7 import { Actor } from '@app/shared/actor/actor.model'
9 export class Video implements VideoServerModel {
11 accountAvatarUrl: string
15 category: VideoConstant<number>
16 licence: VideoConstant<number>
17 language: VideoConstant<string>
18 privacy: VideoConstant<VideoPrivacy>
58 private static createDurationString (duration: number) {
59 const hours = Math.floor(duration / 3600)
60 const minutes = Math.floor(duration % 3600 / 60)
61 const seconds = duration % 60
63 const minutesPadding = minutes >= 10 ? '' : '0'
64 const secondsPadding = seconds >= 10 ? '' : '0'
65 const displayedHours = hours > 0 ? hours.toString() + ':' : ''
67 return displayedHours + minutesPadding +
68 minutes.toString() + ':' + secondsPadding + seconds.toString()
71 constructor (hash: VideoServerModel) {
72 const absoluteAPIUrl = getAbsoluteAPIUrl()
74 this.createdAt = new Date(hash.createdAt.toString())
75 this.publishedAt = new Date(hash.publishedAt.toString())
76 this.category = hash.category
77 this.licence = hash.licence
78 this.language = hash.language
79 this.privacy = hash.privacy
80 this.description = hash.description
81 this.duration = hash.duration
82 this.durationLabel = Video.createDurationString(hash.duration)
85 this.isLocal = hash.isLocal
87 this.thumbnailPath = hash.thumbnailPath
88 this.thumbnailUrl = absoluteAPIUrl + hash.thumbnailPath
89 this.previewPath = hash.previewPath
90 this.previewUrl = absoluteAPIUrl + hash.previewPath
91 this.embedPath = hash.embedPath
92 this.embedUrl = absoluteAPIUrl + hash.embedPath
93 this.views = hash.views
94 this.likes = hash.likes
95 this.dislikes = hash.dislikes
97 this.account = hash.account
99 this.by = Actor.CREATE_BY_STRING(hash.account.name, hash.account.host)
100 this.accountAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.account)
103 isVideoNSFWForUser (user: User, serverConfig: ServerConfig) {
104 // Video is not NSFW, skip
105 if (this.nsfw === false) return false
107 // Return user setting if logged in
108 if (user) return user.nsfwPolicy !== 'display'
110 // Return default instance config
111 return serverConfig.instance.defaultNSFWPolicy !== 'display'