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