]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/video/video.model.ts
Add ability to choose what policy we have for NSFW videos
[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 '../'
63c4db6d 3import { Video as VideoServerModel } 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>
df98563e
C
17 description: string
18 duration: number
19 durationLabel: string
0a6658fd
C
20 id: number
21 uuid: string
df98563e 22 isLocal: boolean
df98563e 23 name: string
60862425 24 serverHost: string
df98563e
C
25 thumbnailPath: string
26 thumbnailUrl: string
43f61d26
C
27 previewPath: string
28 previewUrl: string
d8755eed
C
29 embedPath: string
30 embedUrl: string
df98563e
C
31 views: number
32 likes: number
33 dislikes: number
34 nsfw: boolean
b64c950a
C
35
36 account: {
37 name: string
38 displayName: string
39 url: string
40 host: string
41 avatar: Avatar
42 }
aff038cd 43
df98563e 44 private static createDurationString (duration: number) {
f6aec1b0
LD
45 const hours = Math.floor(duration / 3600)
46 const minutes = Math.floor(duration % 3600 / 60)
df98563e 47 const seconds = duration % 60
f6aec1b0 48
df98563e
C
49 const minutesPadding = minutes >= 10 ? '' : '0'
50 const secondsPadding = seconds >= 10 ? '' : '0'
f6aec1b0 51 const displayedHours = hours > 0 ? hours.toString() + ':' : ''
4fd8aa32 52
f6aec1b0
LD
53 return displayedHours + minutesPadding +
54 minutes.toString() + ':' + secondsPadding + seconds.toString()
4fd8aa32
C
55 }
56
404b54e1 57 constructor (hash: VideoServerModel) {
c5911fd3 58 const absoluteAPIUrl = getAbsoluteAPIUrl()
c6e0bfbf 59
d592e0a9 60 this.createdAt = new Date(hash.createdAt.toString())
2922e048 61 this.publishedAt = new Date(hash.publishedAt.toString())
df98563e 62 this.category = hash.category
df98563e 63 this.licence = hash.licence
df98563e
C
64 this.language = hash.language
65 this.description = hash.description
66 this.duration = hash.duration
67 this.durationLabel = Video.createDurationString(hash.duration)
68 this.id = hash.id
0a6658fd 69 this.uuid = hash.uuid
df98563e 70 this.isLocal = hash.isLocal
df98563e 71 this.name = hash.name
df98563e 72 this.thumbnailPath = hash.thumbnailPath
c6e0bfbf 73 this.thumbnailUrl = absoluteAPIUrl + hash.thumbnailPath
43f61d26 74 this.previewPath = hash.previewPath
c6e0bfbf 75 this.previewUrl = absoluteAPIUrl + hash.previewPath
d8755eed 76 this.embedPath = hash.embedPath
c6e0bfbf 77 this.embedUrl = absoluteAPIUrl + hash.embedPath
df98563e
C
78 this.views = hash.views
79 this.likes = hash.likes
80 this.dislikes = hash.dislikes
81 this.nsfw = hash.nsfw
b64c950a 82 this.account = hash.account
4fd8aa32 83
b64c950a 84 this.by = Account.CREATE_BY_STRING(hash.account.name, hash.account.host)
501bc6c2
C
85 }
86
0883b324
C
87 isVideoNSFWForUser (user: User, serverConfig: ServerConfig) {
88 // Video is not NSFW, skip
89 if (this.nsfw === false) return false
90
91 // Return user setting if logged in
92 if (user) return user.nsfwPolicy !== 'display'
93
94 // Return default instance config
95 return serverConfig.instance.defaultNSFWPolicy !== 'display'
92fb909c 96 }
501bc6c2 97}