]>
Commit | Line | Data |
---|---|---|
951b582f | 1 | import { getAbsoluteAPIUrl, getAbsoluteEmbedUrl } from '@app/helpers' |
37a44fc9 | 2 | import { Actor } from '@app/shared/shared-main' |
15a7eafb | 3 | import { buildPlaylistWatchPath } from '@shared/core-utils' |
bd45d503 | 4 | import { peertubeTranslate } from '@shared/core-utils/i18n' |
830b4faf | 5 | import { |
67ed6552 | 6 | AccountSummary, |
830b4faf C |
7 | VideoChannelSummary, |
8 | VideoConstant, | |
9 | VideoPlaylist as ServerVideoPlaylist, | |
10 | VideoPlaylistPrivacy, | |
11 | VideoPlaylistType | |
67ed6552 | 12 | } from '@shared/models' |
830b4faf C |
13 | |
14 | export class VideoPlaylist implements ServerVideoPlaylist { | |
15 | id: number | |
16 | uuid: string | |
d4a8e7a6 C |
17 | shortUUID: string |
18 | ||
830b4faf C |
19 | isLocal: boolean |
20 | ||
37a44fc9 C |
21 | url: string |
22 | ||
830b4faf C |
23 | displayName: string |
24 | description: string | |
25 | privacy: VideoConstant<VideoPlaylistPrivacy> | |
26 | ||
830b4faf C |
27 | videosLength: number |
28 | ||
29 | type: VideoConstant<VideoPlaylistType> | |
30 | ||
31 | createdAt: Date | string | |
32 | updatedAt: Date | string | |
33 | ||
34 | ownerAccount: AccountSummary | |
35 | videoChannel?: VideoChannelSummary | |
36 | ||
37a44fc9 | 37 | thumbnailPath: string |
830b4faf C |
38 | thumbnailUrl: string |
39 | ||
951b582f C |
40 | embedPath: string |
41 | embedUrl: string | |
42 | ||
830b4faf | 43 | ownerBy: string |
830b4faf C |
44 | |
45 | videoChannelBy?: string | |
830b4faf | 46 | |
d4a8e7a6 | 47 | static buildWatchUrl (playlist: Pick<VideoPlaylist, 'uuid' | 'shortUUID'>) { |
15a7eafb | 48 | return buildPlaylistWatchPath({ shortUUID: playlist.shortUUID || playlist.uuid }) |
d4a8e7a6 C |
49 | } |
50 | ||
830b4faf C |
51 | constructor (hash: ServerVideoPlaylist, translations: {}) { |
52 | const absoluteAPIUrl = getAbsoluteAPIUrl() | |
53 | ||
54 | this.id = hash.id | |
55 | this.uuid = hash.uuid | |
d4a8e7a6 C |
56 | this.shortUUID = hash.shortUUID |
57 | ||
37a44fc9 | 58 | this.url = hash.url |
830b4faf C |
59 | this.isLocal = hash.isLocal |
60 | ||
61 | this.displayName = hash.displayName | |
f0a39880 | 62 | |
830b4faf C |
63 | this.description = hash.description |
64 | this.privacy = hash.privacy | |
65 | ||
66 | this.thumbnailPath = hash.thumbnailPath | |
5fb6996b | 67 | |
37a44fc9 C |
68 | this.thumbnailUrl = this.thumbnailPath |
69 | ? hash.thumbnailUrl || (absoluteAPIUrl + hash.thumbnailPath) | |
70 | : absoluteAPIUrl + '/client/assets/images/default-playlist.jpg' | |
830b4faf | 71 | |
951b582f | 72 | this.embedPath = hash.embedPath |
37a44fc9 | 73 | this.embedUrl = hash.embedUrl || (getAbsoluteEmbedUrl() + hash.embedPath) |
951b582f | 74 | |
830b4faf C |
75 | this.videosLength = hash.videosLength |
76 | ||
77 | this.type = hash.type | |
78 | ||
79 | this.createdAt = new Date(hash.createdAt) | |
80 | this.updatedAt = new Date(hash.updatedAt) | |
81 | ||
82 | this.ownerAccount = hash.ownerAccount | |
83 | this.ownerBy = Actor.CREATE_BY_STRING(hash.ownerAccount.name, hash.ownerAccount.host) | |
830b4faf C |
84 | |
85 | if (hash.videoChannel) { | |
86 | this.videoChannel = hash.videoChannel | |
87 | this.videoChannelBy = Actor.CREATE_BY_STRING(hash.videoChannel.name, hash.videoChannel.host) | |
830b4faf C |
88 | } |
89 | ||
90 | this.privacy.label = peertubeTranslate(this.privacy.label, translations) | |
f0a39880 C |
91 | |
92 | if (this.type.id === VideoPlaylistType.WATCH_LATER) { | |
93 | this.displayName = peertubeTranslate(this.displayName, translations) | |
94 | } | |
830b4faf C |
95 | } |
96 | } |