]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/shared/shared-video-playlist/video-playlist.model.ts
Bumped to version v5.2.1
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-video-playlist / video-playlist.model.ts
1 import { getAbsoluteAPIUrl, getAbsoluteEmbedUrl } from '@app/helpers'
2 import { Actor } from '@app/shared/shared-main'
3 import { buildPlaylistWatchPath } from '@shared/core-utils'
4 import { peertubeTranslate } from '@shared/core-utils/i18n'
5 import {
6 AccountSummary,
7 VideoChannelSummary,
8 VideoConstant,
9 VideoPlaylist as ServerVideoPlaylist,
10 VideoPlaylistPrivacy,
11 VideoPlaylistType
12 } from '@shared/models'
13
14 export class VideoPlaylist implements ServerVideoPlaylist {
15 id: number
16 uuid: string
17 shortUUID: string
18
19 isLocal: boolean
20
21 url: string
22
23 displayName: string
24 description: string
25 privacy: VideoConstant<VideoPlaylistPrivacy>
26
27 videosLength: number
28
29 type: VideoConstant<VideoPlaylistType>
30
31 createdAt: Date | string
32 updatedAt: Date | string
33
34 ownerAccount: AccountSummary
35 videoChannel?: VideoChannelSummary
36
37 thumbnailPath: string
38 thumbnailUrl: string
39
40 embedPath: string
41 embedUrl: string
42
43 ownerBy: string
44
45 videoChannelBy?: string
46
47 static buildWatchUrl (playlist: Pick<VideoPlaylist, 'uuid' | 'shortUUID'>) {
48 return buildPlaylistWatchPath({ shortUUID: playlist.shortUUID || playlist.uuid })
49 }
50
51 constructor (hash: ServerVideoPlaylist, translations: { [ id: string ]: string }) {
52 const absoluteAPIUrl = getAbsoluteAPIUrl()
53
54 this.id = hash.id
55 this.uuid = hash.uuid
56 this.shortUUID = hash.shortUUID
57
58 this.url = hash.url
59 this.isLocal = hash.isLocal
60
61 this.displayName = hash.displayName
62
63 this.description = hash.description
64 this.privacy = hash.privacy
65
66 this.thumbnailPath = hash.thumbnailPath
67
68 this.thumbnailUrl = this.thumbnailPath
69 ? hash.thumbnailUrl || (absoluteAPIUrl + hash.thumbnailPath)
70 : absoluteAPIUrl + '/client/assets/images/default-playlist.jpg'
71
72 this.embedPath = hash.embedPath
73 this.embedUrl = hash.embedUrl || (getAbsoluteEmbedUrl() + hash.embedPath)
74
75 this.videosLength = hash.videosLength
76
77 this.type = hash.type
78
79 this.createdAt = new Date(hash.createdAt)
80 this.updatedAt = new Date(hash.updatedAt)
81
82 this.ownerAccount = hash.ownerAccount
83 this.ownerBy = Actor.CREATE_BY_STRING(hash.ownerAccount.name, hash.ownerAccount.host)
84
85 if (hash.videoChannel) {
86 this.videoChannel = hash.videoChannel
87 this.videoChannelBy = Actor.CREATE_BY_STRING(hash.videoChannel.name, hash.videoChannel.host)
88 }
89
90 this.privacy.label = peertubeTranslate(this.privacy.label, translations)
91
92 if (this.type.id === VideoPlaylistType.WATCH_LATER) {
93 this.displayName = peertubeTranslate(this.displayName, translations)
94 }
95 }
96 }