]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/shared/video/video.model.ts
Begin to add avatar to actors
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / video / video.model.ts
1 import { User } from '../'
2 import { Video as VideoServerModel } from '../../../../../shared'
3 import { Account } from '../../../../../shared/models/actors'
4 import { environment } from '../../../environments/environment'
5 import { getAbsoluteAPIUrl } from '../misc/utils'
6
7 export class Video implements VideoServerModel {
8 accountName: string
9 by: string
10 createdAt: Date
11 updatedAt: Date
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
21 id: number
22 uuid: string
23 isLocal: boolean
24 name: string
25 serverHost: string
26 thumbnailPath: string
27 thumbnailUrl: string
28 previewPath: string
29 previewUrl: string
30 embedPath: string
31 embedUrl: string
32 views: number
33 likes: number
34 dislikes: number
35 nsfw: boolean
36 account: Account
37
38 private static createByString (account: string, serverHost: string) {
39 return account + '@' + serverHost
40 }
41
42 private static createDurationString (duration: number) {
43 const minutes = Math.floor(duration / 60)
44 const seconds = duration % 60
45 const minutesPadding = minutes >= 10 ? '' : '0'
46 const secondsPadding = seconds >= 10 ? '' : '0'
47
48 return minutesPadding + minutes.toString() + ':' + secondsPadding + seconds.toString()
49 }
50
51 constructor (hash: VideoServerModel) {
52 const absoluteAPIUrl = getAbsoluteAPIUrl()
53
54 this.accountName = hash.accountName
55 this.createdAt = new Date(hash.createdAt.toString())
56 this.categoryLabel = hash.categoryLabel
57 this.category = hash.category
58 this.licenceLabel = hash.licenceLabel
59 this.licence = hash.licence
60 this.languageLabel = hash.languageLabel
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
66 this.uuid = hash.uuid
67 this.isLocal = hash.isLocal
68 this.name = hash.name
69 this.serverHost = hash.serverHost
70 this.thumbnailPath = hash.thumbnailPath
71 this.thumbnailUrl = absoluteAPIUrl + hash.thumbnailPath
72 this.previewPath = hash.previewPath
73 this.previewUrl = absoluteAPIUrl + hash.previewPath
74 this.embedPath = hash.embedPath
75 this.embedUrl = absoluteAPIUrl + hash.embedPath
76 this.views = hash.views
77 this.likes = hash.likes
78 this.dislikes = hash.dislikes
79 this.nsfw = hash.nsfw
80
81 this.by = Video.createByString(hash.accountName, hash.serverHost)
82 }
83
84 isVideoNSFWForUser (user: User) {
85 // If the video is NSFW and the user is not logged in, or the user does not want to display NSFW videos...
86 return (this.nsfw && (!user || user.displayNSFW === false))
87 }
88 }