]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/video/video.model.ts
Add information concerning video privacy in my videos list
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / video / video.model.ts
CommitLineData
76d36e0b 1import { Account } from '@app/shared/account/account.model'
202f6b6c 2import { User } from '../'
2243730c 3import { Video as VideoServerModel, VideoPrivacy } from '../../../../../shared'
b64c950a 4import { Avatar } from '../../../../../shared/models/avatars/avatar.model'
09700934 5import { VideoConstant } from '../../../../../shared/models/videos/video.model'
c5911fd3 6import { getAbsoluteAPIUrl } from '../misc/utils'
0883b324 7import { ServerConfig } from '../../../../../shared/models'
92fb909c 8
69f616ab 9export class Video implements VideoServerModel {
df98563e
C
10 by: string
11 createdAt: Date
6d33593a 12 updatedAt: Date
2922e048 13 publishedAt: Date
09700934
C
14 category: VideoConstant<number>
15 licence: VideoConstant<number>
16 language: VideoConstant<number>
2243730c 17 privacy: VideoConstant<VideoPrivacy>
df98563e
C
18 description: string
19 duration: number
20 durationLabel: string
0a6658fd
C
21 id: number
22 uuid: string
df98563e 23 isLocal: boolean
df98563e 24 name: string
60862425 25 serverHost: string
df98563e
C
26 thumbnailPath: string
27 thumbnailUrl: string
43f61d26
C
28 previewPath: string
29 previewUrl: string
d8755eed
C
30 embedPath: string
31 embedUrl: string
df98563e
C
32 views: number
33 likes: number
34 dislikes: number
35 nsfw: boolean
b64c950a
C
36
37 account: {
38 name: string
39 displayName: string
40 url: string
41 host: string
42 avatar: Avatar
43 }
aff038cd 44
df98563e 45 private static createDurationString (duration: number) {
f6aec1b0
LD
46 const hours = Math.floor(duration / 3600)
47 const minutes = Math.floor(duration % 3600 / 60)
df98563e 48 const seconds = duration % 60
f6aec1b0 49
df98563e
C
50 const minutesPadding = minutes >= 10 ? '' : '0'
51 const secondsPadding = seconds >= 10 ? '' : '0'
f6aec1b0 52 const displayedHours = hours > 0 ? hours.toString() + ':' : ''
4fd8aa32 53
f6aec1b0
LD
54 return displayedHours + minutesPadding +
55 minutes.toString() + ':' + secondsPadding + seconds.toString()
4fd8aa32
C
56 }
57
404b54e1 58 constructor (hash: VideoServerModel) {
c5911fd3 59 const absoluteAPIUrl = getAbsoluteAPIUrl()
c6e0bfbf 60
d592e0a9 61 this.createdAt = new Date(hash.createdAt.toString())
2922e048 62 this.publishedAt = new Date(hash.publishedAt.toString())
df98563e 63 this.category = hash.category
df98563e 64 this.licence = hash.licence
df98563e 65 this.language = hash.language
2243730c 66 this.privacy = hash.privacy
df98563e
C
67 this.description = hash.description
68 this.duration = hash.duration
69 this.durationLabel = Video.createDurationString(hash.duration)
70 this.id = hash.id
0a6658fd 71 this.uuid = hash.uuid
df98563e 72 this.isLocal = hash.isLocal
df98563e 73 this.name = hash.name
df98563e 74 this.thumbnailPath = hash.thumbnailPath
c6e0bfbf 75 this.thumbnailUrl = absoluteAPIUrl + hash.thumbnailPath
43f61d26 76 this.previewPath = hash.previewPath
c6e0bfbf 77 this.previewUrl = absoluteAPIUrl + hash.previewPath
d8755eed 78 this.embedPath = hash.embedPath
c6e0bfbf 79 this.embedUrl = absoluteAPIUrl + hash.embedPath
df98563e
C
80 this.views = hash.views
81 this.likes = hash.likes
82 this.dislikes = hash.dislikes
83 this.nsfw = hash.nsfw
b64c950a 84 this.account = hash.account
4fd8aa32 85
b64c950a 86 this.by = Account.CREATE_BY_STRING(hash.account.name, hash.account.host)
501bc6c2
C
87 }
88
0883b324
C
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'
92fb909c 98 }
501bc6c2 99}