Add background placeholder for thumbnails
[oweals/peertube.git] / client / src / app / shared / video / video.model.ts
1 import { Account } from '@app/shared/account/account.model'
2 import { User } from '../'
3 import { Video as VideoServerModel } from '../../../../../shared'
4 import { getAbsoluteAPIUrl } from '../misc/utils'
5
6 export class Video implements VideoServerModel {
7   accountName: string
8   by: string
9   createdAt: Date
10   updatedAt: Date
11   categoryLabel: string
12   category: number
13   licenceLabel: string
14   licence: number
15   languageLabel: string
16   language: number
17   description: string
18   duration: number
19   durationLabel: string
20   id: number
21   uuid: string
22   isLocal: boolean
23   name: string
24   serverHost: string
25   thumbnailPath: string
26   thumbnailUrl: string
27   previewPath: string
28   previewUrl: string
29   embedPath: string
30   embedUrl: string
31   views: number
32   likes: number
33   dislikes: number
34   nsfw: boolean
35   account: Account
36
37   private static createDurationString (duration: number) {
38     const minutes = Math.floor(duration / 60)
39     const seconds = duration % 60
40     const minutesPadding = minutes >= 10 ? '' : '0'
41     const secondsPadding = seconds >= 10 ? '' : '0'
42
43     return minutesPadding + minutes.toString() + ':' + secondsPadding + seconds.toString()
44   }
45
46   constructor (hash: VideoServerModel) {
47     const absoluteAPIUrl = getAbsoluteAPIUrl()
48
49     this.accountName = hash.accountName
50     this.createdAt = new Date(hash.createdAt.toString())
51     this.categoryLabel = hash.categoryLabel
52     this.category = hash.category
53     this.licenceLabel = hash.licenceLabel
54     this.licence = hash.licence
55     this.languageLabel = hash.languageLabel
56     this.language = hash.language
57     this.description = hash.description
58     this.duration = hash.duration
59     this.durationLabel = Video.createDurationString(hash.duration)
60     this.id = hash.id
61     this.uuid = hash.uuid
62     this.isLocal = hash.isLocal
63     this.name = hash.name
64     this.serverHost = hash.serverHost
65     this.thumbnailPath = hash.thumbnailPath
66     this.thumbnailUrl = absoluteAPIUrl + hash.thumbnailPath
67     this.previewPath = hash.previewPath
68     this.previewUrl = absoluteAPIUrl + hash.previewPath
69     this.embedPath = hash.embedPath
70     this.embedUrl = absoluteAPIUrl + hash.embedPath
71     this.views = hash.views
72     this.likes = hash.likes
73     this.dislikes = hash.dislikes
74     this.nsfw = hash.nsfw
75
76     this.by = Account.CREATE_BY_STRING(hash.accountName, hash.serverHost)
77   }
78
79   isVideoNSFWForUser (user: User) {
80     // If the video is NSFW and the user is not logged in, or the user does not want to display NSFW videos...
81     return (this.nsfw && (!user || user.displayNSFW === false))
82   }
83 }