]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/video/video.model.ts
A few updates for the watch video view (#181)
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / video / video.model.ts
CommitLineData
202f6b6c 1import { User } from '../'
63c4db6d 2import { Video as VideoServerModel } from '../../../../../shared'
50d6de9c 3import { Account } from '../../../../../shared/models/actors'
63c4db6d 4import { environment } from '../../../environments/environment'
c5911fd3 5import { getAbsoluteAPIUrl } from '../misc/utils'
92fb909c 6
69f616ab 7export class Video implements VideoServerModel {
b1fa3eba 8 accountName: string
df98563e
C
9 by: string
10 createdAt: Date
6d33593a 11 updatedAt: Date
df98563e
C
12 categoryLabel: string
13 category: number
14 licenceLabel: string
15 licence: number
16 languageLabel: string
17 language: number
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
b1fa3eba 36 account: Account
aff038cd 37
57a49263
BB
38 private static createByString (account: string, serverHost: string, apiURL: string) {
39 const thisHost = new URL(apiURL).host
40 if (serverHost.trim() === thisHost)
41 return account
60862425 42 return account + '@' + serverHost
aff038cd
C
43 }
44
df98563e
C
45 private static createDurationString (duration: number) {
46 const minutes = Math.floor(duration / 60)
47 const seconds = duration % 60
48 const minutesPadding = minutes >= 10 ? '' : '0'
49 const secondsPadding = seconds >= 10 ? '' : '0'
4fd8aa32 50
df98563e 51 return minutesPadding + minutes.toString() + ':' + secondsPadding + seconds.toString()
4fd8aa32
C
52 }
53
404b54e1 54 constructor (hash: VideoServerModel) {
c5911fd3 55 const absoluteAPIUrl = getAbsoluteAPIUrl()
c6e0bfbf 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 73 this.thumbnailPath = hash.thumbnailPath
c6e0bfbf 74 this.thumbnailUrl = absoluteAPIUrl + hash.thumbnailPath
43f61d26 75 this.previewPath = hash.previewPath
c6e0bfbf 76 this.previewUrl = absoluteAPIUrl + hash.previewPath
d8755eed 77 this.embedPath = hash.embedPath
c6e0bfbf 78 this.embedUrl = absoluteAPIUrl + hash.embedPath
df98563e
C
79 this.views = hash.views
80 this.likes = hash.likes
81 this.dislikes = hash.dislikes
82 this.nsfw = hash.nsfw
4fd8aa32 83
57a49263 84 this.by = Video.createByString(hash.accountName, hash.serverHost, absoluteAPIUrl)
501bc6c2
C
85 }
86
df98563e 87 isVideoNSFWForUser (user: User) {
92fb909c 88 // If the video is NSFW and the user is not logged in, or the user does not want to display NSFW videos...
df98563e 89 return (this.nsfw && (!user || user.displayNSFW === false))
92fb909c 90 }
501bc6c2 91}