]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/shared-main/video/video.model.ts
Use HTML config when possible
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-main / video / video.model.ts
CommitLineData
3a0fb65c 1import { AuthUser } from '@app/core'
67ed6552 2import { User } from '@app/core/users/user.model'
72493e44 3import { durationToString, getAbsoluteAPIUrl, getAbsoluteEmbedUrl } from '@app/helpers'
69524f6e 4import { Actor } from '@app/shared/shared-main/account/actor.model'
bd45d503 5import { peertubeTranslate } from '@shared/core-utils/i18n'
67ed6552 6import {
f4796856 7 ActorImage,
2989628b 8 HTMLServerConfig,
67ed6552
C
9 UserRight,
10 Video as VideoServerModel,
11 VideoConstant,
12 VideoPrivacy,
13 VideoScheduleUpdate,
14 VideoState
15} from '@shared/models'
92fb909c 16
69f616ab 17export class Video implements VideoServerModel {
22a16e36
C
18 byVideoChannel: string
19 byAccount: string
20
df98563e 21 createdAt: Date
6d33593a 22 updatedAt: Date
2922e048 23 publishedAt: Date
c8034165 24 originallyPublishedAt: Date | string
09700934
C
25 category: VideoConstant<number>
26 licence: VideoConstant<number>
9d3ef9fe 27 language: VideoConstant<string>
2243730c 28 privacy: VideoConstant<VideoPrivacy>
df98563e
C
29 description: string
30 duration: number
31 durationLabel: string
0a6658fd
C
32 id: number
33 uuid: string
df98563e 34 isLocal: boolean
df98563e 35 name: string
60862425 36 serverHost: string
df98563e
C
37 thumbnailPath: string
38 thumbnailUrl: string
5fb2e288 39
c6c0fa6c
C
40 isLive: boolean
41
43f61d26
C
42 previewPath: string
43 previewUrl: string
5fb2e288 44
d8755eed
C
45 embedPath: string
46 embedUrl: string
5fb2e288
C
47
48 url?: string
49
df98563e
C
50 views: number
51 likes: number
52 dislikes: number
53 nsfw: boolean
b64c950a 54
c910f667
C
55 originInstanceUrl: string
56 originInstanceHost: string
57
2186386c
C
58 waitTranscoding?: boolean
59 state?: VideoConstant<VideoState>
bbe0f064 60 scheduledUpdate?: VideoScheduleUpdate
191764f3 61 blacklisted?: boolean
5baee5fc 62 blockedReason?: string
2186386c 63
b64c950a 64 account: {
03e12d7c 65 id: number
b64c950a
C
66 name: string
67 displayName: string
68 url: string
0f320037 69 host: string
f4796856 70 avatar?: ActorImage
0f320037
C
71 }
72
73 channel: {
74 id: number
0f320037
C
75 name: string
76 displayName: string
77 url: string
b64c950a 78 host: string
f4796856 79 avatar?: ActorImage
b64c950a 80 }
aff038cd 81
6e46de09
C
82 userHistory?: {
83 currentTime: number
84 }
85
7294aab0
C
86 pluginData?: any
87
191764f3 88 static buildClientUrl (videoUUID: string) {
a1eda903 89 return '/w/' + videoUUID
191764f3
C
90 }
91
7ce44a74 92 constructor (hash: VideoServerModel, translations = {}) {
c5911fd3 93 const absoluteAPIUrl = getAbsoluteAPIUrl()
c6e0bfbf 94
d592e0a9 95 this.createdAt = new Date(hash.createdAt.toString())
2922e048 96 this.publishedAt = new Date(hash.publishedAt.toString())
df98563e 97 this.category = hash.category
df98563e 98 this.licence = hash.licence
df98563e 99 this.language = hash.language
2243730c 100 this.privacy = hash.privacy
2186386c
C
101 this.waitTranscoding = hash.waitTranscoding
102 this.state = hash.state
df98563e 103 this.description = hash.description
c910f667 104
c6c0fa6c
C
105 this.isLive = hash.isLive
106
df98563e 107 this.duration = hash.duration
11b8762f 108 this.durationLabel = durationToString(hash.duration)
c910f667 109
df98563e 110 this.id = hash.id
0a6658fd 111 this.uuid = hash.uuid
c910f667 112
df98563e 113 this.isLocal = hash.isLocal
df98563e 114 this.name = hash.name
c910f667 115
df98563e 116 this.thumbnailPath = hash.thumbnailPath
c6c0fa6c
C
117 this.thumbnailUrl = this.thumbnailPath
118 ? hash.thumbnailUrl || (absoluteAPIUrl + hash.thumbnailPath)
119 : null
c910f667 120
43f61d26 121 this.previewPath = hash.previewPath
c6c0fa6c
C
122 this.previewUrl = this.previewPath
123 ? hash.previewUrl || (absoluteAPIUrl + hash.previewPath)
124 : null
c910f667 125
d8755eed 126 this.embedPath = hash.embedPath
72493e44 127 this.embedUrl = hash.embedUrl || (getAbsoluteEmbedUrl() + hash.embedPath)
5fb2e288
C
128
129 this.url = hash.url
c910f667 130
df98563e
C
131 this.views = hash.views
132 this.likes = hash.likes
133 this.dislikes = hash.dislikes
c910f667 134
df98563e 135 this.nsfw = hash.nsfw
c910f667 136
b64c950a 137 this.account = hash.account
52d9f792 138 this.channel = hash.channel
4fd8aa32 139
22a16e36
C
140 this.byAccount = Actor.CREATE_BY_STRING(hash.account.name, hash.account.host)
141 this.byVideoChannel = Actor.CREATE_BY_STRING(hash.channel.name, hash.channel.host)
7ce44a74
C
142
143 this.category.label = peertubeTranslate(this.category.label, translations)
144 this.licence.label = peertubeTranslate(this.licence.label, translations)
145 this.language.label = peertubeTranslate(this.language.label, translations)
146 this.privacy.label = peertubeTranslate(this.privacy.label, translations)
2186386c 147
bbe0f064 148 this.scheduledUpdate = hash.scheduledUpdate
830b4faf
C
149 this.originallyPublishedAt = hash.originallyPublishedAt ? new Date(hash.originallyPublishedAt.toString()) : null
150
2186386c 151 if (this.state) this.state.label = peertubeTranslate(this.state.label, translations)
191764f3
C
152
153 this.blacklisted = hash.blacklisted
5baee5fc 154 this.blockedReason = hash.blacklistedReason
6e46de09
C
155
156 this.userHistory = hash.userHistory
c910f667
C
157
158 this.originInstanceHost = this.account.host
159 this.originInstanceUrl = 'https://' + this.originInstanceHost
7294aab0
C
160
161 this.pluginData = hash.pluginData
501bc6c2
C
162 }
163
2989628b 164 isVideoNSFWForUser (user: User, serverConfig: HTMLServerConfig) {
0883b324
C
165 // Video is not NSFW, skip
166 if (this.nsfw === false) return false
167
168 // Return user setting if logged in
169 if (user) return user.nsfwPolicy !== 'display'
170
171 // Return default instance config
172 return serverConfig.instance.defaultNSFWPolicy !== 'display'
92fb909c 173 }
3a0fb65c
C
174
175 isRemovableBy (user: AuthUser) {
176 return user && this.isLocal === true && (this.account.name === user.username || user.hasRight(UserRight.REMOVE_ANY_VIDEO))
177 }
178
5baee5fc 179 isBlockableBy (user: AuthUser) {
3487330d 180 return this.blacklisted !== true && user && user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) === true
3a0fb65c
C
181 }
182
5baee5fc 183 isUnblockableBy (user: AuthUser) {
3487330d 184 return this.blacklisted === true && user && user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) === true
3a0fb65c
C
185 }
186
187 isUpdatableBy (user: AuthUser) {
188 return user && this.isLocal === true && (this.account.name === user.username || user.hasRight(UserRight.UPDATE_ANY_VIDEO))
189 }
b764380a 190
f8c00564
C
191 isLiveInfoAvailableBy (user: AuthUser) {
192 return this.isLive &&
193 user && this.isLocal === true && (this.account.name === user.username || user.hasRight(UserRight.GET_ANY_LIVE))
194 }
195
b764380a
C
196 canBeDuplicatedBy (user: AuthUser) {
197 return user && this.isLocal === false && user.hasRight(UserRight.MANAGE_VIDEOS_REDUNDANCIES)
198 }
4ec25ae8
C
199
200 getExactNumberOfViews () {
201 if (this.views < 1000) return ''
202
203 if (this.isLive) {
204 return $localize`${this.views} viewers`
205 }
206
207 return $localize`${this.views} views`
208 }
501bc6c2 209}