]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/video/video.model.ts
Add account link in 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>
9d3ef9fe 16 language: VideoConstant<string>
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: {
03e12d7c
C
38 id: number
39 uuid: string
b64c950a
C
40 name: string
41 displayName: string
42 url: string
43 host: string
44 avatar: Avatar
45 }
aff038cd 46
df98563e 47 private static createDurationString (duration: number) {
f6aec1b0
LD
48 const hours = Math.floor(duration / 3600)
49 const minutes = Math.floor(duration % 3600 / 60)
df98563e 50 const seconds = duration % 60
f6aec1b0 51
df98563e
C
52 const minutesPadding = minutes >= 10 ? '' : '0'
53 const secondsPadding = seconds >= 10 ? '' : '0'
f6aec1b0 54 const displayedHours = hours > 0 ? hours.toString() + ':' : ''
4fd8aa32 55
f6aec1b0
LD
56 return displayedHours + minutesPadding +
57 minutes.toString() + ':' + secondsPadding + seconds.toString()
4fd8aa32
C
58 }
59
404b54e1 60 constructor (hash: VideoServerModel) {
c5911fd3 61 const absoluteAPIUrl = getAbsoluteAPIUrl()
c6e0bfbf 62
d592e0a9 63 this.createdAt = new Date(hash.createdAt.toString())
2922e048 64 this.publishedAt = new Date(hash.publishedAt.toString())
df98563e 65 this.category = hash.category
df98563e 66 this.licence = hash.licence
df98563e 67 this.language = hash.language
2243730c 68 this.privacy = hash.privacy
df98563e
C
69 this.description = hash.description
70 this.duration = hash.duration
71 this.durationLabel = Video.createDurationString(hash.duration)
72 this.id = hash.id
0a6658fd 73 this.uuid = hash.uuid
df98563e 74 this.isLocal = hash.isLocal
df98563e 75 this.name = hash.name
df98563e 76 this.thumbnailPath = hash.thumbnailPath
c6e0bfbf 77 this.thumbnailUrl = absoluteAPIUrl + hash.thumbnailPath
43f61d26 78 this.previewPath = hash.previewPath
c6e0bfbf 79 this.previewUrl = absoluteAPIUrl + hash.previewPath
d8755eed 80 this.embedPath = hash.embedPath
c6e0bfbf 81 this.embedUrl = absoluteAPIUrl + hash.embedPath
df98563e
C
82 this.views = hash.views
83 this.likes = hash.likes
84 this.dislikes = hash.dislikes
85 this.nsfw = hash.nsfw
b64c950a 86 this.account = hash.account
4fd8aa32 87
b64c950a 88 this.by = Account.CREATE_BY_STRING(hash.account.name, hash.account.host)
501bc6c2
C
89 }
90
0883b324
C
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'
92fb909c 100 }
501bc6c2 101}