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