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