]>
Commit | Line | Data |
---|---|---|
67ed6552 C |
1 | import { getAbsoluteAPIUrl } from '@app/helpers' |
2 | import { Actor } from '@app/shared/shared-main' | |
830b4faf | 3 | import { |
67ed6552 C |
4 | AccountSummary, |
5 | peertubeTranslate, | |
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 | ||
36 | ownerBy: string | |
37 | ownerAvatarUrl: string | |
38 | ||
39 | videoChannelBy?: string | |
40 | videoChannelAvatarUrl?: string | |
41 | ||
65af03a2 C |
42 | private thumbnailVersion: number |
43 | private originThumbnailUrl: string | |
44 | ||
830b4faf C |
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 | |
f0a39880 | 53 | |
830b4faf C |
54 | this.description = hash.description |
55 | this.privacy = hash.privacy | |
56 | ||
57 | this.thumbnailPath = hash.thumbnailPath | |
5fb6996b C |
58 | |
59 | if (this.thumbnailPath) { | |
60 | this.thumbnailUrl = absoluteAPIUrl + hash.thumbnailPath | |
65af03a2 | 61 | this.originThumbnailUrl = this.thumbnailUrl |
5fb6996b C |
62 | } else { |
63 | this.thumbnailUrl = window.location.origin + '/client/assets/images/default-playlist.jpg' | |
64 | } | |
830b4faf C |
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) | |
f0a39880 C |
84 | |
85 | if (this.type.id === VideoPlaylistType.WATCH_LATER) { | |
86 | this.displayName = peertubeTranslate(this.displayName, translations) | |
87 | } | |
830b4faf | 88 | } |
65af03a2 C |
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 | } | |
830b4faf | 98 | } |