provide specific engine boundaries for nodejs and yarn
[oweals/peertube.git] / client / src / app / shared / video-playlist / video-playlist.model.ts
1 import {
2   VideoChannelSummary,
3   VideoConstant,
4   VideoPlaylist as ServerVideoPlaylist,
5   VideoPlaylistPrivacy,
6   VideoPlaylistType
7 } from '../../../../../shared/models/videos'
8 import { AccountSummary, peertubeTranslate } from '@shared/models'
9 import { Actor } from '@app/shared/actor/actor.model'
10 import { getAbsoluteAPIUrl } from '@app/shared/misc/utils'
11
12 export class VideoPlaylist implements ServerVideoPlaylist {
13   id: number
14   uuid: string
15   isLocal: boolean
16
17   displayName: string
18   description: string
19   privacy: VideoConstant<VideoPlaylistPrivacy>
20
21   thumbnailPath: string
22
23   videosLength: number
24
25   type: VideoConstant<VideoPlaylistType>
26
27   createdAt: Date | string
28   updatedAt: Date | string
29
30   ownerAccount: AccountSummary
31   videoChannel?: VideoChannelSummary
32
33   thumbnailUrl: string
34
35   ownerBy: string
36   ownerAvatarUrl: string
37
38   videoChannelBy?: string
39   videoChannelAvatarUrl?: string
40
41   private thumbnailVersion: number
42   private originThumbnailUrl: string
43
44   constructor (hash: ServerVideoPlaylist, translations: {}) {
45     const absoluteAPIUrl = getAbsoluteAPIUrl()
46
47     this.id = hash.id
48     this.uuid = hash.uuid
49     this.isLocal = hash.isLocal
50
51     this.displayName = hash.displayName
52
53     this.description = hash.description
54     this.privacy = hash.privacy
55
56     this.thumbnailPath = hash.thumbnailPath
57
58     if (this.thumbnailPath) {
59       this.thumbnailUrl = absoluteAPIUrl + hash.thumbnailPath
60       this.originThumbnailUrl = this.thumbnailUrl
61     } else {
62       this.thumbnailUrl = window.location.origin + '/client/assets/images/default-playlist.jpg'
63     }
64
65     this.videosLength = hash.videosLength
66
67     this.type = hash.type
68
69     this.createdAt = new Date(hash.createdAt)
70     this.updatedAt = new Date(hash.updatedAt)
71
72     this.ownerAccount = hash.ownerAccount
73     this.ownerBy = Actor.CREATE_BY_STRING(hash.ownerAccount.name, hash.ownerAccount.host)
74     this.ownerAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.ownerAccount)
75
76     if (hash.videoChannel) {
77       this.videoChannel = hash.videoChannel
78       this.videoChannelBy = Actor.CREATE_BY_STRING(hash.videoChannel.name, hash.videoChannel.host)
79       this.videoChannelAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.videoChannel)
80     }
81
82     this.privacy.label = peertubeTranslate(this.privacy.label, translations)
83
84     if (this.type.id === VideoPlaylistType.WATCH_LATER) {
85       this.displayName = peertubeTranslate(this.displayName, translations)
86     }
87   }
88
89   refreshThumbnail () {
90     if (!this.originThumbnailUrl) return
91
92     if (!this.thumbnailVersion) this.thumbnailVersion = 0
93     this.thumbnailVersion++
94
95     this.thumbnailUrl = this.originThumbnailUrl + '?v' + this.thumbnailVersion
96   }
97 }