]>
Commit | Line | Data |
---|---|---|
951b582f | 1 | import { getAbsoluteAPIUrl, getAbsoluteEmbedUrl } from '@app/helpers' |
c418d483 | 2 | import { Account, Actor, VideoChannel } from '@app/shared/shared-main' |
bd45d503 | 3 | import { peertubeTranslate } from '@shared/core-utils/i18n' |
830b4faf | 4 | import { |
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 | |
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 | ||
951b582f C |
36 | embedPath: string |
37 | embedUrl: string | |
38 | ||
830b4faf | 39 | ownerBy: string |
830b4faf C |
40 | |
41 | videoChannelBy?: string | |
830b4faf | 42 | |
65af03a2 C |
43 | private thumbnailVersion: number |
44 | private originThumbnailUrl: string | |
45 | ||
830b4faf C |
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 | |
f0a39880 | 54 | |
830b4faf C |
55 | this.description = hash.description |
56 | this.privacy = hash.privacy | |
57 | ||
58 | this.thumbnailPath = hash.thumbnailPath | |
5fb6996b C |
59 | |
60 | if (this.thumbnailPath) { | |
61 | this.thumbnailUrl = absoluteAPIUrl + hash.thumbnailPath | |
65af03a2 | 62 | this.originThumbnailUrl = this.thumbnailUrl |
5fb6996b C |
63 | } else { |
64 | this.thumbnailUrl = window.location.origin + '/client/assets/images/default-playlist.jpg' | |
65 | } | |
830b4faf | 66 | |
951b582f C |
67 | this.embedPath = hash.embedPath |
68 | this.embedUrl = getAbsoluteEmbedUrl() + hash.embedPath | |
69 | ||
830b4faf C |
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) | |
830b4faf C |
79 | |
80 | if (hash.videoChannel) { | |
81 | this.videoChannel = hash.videoChannel | |
82 | this.videoChannelBy = Actor.CREATE_BY_STRING(hash.videoChannel.name, hash.videoChannel.host) | |
830b4faf C |
83 | } |
84 | ||
85 | this.privacy.label = peertubeTranslate(this.privacy.label, translations) | |
f0a39880 C |
86 | |
87 | if (this.type.id === VideoPlaylistType.WATCH_LATER) { | |
88 | this.displayName = peertubeTranslate(this.displayName, translations) | |
89 | } | |
830b4faf | 90 | } |
65af03a2 C |
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 | } | |
830b4faf | 100 | } |