]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/video/video.model.ts
Add likes/dislikes bar
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / video / video.model.ts
CommitLineData
404b54e1 1import { Video as VideoServerModel } from '../../../../../shared'
202f6b6c 2import { User } from '../'
b1fa3eba 3import { Account } from '../../../../../shared/models/accounts'
92fb909c 4
69f616ab 5export class Video implements VideoServerModel {
b1fa3eba 6 accountName: string
df98563e
C
7 by: string
8 createdAt: Date
6d33593a 9 updatedAt: Date
df98563e
C
10 categoryLabel: string
11 category: number
12 licenceLabel: string
13 licence: number
14 languageLabel: string
15 language: number
16 description: string
17 duration: number
18 durationLabel: string
0a6658fd
C
19 id: number
20 uuid: string
df98563e 21 isLocal: boolean
df98563e 22 name: string
60862425 23 serverHost: string
df98563e
C
24 tags: string[]
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
b1fa3eba 35 account: Account
aff038cd 36
60862425
C
37 private static createByString (account: string, serverHost: string) {
38 return account + '@' + serverHost
aff038cd
C
39 }
40
df98563e
C
41 private static createDurationString (duration: number) {
42 const minutes = Math.floor(duration / 60)
43 const seconds = duration % 60
44 const minutesPadding = minutes >= 10 ? '' : '0'
45 const secondsPadding = seconds >= 10 ? '' : '0'
4fd8aa32 46
df98563e 47 return minutesPadding + minutes.toString() + ':' + secondsPadding + seconds.toString()
4fd8aa32
C
48 }
49
404b54e1 50 constructor (hash: VideoServerModel) {
c6e0bfbf
C
51 let absoluteAPIUrl = API_URL
52 if (!absoluteAPIUrl) {
53 // The API is on the same domain
54 absoluteAPIUrl = window.location.origin
55 }
56
b1fa3eba 57 this.accountName = hash.accountName
d592e0a9 58 this.createdAt = new Date(hash.createdAt.toString())
df98563e
C
59 this.categoryLabel = hash.categoryLabel
60 this.category = hash.category
61 this.licenceLabel = hash.licenceLabel
62 this.licence = hash.licence
63 this.languageLabel = hash.languageLabel
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
60862425 72 this.serverHost = hash.serverHost
df98563e
C
73 this.tags = hash.tags
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
4fd8aa32 84
b1fa3eba 85 this.by = Video.createByString(hash.accountName, hash.serverHost)
501bc6c2
C
86 }
87
df98563e 88 isVideoNSFWForUser (user: User) {
92fb909c 89 // If the video is NSFW and the user is not logged in, or the user does not want to display NSFW videos...
df98563e 90 return (this.nsfw && (!user || user.displayNSFW === false))
92fb909c 91 }
501bc6c2 92}