diff options
author | Chocobozzz <me@florianbigard.com> | 2020-06-23 14:10:17 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-06-23 16:00:49 +0200 |
commit | 67ed6552b831df66713bac9e672738796128d33f (patch) | |
tree | 59c97d41e0b49d75a90aa3de987968ab9b1ff447 /client/src/app/shared/shared-video-playlist/video-playlist.model.ts | |
parent | 0c4bacbff53bc732f5a2677d62a6ead7752e2405 (diff) | |
download | PeerTube-67ed6552b831df66713bac9e672738796128d33f.tar.gz PeerTube-67ed6552b831df66713bac9e672738796128d33f.tar.zst PeerTube-67ed6552b831df66713bac9e672738796128d33f.zip |
Reorganize client shared modules
Diffstat (limited to 'client/src/app/shared/shared-video-playlist/video-playlist.model.ts')
-rw-r--r-- | client/src/app/shared/shared-video-playlist/video-playlist.model.ts | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/client/src/app/shared/shared-video-playlist/video-playlist.model.ts b/client/src/app/shared/shared-video-playlist/video-playlist.model.ts new file mode 100644 index 000000000..8f63d2abd --- /dev/null +++ b/client/src/app/shared/shared-video-playlist/video-playlist.model.ts | |||
@@ -0,0 +1,98 @@ | |||
1 | import { getAbsoluteAPIUrl } from '@app/helpers' | ||
2 | import { Actor } from '@app/shared/shared-main' | ||
3 | import { | ||
4 | AccountSummary, | ||
5 | peertubeTranslate, | ||
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 | ownerBy: string | ||
37 | ownerAvatarUrl: string | ||
38 | |||
39 | videoChannelBy?: string | ||
40 | videoChannelAvatarUrl?: string | ||
41 | |||
42 | private thumbnailVersion: number | ||
43 | private originThumbnailUrl: string | ||
44 | |||
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 | ||
53 | |||
54 | this.description = hash.description | ||
55 | this.privacy = hash.privacy | ||
56 | |||
57 | this.thumbnailPath = hash.thumbnailPath | ||
58 | |||
59 | if (this.thumbnailPath) { | ||
60 | this.thumbnailUrl = absoluteAPIUrl + hash.thumbnailPath | ||
61 | this.originThumbnailUrl = this.thumbnailUrl | ||
62 | } else { | ||
63 | this.thumbnailUrl = window.location.origin + '/client/assets/images/default-playlist.jpg' | ||
64 | } | ||
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) | ||
84 | |||
85 | if (this.type.id === VideoPlaylistType.WATCH_LATER) { | ||
86 | this.displayName = peertubeTranslate(this.displayName, translations) | ||
87 | } | ||
88 | } | ||
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 | } | ||
98 | } | ||