]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/shared/video/video.model.ts
Begin moving video channel to actor
[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
6 export class Video implements VideoServerModel {
7 accountName: string
8 by: string
9 createdAt: Date
10 updatedAt: Date
11 categoryLabel: string
12 category: number
13 licenceLabel: string
14 licence: number
15 languageLabel: string
16 language: number
17 description: string
18 duration: number
19 durationLabel: string
20 id: number
21 uuid: string
22 isLocal: boolean
23 name: string
24 serverHost: string
25 thumbnailPath: string
26 thumbnailUrl: string
27 previewPath: string
28 previewUrl: string
29 embedPath: string
30 embedUrl: string
31 views: number
32 likes: number
33 dislikes: number
34 nsfw: boolean
35 account: Account
36
37 private static createByString (account: string, serverHost: string) {
38 return account + '@' + serverHost
39 }
40
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'
46
47 return minutesPadding + minutes.toString() + ':' + secondsPadding + seconds.toString()
48 }
49
50 constructor (hash: VideoServerModel) {
51 let absoluteAPIUrl = environment.apiUrl
52 if (!absoluteAPIUrl) {
53 // The API is on the same domain
54 absoluteAPIUrl = window.location.origin
55 }
56
57 this.accountName = hash.accountName
58 this.createdAt = new Date(hash.createdAt.toString())
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
69 this.uuid = hash.uuid
70 this.isLocal = hash.isLocal
71 this.name = hash.name
72 this.serverHost = hash.serverHost
73 this.thumbnailPath = hash.thumbnailPath
74 this.thumbnailUrl = absoluteAPIUrl + hash.thumbnailPath
75 this.previewPath = hash.previewPath
76 this.previewUrl = absoluteAPIUrl + hash.previewPath
77 this.embedPath = hash.embedPath
78 this.embedUrl = absoluteAPIUrl + hash.embedPath
79 this.views = hash.views
80 this.likes = hash.likes
81 this.dislikes = hash.dislikes
82 this.nsfw = hash.nsfw
83
84 this.by = Video.createByString(hash.accountName, hash.serverHost)
85 }
86
87 isVideoNSFWForUser (user: User) {
88 // If the video is NSFW and the user is not logged in, or the user does not want to display NSFW videos...
89 return (this.nsfw && (!user || user.displayNSFW === false))
90 }
91 }