]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/shared/video/video.model.ts
Merge branch 'develop' of framagit.org:chocobozzz/PeerTube into develop
[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<number>
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 name: string
39 displayName: string
40 url: string
41 host: string
42 avatar: Avatar
43 }
44
45 private static createDurationString (duration: number) {
46 const hours = Math.floor(duration / 3600)
47 const minutes = Math.floor(duration % 3600 / 60)
48 const seconds = duration % 60
49
50 const minutesPadding = minutes >= 10 ? '' : '0'
51 const secondsPadding = seconds >= 10 ? '' : '0'
52 const displayedHours = hours > 0 ? hours.toString() + ':' : ''
53
54 return displayedHours + minutesPadding +
55 minutes.toString() + ':' + secondsPadding + seconds.toString()
56 }
57
58 constructor (hash: VideoServerModel) {
59 const absoluteAPIUrl = getAbsoluteAPIUrl()
60
61 this.createdAt = new Date(hash.createdAt.toString())
62 this.publishedAt = new Date(hash.publishedAt.toString())
63 this.category = hash.category
64 this.licence = hash.licence
65 this.language = hash.language
66 this.privacy = hash.privacy
67 this.description = hash.description
68 this.duration = hash.duration
69 this.durationLabel = Video.createDurationString(hash.duration)
70 this.id = hash.id
71 this.uuid = hash.uuid
72 this.isLocal = hash.isLocal
73 this.name = hash.name
74 this.thumbnailPath = hash.thumbnailPath
75 this.thumbnailUrl = absoluteAPIUrl + hash.thumbnailPath
76 this.previewPath = hash.previewPath
77 this.previewUrl = absoluteAPIUrl + hash.previewPath
78 this.embedPath = hash.embedPath
79 this.embedUrl = absoluteAPIUrl + hash.embedPath
80 this.views = hash.views
81 this.likes = hash.likes
82 this.dislikes = hash.dislikes
83 this.nsfw = hash.nsfw
84 this.account = hash.account
85
86 this.by = Account.CREATE_BY_STRING(hash.account.name, hash.account.host)
87 }
88
89 isVideoNSFWForUser (user: User, serverConfig: ServerConfig) {
90 // Video is not NSFW, skip
91 if (this.nsfw === false) return false
92
93 // Return user setting if logged in
94 if (user) return user.nsfwPolicy !== 'display'
95
96 // Return default instance config
97 return serverConfig.instance.defaultNSFWPolicy !== 'display'
98 }
99 }