]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/shared-video-playlist/video-playlist.model.ts
Add new default different avatar for channel and account
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-video-playlist / video-playlist.model.ts
CommitLineData
951b582f 1import { getAbsoluteAPIUrl, getAbsoluteEmbedUrl } from '@app/helpers'
c418d483 2import { Account, Actor, VideoChannel } from '@app/shared/shared-main'
bd45d503 3import { peertubeTranslate } from '@shared/core-utils/i18n'
830b4faf 4import {
67ed6552 5 AccountSummary,
830b4faf
C
6 VideoChannelSummary,
7 VideoConstant,
8 VideoPlaylist as ServerVideoPlaylist,
9 VideoPlaylistPrivacy,
10 VideoPlaylistType
67ed6552 11} from '@shared/models'
830b4faf
C
12
13export 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
951b582f
C
36 embedPath: string
37 embedUrl: string
38
830b4faf
C
39 ownerBy: string
40 ownerAvatarUrl: string
41
42 videoChannelBy?: string
43 videoChannelAvatarUrl?: string
44
65af03a2
C
45 private thumbnailVersion: number
46 private originThumbnailUrl: string
47
830b4faf
C
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
f0a39880 56
830b4faf
C
57 this.description = hash.description
58 this.privacy = hash.privacy
59
60 this.thumbnailPath = hash.thumbnailPath
5fb6996b
C
61
62 if (this.thumbnailPath) {
63 this.thumbnailUrl = absoluteAPIUrl + hash.thumbnailPath
65af03a2 64 this.originThumbnailUrl = this.thumbnailUrl
5fb6996b
C
65 } else {
66 this.thumbnailUrl = window.location.origin + '/client/assets/images/default-playlist.jpg'
67 }
830b4faf 68
951b582f
C
69 this.embedPath = hash.embedPath
70 this.embedUrl = getAbsoluteEmbedUrl() + hash.embedPath
71
830b4faf
C
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)
c418d483 81 this.ownerAvatarUrl = Account.GET_ACTOR_AVATAR_URL(this.ownerAccount)
830b4faf
C
82
83 if (hash.videoChannel) {
84 this.videoChannel = hash.videoChannel
85 this.videoChannelBy = Actor.CREATE_BY_STRING(hash.videoChannel.name, hash.videoChannel.host)
c418d483 86 this.videoChannelAvatarUrl = VideoChannel.GET_ACTOR_AVATAR_URL(this.videoChannel)
830b4faf
C
87 }
88
89 this.privacy.label = peertubeTranslate(this.privacy.label, translations)
f0a39880
C
90
91 if (this.type.id === VideoPlaylistType.WATCH_LATER) {
92 this.displayName = peertubeTranslate(this.displayName, translations)
93 }
830b4faf 94 }
65af03a2
C
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 }
830b4faf 104}