]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/video/video.model.ts
Add blacklist reason field
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / video / video.model.ts
CommitLineData
202f6b6c 1import { User } from '../'
2186386c 2import { Video as VideoServerModel, VideoPrivacy, VideoState } from '../../../../../shared'
b64c950a 3import { Avatar } from '../../../../../shared/models/avatars/avatar.model'
40e87e9e 4import { VideoConstant } from '../../../../../shared/models/videos/video-constant.model'
c5911fd3 5import { getAbsoluteAPIUrl } from '../misc/utils'
0883b324 6import { ServerConfig } from '../../../../../shared/models'
d3e91a5f 7import { Actor } from '@app/shared/actor/actor.model'
7ce44a74 8import { peertubeTranslate } from '@app/shared/i18n/i18n-utils'
bbe0f064 9import { VideoScheduleUpdate } from '../../../../../shared/models/videos/video-schedule-update.model'
92fb909c 10
69f616ab 11export class Video implements VideoServerModel {
df98563e 12 by: string
d3e91a5f 13 accountAvatarUrl: string
52d9f792 14 videoChannelAvatarUrl: string
df98563e 15 createdAt: Date
6d33593a 16 updatedAt: Date
2922e048 17 publishedAt: Date
09700934
C
18 category: VideoConstant<number>
19 licence: VideoConstant<number>
9d3ef9fe 20 language: VideoConstant<string>
2243730c 21 privacy: VideoConstant<VideoPrivacy>
df98563e
C
22 description: string
23 duration: number
24 durationLabel: string
0a6658fd
C
25 id: number
26 uuid: string
df98563e 27 isLocal: boolean
df98563e 28 name: string
60862425 29 serverHost: string
df98563e
C
30 thumbnailPath: string
31 thumbnailUrl: string
43f61d26
C
32 previewPath: string
33 previewUrl: string
d8755eed
C
34 embedPath: string
35 embedUrl: string
df98563e
C
36 views: number
37 likes: number
38 dislikes: number
39 nsfw: boolean
b64c950a 40
2186386c
C
41 waitTranscoding?: boolean
42 state?: VideoConstant<VideoState>
bbe0f064 43 scheduledUpdate?: VideoScheduleUpdate
2186386c 44
b64c950a 45 account: {
03e12d7c
C
46 id: number
47 uuid: string
b64c950a
C
48 name: string
49 displayName: string
50 url: string
0f320037
C
51 host: string
52 avatar: Avatar
53 }
54
55 channel: {
56 id: number
57 uuid: string
58 name: string
59 displayName: string
60 url: string
b64c950a
C
61 host: string
62 avatar: Avatar
63 }
aff038cd 64
df98563e 65 private static createDurationString (duration: number) {
f6aec1b0 66 const hours = Math.floor(duration / 3600)
2186386c 67 const minutes = Math.floor((duration % 3600) / 60)
df98563e 68 const seconds = duration % 60
f6aec1b0 69
df98563e
C
70 const minutesPadding = minutes >= 10 ? '' : '0'
71 const secondsPadding = seconds >= 10 ? '' : '0'
f6aec1b0 72 const displayedHours = hours > 0 ? hours.toString() + ':' : ''
4fd8aa32 73
2186386c 74 return displayedHours + minutesPadding + minutes.toString() + ':' + secondsPadding + seconds.toString()
4fd8aa32
C
75 }
76
7ce44a74 77 constructor (hash: VideoServerModel, translations = {}) {
c5911fd3 78 const absoluteAPIUrl = getAbsoluteAPIUrl()
c6e0bfbf 79
d592e0a9 80 this.createdAt = new Date(hash.createdAt.toString())
2922e048 81 this.publishedAt = new Date(hash.publishedAt.toString())
df98563e 82 this.category = hash.category
df98563e 83 this.licence = hash.licence
df98563e 84 this.language = hash.language
2243730c 85 this.privacy = hash.privacy
2186386c
C
86 this.waitTranscoding = hash.waitTranscoding
87 this.state = hash.state
df98563e
C
88 this.description = hash.description
89 this.duration = hash.duration
90 this.durationLabel = Video.createDurationString(hash.duration)
91 this.id = hash.id
0a6658fd 92 this.uuid = hash.uuid
df98563e 93 this.isLocal = hash.isLocal
df98563e 94 this.name = hash.name
df98563e 95 this.thumbnailPath = hash.thumbnailPath
c6e0bfbf 96 this.thumbnailUrl = absoluteAPIUrl + hash.thumbnailPath
43f61d26 97 this.previewPath = hash.previewPath
c6e0bfbf 98 this.previewUrl = absoluteAPIUrl + hash.previewPath
d8755eed 99 this.embedPath = hash.embedPath
c6e0bfbf 100 this.embedUrl = absoluteAPIUrl + hash.embedPath
df98563e
C
101 this.views = hash.views
102 this.likes = hash.likes
103 this.dislikes = hash.dislikes
104 this.nsfw = hash.nsfw
b64c950a 105 this.account = hash.account
52d9f792 106 this.channel = hash.channel
4fd8aa32 107
d3e91a5f
C
108 this.by = Actor.CREATE_BY_STRING(hash.account.name, hash.account.host)
109 this.accountAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.account)
52d9f792 110 this.videoChannelAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.channel)
7ce44a74
C
111
112 this.category.label = peertubeTranslate(this.category.label, translations)
113 this.licence.label = peertubeTranslate(this.licence.label, translations)
114 this.language.label = peertubeTranslate(this.language.label, translations)
115 this.privacy.label = peertubeTranslate(this.privacy.label, translations)
2186386c 116
bbe0f064 117 this.scheduledUpdate = hash.scheduledUpdate
2186386c 118 if (this.state) this.state.label = peertubeTranslate(this.state.label, translations)
501bc6c2
C
119 }
120
0883b324
C
121 isVideoNSFWForUser (user: User, serverConfig: ServerConfig) {
122 // Video is not NSFW, skip
123 if (this.nsfw === false) return false
124
125 // Return user setting if logged in
126 if (user) return user.nsfwPolicy !== 'display'
127
128 // Return default instance config
129 return serverConfig.instance.defaultNSFWPolicy !== 'display'
92fb909c 130 }
501bc6c2 131}