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