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