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