]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/videos/shared/video.model.ts
Remove any typing from server
[github/Chocobozzz/PeerTube.git] / client / src / app / videos / shared / video.model.ts
1 import { Video as VideoServerModel } from '../../../../../shared'
2 import { User } from '../../shared'
3
4 export class Video implements VideoServerModel {
5 author: string
6 by: string
7 createdAt: Date
8 categoryLabel: string
9 category: number
10 licenceLabel: string
11 licence: number
12 languageLabel: string
13 language: number
14 description: string
15 duration: number
16 durationLabel: string
17 id: string
18 isLocal: boolean
19 magnetUri: string
20 name: string
21 podHost: string
22 tags: string[]
23 thumbnailPath: string
24 thumbnailUrl: string
25 views: number
26 likes: number
27 dislikes: number
28 nsfw: boolean
29
30 private static createByString (author: string, podHost: string) {
31 return author + '@' + podHost
32 }
33
34 private static createDurationString (duration: number) {
35 const minutes = Math.floor(duration / 60)
36 const seconds = duration % 60
37 const minutesPadding = minutes >= 10 ? '' : '0'
38 const secondsPadding = seconds >= 10 ? '' : '0'
39
40 return minutesPadding + minutes.toString() + ':' + secondsPadding + seconds.toString()
41 }
42
43 constructor (hash: {
44 author: string,
45 createdAt: string,
46 categoryLabel: string,
47 category: number,
48 licenceLabel: string,
49 licence: number,
50 languageLabel: string
51 language: number
52 description: string,
53 duration: number
54 id: string,
55 isLocal: boolean,
56 magnetUri: string,
57 name: string,
58 podHost: string,
59 tags: string[],
60 thumbnailPath: string,
61 views: number,
62 likes: number,
63 dislikes: number,
64 nsfw: boolean
65 }) {
66 this.author = hash.author
67 this.createdAt = new Date(hash.createdAt)
68 this.categoryLabel = hash.categoryLabel
69 this.category = hash.category
70 this.licenceLabel = hash.licenceLabel
71 this.licence = hash.licence
72 this.languageLabel = hash.languageLabel
73 this.language = hash.language
74 this.description = hash.description
75 this.duration = hash.duration
76 this.durationLabel = Video.createDurationString(hash.duration)
77 this.id = hash.id
78 this.isLocal = hash.isLocal
79 this.magnetUri = hash.magnetUri
80 this.name = hash.name
81 this.podHost = hash.podHost
82 this.tags = hash.tags
83 this.thumbnailPath = hash.thumbnailPath
84 this.thumbnailUrl = API_URL + hash.thumbnailPath
85 this.views = hash.views
86 this.likes = hash.likes
87 this.dislikes = hash.dislikes
88 this.nsfw = hash.nsfw
89
90 this.by = Video.createByString(hash.author, hash.podHost)
91 }
92
93 isRemovableBy (user) {
94 return user && this.isLocal === true && (this.author === user.username || user.isAdmin() === true)
95 }
96
97 isBlackistableBy (user) {
98 return user && user.isAdmin() === true && this.isLocal === false
99 }
100
101 isUpdatableBy (user) {
102 return user && this.isLocal === true && user.username === this.author
103 }
104
105 isVideoNSFWForUser (user: User) {
106 // If the video is NSFW and the user is not logged in, or the user does not want to display NSFW videos...
107 return (this.nsfw && (!user || user.displayNSFW === false))
108 }
109
110 patch (values: Object) {
111 Object.keys(values).forEach((key) => {
112 this[key] = values[key]
113 })
114 }
115
116 toJSON () {
117 return {
118 author: this.author,
119 createdAt: this.createdAt,
120 category: this.category,
121 licence: this.licence,
122 language: this.language,
123 description: this.description,
124 duration: this.duration,
125 id: this.id,
126 isLocal: this.isLocal,
127 magnetUri: this.magnetUri,
128 name: this.name,
129 podHost: this.podHost,
130 tags: this.tags,
131 thumbnailPath: this.thumbnailPath,
132 views: this.views,
133 likes: this.likes,
134 dislikes: this.dislikes,
135 nsfw: this.nsfw
136 }
137 }
138 }