1 import { Account } from '@app/shared/account/account.model'
2 import { User } from '../'
3 import { Video as VideoServerModel } from '../../../../../shared'
4 import { Avatar } from '../../../../../shared/models/avatars/avatar.model'
5 import { VideoConstant } from '../../../../../shared/models/videos/video.model'
6 import { getAbsoluteAPIUrl } from '../misc/utils'
7 import { ServerConfig } from '../../../../../shared/models'
9 export class Video implements VideoServerModel {
14 category: VideoConstant<number>
15 licence: VideoConstant<number>
16 language: VideoConstant<number>
44 private static createDurationString (duration: number) {
45 const hours = Math.floor(duration / 3600)
46 const minutes = Math.floor(duration % 3600 / 60)
47 const seconds = duration % 60
49 const minutesPadding = minutes >= 10 ? '' : '0'
50 const secondsPadding = seconds >= 10 ? '' : '0'
51 const displayedHours = hours > 0 ? hours.toString() + ':' : ''
53 return displayedHours + minutesPadding +
54 minutes.toString() + ':' + secondsPadding + seconds.toString()
57 constructor (hash: VideoServerModel) {
58 const absoluteAPIUrl = getAbsoluteAPIUrl()
60 this.createdAt = new Date(hash.createdAt.toString())
61 this.publishedAt = new Date(hash.publishedAt.toString())
62 this.category = hash.category
63 this.licence = hash.licence
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.thumbnailPath = hash.thumbnailPath
73 this.thumbnailUrl = absoluteAPIUrl + hash.thumbnailPath
74 this.previewPath = hash.previewPath
75 this.previewUrl = absoluteAPIUrl + hash.previewPath
76 this.embedPath = hash.embedPath
77 this.embedUrl = absoluteAPIUrl + hash.embedPath
78 this.views = hash.views
79 this.likes = hash.likes
80 this.dislikes = hash.dislikes
82 this.account = hash.account
84 this.by = Account.CREATE_BY_STRING(hash.account.name, hash.account.host)
87 isVideoNSFWForUser (user: User, serverConfig: ServerConfig) {
88 // Video is not NSFW, skip
89 if (this.nsfw === false) return false
91 // Return user setting if logged in
92 if (user) return user.nsfwPolicy !== 'display'
94 // Return default instance config
95 return serverConfig.instance.defaultNSFWPolicy !== 'display'