]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/video/video.model.ts
Fix little typo in variable.
[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'
92fb909c 7
69f616ab 8export class Video implements VideoServerModel {
df98563e
C
9 by: string
10 createdAt: Date
6d33593a 11 updatedAt: Date
09700934
C
12 category: VideoConstant<number>
13 licence: VideoConstant<number>
14 language: VideoConstant<number>
df98563e
C
15 description: string
16 duration: number
17 durationLabel: string
0a6658fd
C
18 id: number
19 uuid: string
df98563e 20 isLocal: boolean
df98563e 21 name: string
60862425 22 serverHost: string
df98563e
C
23 thumbnailPath: string
24 thumbnailUrl: string
43f61d26
C
25 previewPath: string
26 previewUrl: string
d8755eed
C
27 embedPath: string
28 embedUrl: string
df98563e
C
29 views: number
30 likes: number
31 dislikes: number
32 nsfw: boolean
b64c950a
C
33
34 account: {
35 name: string
36 displayName: string
37 url: string
38 host: string
39 avatar: Avatar
40 }
aff038cd 41
df98563e 42 private static createDurationString (duration: number) {
f6aec1b0
LD
43 const hours = Math.floor(duration / 3600)
44 const minutes = Math.floor(duration % 3600 / 60)
df98563e 45 const seconds = duration % 60
f6aec1b0 46
df98563e
C
47 const minutesPadding = minutes >= 10 ? '' : '0'
48 const secondsPadding = seconds >= 10 ? '' : '0'
f6aec1b0 49 const displayedHours = hours > 0 ? hours.toString() + ':' : ''
4fd8aa32 50
f6aec1b0
LD
51 return displayedHours + minutesPadding +
52 minutes.toString() + ':' + secondsPadding + seconds.toString()
4fd8aa32
C
53 }
54
404b54e1 55 constructor (hash: VideoServerModel) {
c5911fd3 56 const absoluteAPIUrl = getAbsoluteAPIUrl()
c6e0bfbf 57
d592e0a9 58 this.createdAt = new Date(hash.createdAt.toString())
df98563e 59 this.category = hash.category
df98563e 60 this.licence = hash.licence
df98563e
C
61 this.language = hash.language
62 this.description = hash.description
63 this.duration = hash.duration
64 this.durationLabel = Video.createDurationString(hash.duration)
65 this.id = hash.id
0a6658fd 66 this.uuid = hash.uuid
df98563e 67 this.isLocal = hash.isLocal
df98563e 68 this.name = hash.name
df98563e 69 this.thumbnailPath = hash.thumbnailPath
c6e0bfbf 70 this.thumbnailUrl = absoluteAPIUrl + hash.thumbnailPath
43f61d26 71 this.previewPath = hash.previewPath
c6e0bfbf 72 this.previewUrl = absoluteAPIUrl + hash.previewPath
d8755eed 73 this.embedPath = hash.embedPath
c6e0bfbf 74 this.embedUrl = absoluteAPIUrl + hash.embedPath
df98563e
C
75 this.views = hash.views
76 this.likes = hash.likes
77 this.dislikes = hash.dislikes
78 this.nsfw = hash.nsfw
b64c950a 79 this.account = hash.account
4fd8aa32 80
b64c950a 81 this.by = Account.CREATE_BY_STRING(hash.account.name, hash.account.host)
501bc6c2
C
82 }
83
df98563e 84 isVideoNSFWForUser (user: User) {
92fb909c 85 // If the video is NSFW and the user is not logged in, or the user does not want to display NSFW videos...
df98563e 86 return (this.nsfw && (!user || user.displayNSFW === false))
92fb909c 87 }
501bc6c2 88}