]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/shared/video/video.model.ts
2e85f40eff008f9e1b9af60955e9b3c4182f6e65
[github/Chocobozzz/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, VideoPrivacy } from '../../../../../shared'
4 import { Avatar } from '../../../../../shared/models/avatars/avatar.model'
5 import { VideoConstant } from '../../../../../shared/models/videos/video.model'
6 import { getAbsoluteAPIUrl } from '../misc/utils'
7 import { ServerConfig } from '../../../../../shared/models'
8
9 export class Video implements VideoServerModel {
10 by: string
11 createdAt: Date
12 updatedAt: Date
13 publishedAt: Date
14 category: VideoConstant<number>
15 licence: VideoConstant<number>
16 language: VideoConstant<string>
17 privacy: VideoConstant<VideoPrivacy>
18 description: string
19 duration: number
20 durationLabel: string
21 id: number
22 uuid: string
23 isLocal: boolean
24 name: string
25 serverHost: string
26 thumbnailPath: string
27 thumbnailUrl: string
28 previewPath: string
29 previewUrl: string
30 embedPath: string
31 embedUrl: string
32 views: number
33 likes: number
34 dislikes: number
35 nsfw: boolean
36
37 account: {
38 id: number
39 uuid: string
40 name: string
41 displayName: string
42 url: string
43 host: string
44 avatar: Avatar
45 }
46
47 private static createDurationString (duration: number) {
48 const hours = Math.floor(duration / 3600)
49 const minutes = Math.floor(duration % 3600 / 60)
50 const seconds = duration % 60
51
52 const minutesPadding = minutes >= 10 ? '' : '0'
53 const secondsPadding = seconds >= 10 ? '' : '0'
54 const displayedHours = hours > 0 ? hours.toString() + ':' : ''
55
56 return displayedHours + minutesPadding +
57 minutes.toString() + ':' + secondsPadding + seconds.toString()
58 }
59
60 constructor (hash: VideoServerModel) {
61 const absoluteAPIUrl = getAbsoluteAPIUrl()
62
63 this.createdAt = new Date(hash.createdAt.toString())
64 this.publishedAt = new Date(hash.publishedAt.toString())
65 this.category = hash.category
66 this.licence = hash.licence
67 this.language = hash.language
68 this.privacy = hash.privacy
69 this.description = hash.description
70 this.duration = hash.duration
71 this.durationLabel = Video.createDurationString(hash.duration)
72 this.id = hash.id
73 this.uuid = hash.uuid
74 this.isLocal = hash.isLocal
75 this.name = hash.name
76 this.thumbnailPath = hash.thumbnailPath
77 this.thumbnailUrl = absoluteAPIUrl + hash.thumbnailPath
78 this.previewPath = hash.previewPath
79 this.previewUrl = absoluteAPIUrl + hash.previewPath
80 this.embedPath = hash.embedPath
81 this.embedUrl = absoluteAPIUrl + hash.embedPath
82 this.views = hash.views
83 this.likes = hash.likes
84 this.dislikes = hash.dislikes
85 this.nsfw = hash.nsfw
86 this.account = hash.account
87
88 this.by = Account.CREATE_BY_STRING(hash.account.name, hash.account.host)
89 }
90
91 isVideoNSFWForUser (user: User, serverConfig: ServerConfig) {
92 // Video is not NSFW, skip
93 if (this.nsfw === false) return false
94
95 // Return user setting if logged in
96 if (user) return user.nsfwPolicy !== 'display'
97
98 // Return default instance config
99 return serverConfig.instance.defaultNSFWPolicy !== 'display'
100 }
101 }