]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/shared/shared-video-playlist/video-playlist.model.ts
Reorganize client shared modules
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-video-playlist / video-playlist.model.ts
1 import { getAbsoluteAPIUrl } from '@app/helpers'
2 import { Actor } from '@app/shared/shared-main'
3 import {
4 AccountSummary,
5 peertubeTranslate,
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 ownerBy: string
37 ownerAvatarUrl: string
38
39 videoChannelBy?: string
40 videoChannelAvatarUrl?: string
41
42 private thumbnailVersion: number
43 private originThumbnailUrl: string
44
45 constructor (hash: ServerVideoPlaylist, translations: {}) {
46 const absoluteAPIUrl = getAbsoluteAPIUrl()
47
48 this.id = hash.id
49 this.uuid = hash.uuid
50 this.isLocal = hash.isLocal
51
52 this.displayName = hash.displayName
53
54 this.description = hash.description
55 this.privacy = hash.privacy
56
57 this.thumbnailPath = hash.thumbnailPath
58
59 if (this.thumbnailPath) {
60 this.thumbnailUrl = absoluteAPIUrl + hash.thumbnailPath
61 this.originThumbnailUrl = this.thumbnailUrl
62 } else {
63 this.thumbnailUrl = window.location.origin + '/client/assets/images/default-playlist.jpg'
64 }
65
66 this.videosLength = hash.videosLength
67
68 this.type = hash.type
69
70 this.createdAt = new Date(hash.createdAt)
71 this.updatedAt = new Date(hash.updatedAt)
72
73 this.ownerAccount = hash.ownerAccount
74 this.ownerBy = Actor.CREATE_BY_STRING(hash.ownerAccount.name, hash.ownerAccount.host)
75 this.ownerAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.ownerAccount)
76
77 if (hash.videoChannel) {
78 this.videoChannel = hash.videoChannel
79 this.videoChannelBy = Actor.CREATE_BY_STRING(hash.videoChannel.name, hash.videoChannel.host)
80 this.videoChannelAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.videoChannel)
81 }
82
83 this.privacy.label = peertubeTranslate(this.privacy.label, translations)
84
85 if (this.type.id === VideoPlaylistType.WATCH_LATER) {
86 this.displayName = peertubeTranslate(this.displayName, translations)
87 }
88 }
89
90 refreshThumbnail () {
91 if (!this.originThumbnailUrl) return
92
93 if (!this.thumbnailVersion) this.thumbnailVersion = 0
94 this.thumbnailVersion++
95
96 this.thumbnailUrl = this.originThumbnailUrl + '?v' + this.thumbnailVersion
97 }
98 }