2017-12-01 18:56:26 +01:00
|
|
|
import { User } from '../'
|
2018-06-12 20:04:58 +02:00
|
|
|
import { Video as VideoServerModel, VideoPrivacy, VideoState } from '../../../../../shared'
|
2018-03-12 11:06:15 +01:00
|
|
|
import { Avatar } from '../../../../../shared/models/avatars/avatar.model'
|
2018-07-12 19:02:00 +02:00
|
|
|
import { VideoConstant } from '../../../../../shared/models/videos/video-constant.model'
|
2017-12-29 19:10:13 +01:00
|
|
|
import { getAbsoluteAPIUrl } from '../misc/utils'
|
2018-08-16 10:48:35 +02:00
|
|
|
import { peertubeTranslate, ServerConfig } from '../../../../../shared/models'
|
2018-04-25 15:43:19 +02:00
|
|
|
import { Actor } from '@app/shared/actor/actor.model'
|
2018-06-15 16:52:15 +02:00
|
|
|
import { VideoScheduleUpdate } from '../../../../../shared/models/videos/video-schedule-update.model'
|
2017-04-04 21:37:03 +02:00
|
|
|
|
2017-06-11 11:02:35 +02:00
|
|
|
export class Video implements VideoServerModel {
|
2017-06-16 14:32:15 +02:00
|
|
|
by: string
|
2018-04-25 15:43:19 +02:00
|
|
|
accountAvatarUrl: string
|
2018-06-29 14:34:04 +02:00
|
|
|
videoChannelAvatarUrl: string
|
2017-06-16 14:32:15 +02:00
|
|
|
createdAt: Date
|
2017-09-12 12:53:55 +02:00
|
|
|
updatedAt: Date
|
2018-03-28 23:38:52 +02:00
|
|
|
publishedAt: Date
|
2018-03-19 11:04:40 +01:00
|
|
|
category: VideoConstant<number>
|
|
|
|
licence: VideoConstant<number>
|
2018-04-23 14:39:52 +02:00
|
|
|
language: VideoConstant<string>
|
2018-04-19 14:52:10 +02:00
|
|
|
privacy: VideoConstant<VideoPrivacy>
|
2017-06-16 14:32:15 +02:00
|
|
|
description: string
|
|
|
|
duration: number
|
|
|
|
durationLabel: string
|
2017-07-11 16:01:56 +02:00
|
|
|
id: number
|
|
|
|
uuid: string
|
2017-06-16 14:32:15 +02:00
|
|
|
isLocal: boolean
|
|
|
|
name: string
|
2017-11-15 11:00:25 +01:00
|
|
|
serverHost: string
|
2017-06-16 14:32:15 +02:00
|
|
|
thumbnailPath: string
|
|
|
|
thumbnailUrl: string
|
2017-07-12 12:16:13 +02:00
|
|
|
previewPath: string
|
|
|
|
previewUrl: string
|
2017-10-16 10:05:49 +02:00
|
|
|
embedPath: string
|
|
|
|
embedUrl: string
|
2017-06-16 14:32:15 +02:00
|
|
|
views: number
|
|
|
|
likes: number
|
|
|
|
dislikes: number
|
|
|
|
nsfw: boolean
|
2018-03-12 11:06:15 +01:00
|
|
|
|
2018-06-12 20:04:58 +02:00
|
|
|
waitTranscoding?: boolean
|
|
|
|
state?: VideoConstant<VideoState>
|
2018-06-15 16:52:15 +02:00
|
|
|
scheduledUpdate?: VideoScheduleUpdate
|
2018-08-14 09:08:47 +02:00
|
|
|
blacklisted?: boolean
|
|
|
|
blacklistedReason?: string
|
2018-06-12 20:04:58 +02:00
|
|
|
|
2018-03-12 11:06:15 +01:00
|
|
|
account: {
|
2018-04-25 14:32:19 +02:00
|
|
|
id: number
|
|
|
|
uuid: string
|
2018-03-12 11:06:15 +01:00
|
|
|
name: string
|
|
|
|
displayName: string
|
|
|
|
url: string
|
2018-05-11 15:10:13 +02:00
|
|
|
host: string
|
|
|
|
avatar: Avatar
|
|
|
|
}
|
|
|
|
|
|
|
|
channel: {
|
|
|
|
id: number
|
|
|
|
uuid: string
|
|
|
|
name: string
|
|
|
|
displayName: string
|
|
|
|
url: string
|
2018-03-12 11:06:15 +01:00
|
|
|
host: string
|
|
|
|
avatar: Avatar
|
|
|
|
}
|
2016-05-23 12:15:03 +02:00
|
|
|
|
2018-08-14 09:08:47 +02:00
|
|
|
static buildClientUrl (videoUUID: string) {
|
|
|
|
return '/videos/watch/' + videoUUID
|
|
|
|
}
|
|
|
|
|
2017-06-16 14:32:15 +02:00
|
|
|
private static createDurationString (duration: number) {
|
2018-03-19 10:32:12 +01:00
|
|
|
const hours = Math.floor(duration / 3600)
|
2018-06-12 20:04:58 +02:00
|
|
|
const minutes = Math.floor((duration % 3600) / 60)
|
2017-06-16 14:32:15 +02:00
|
|
|
const seconds = duration % 60
|
2018-03-19 10:32:12 +01:00
|
|
|
|
2017-06-16 14:32:15 +02:00
|
|
|
const minutesPadding = minutes >= 10 ? '' : '0'
|
|
|
|
const secondsPadding = seconds >= 10 ? '' : '0'
|
2018-03-19 10:32:12 +01:00
|
|
|
const displayedHours = hours > 0 ? hours.toString() + ':' : ''
|
2016-05-27 17:49:18 +02:00
|
|
|
|
2018-06-12 20:04:58 +02:00
|
|
|
return displayedHours + minutesPadding + minutes.toString() + ':' + secondsPadding + seconds.toString()
|
2016-05-27 17:49:18 +02:00
|
|
|
}
|
|
|
|
|
2018-06-06 16:46:42 +02:00
|
|
|
constructor (hash: VideoServerModel, translations = {}) {
|
2017-12-29 19:10:13 +01:00
|
|
|
const absoluteAPIUrl = getAbsoluteAPIUrl()
|
2017-10-17 16:22:14 +02:00
|
|
|
|
2017-09-14 11:57:49 +02:00
|
|
|
this.createdAt = new Date(hash.createdAt.toString())
|
2018-03-28 23:38:52 +02:00
|
|
|
this.publishedAt = new Date(hash.publishedAt.toString())
|
2017-06-16 14:32:15 +02:00
|
|
|
this.category = hash.category
|
|
|
|
this.licence = hash.licence
|
|
|
|
this.language = hash.language
|
2018-04-19 14:52:10 +02:00
|
|
|
this.privacy = hash.privacy
|
2018-06-12 20:04:58 +02:00
|
|
|
this.waitTranscoding = hash.waitTranscoding
|
|
|
|
this.state = hash.state
|
2017-06-16 14:32:15 +02:00
|
|
|
this.description = hash.description
|
|
|
|
this.duration = hash.duration
|
|
|
|
this.durationLabel = Video.createDurationString(hash.duration)
|
|
|
|
this.id = hash.id
|
2017-07-11 16:01:56 +02:00
|
|
|
this.uuid = hash.uuid
|
2017-06-16 14:32:15 +02:00
|
|
|
this.isLocal = hash.isLocal
|
|
|
|
this.name = hash.name
|
|
|
|
this.thumbnailPath = hash.thumbnailPath
|
2017-10-17 16:22:14 +02:00
|
|
|
this.thumbnailUrl = absoluteAPIUrl + hash.thumbnailPath
|
2017-07-12 12:16:13 +02:00
|
|
|
this.previewPath = hash.previewPath
|
2017-10-17 16:22:14 +02:00
|
|
|
this.previewUrl = absoluteAPIUrl + hash.previewPath
|
2017-10-16 10:05:49 +02:00
|
|
|
this.embedPath = hash.embedPath
|
2017-10-17 16:22:14 +02:00
|
|
|
this.embedUrl = absoluteAPIUrl + hash.embedPath
|
2017-06-16 14:32:15 +02:00
|
|
|
this.views = hash.views
|
|
|
|
this.likes = hash.likes
|
|
|
|
this.dislikes = hash.dislikes
|
|
|
|
this.nsfw = hash.nsfw
|
2018-03-12 11:06:15 +01:00
|
|
|
this.account = hash.account
|
2018-06-29 14:34:04 +02:00
|
|
|
this.channel = hash.channel
|
2016-05-27 17:49:18 +02:00
|
|
|
|
2018-04-25 15:43:19 +02:00
|
|
|
this.by = Actor.CREATE_BY_STRING(hash.account.name, hash.account.host)
|
|
|
|
this.accountAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.account)
|
2018-06-29 14:34:04 +02:00
|
|
|
this.videoChannelAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.channel)
|
2018-06-06 16:46:42 +02:00
|
|
|
|
|
|
|
this.category.label = peertubeTranslate(this.category.label, translations)
|
|
|
|
this.licence.label = peertubeTranslate(this.licence.label, translations)
|
|
|
|
this.language.label = peertubeTranslate(this.language.label, translations)
|
|
|
|
this.privacy.label = peertubeTranslate(this.privacy.label, translations)
|
2018-06-12 20:04:58 +02:00
|
|
|
|
2018-06-15 16:52:15 +02:00
|
|
|
this.scheduledUpdate = hash.scheduledUpdate
|
2018-06-12 20:04:58 +02:00
|
|
|
if (this.state) this.state.label = peertubeTranslate(this.state.label, translations)
|
2018-08-14 09:08:47 +02:00
|
|
|
|
|
|
|
this.blacklisted = hash.blacklisted
|
|
|
|
this.blacklistedReason = hash.blacklistedReason
|
2016-05-21 18:03:34 +02:00
|
|
|
}
|
|
|
|
|
2018-04-19 11:01:34 +02:00
|
|
|
isVideoNSFWForUser (user: User, serverConfig: ServerConfig) {
|
|
|
|
// Video is not NSFW, skip
|
|
|
|
if (this.nsfw === false) return false
|
|
|
|
|
|
|
|
// Return user setting if logged in
|
|
|
|
if (user) return user.nsfwPolicy !== 'display'
|
|
|
|
|
|
|
|
// Return default instance config
|
|
|
|
return serverConfig.instance.defaultNSFWPolicy !== 'display'
|
2017-04-04 21:37:03 +02:00
|
|
|
}
|
2016-05-21 18:03:34 +02:00
|
|
|
}
|