]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - 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
CommitLineData
df98563e
C
1import { Video as VideoServerModel } from '../../../../../shared'
2import { User } from '../../shared'
92fb909c 3
69f616ab 4export class Video implements VideoServerModel {
df98563e
C
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
aff038cd 29
df98563e
C
30 private static createByString (author: string, podHost: string) {
31 return author + '@' + podHost
aff038cd
C
32 }
33
df98563e
C
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'
4fd8aa32 39
df98563e 40 return minutesPadding + minutes.toString() + ':' + secondsPadding + seconds.toString()
4fd8aa32
C
41 }
42
df98563e 43 constructor (hash: {
501bc6c2 44 author: string,
feb4bdfd 45 createdAt: string,
6e07c3de 46 categoryLabel: string,
69f616ab 47 category: number,
d07137b9 48 licenceLabel: string,
69f616ab 49 licence: number,
df98563e
C
50 languageLabel: string
51 language: number
4fd8aa32 52 description: string,
df98563e 53 duration: number
4fd8aa32
C
54 id: string,
55 isLocal: boolean,
56 magnetUri: string,
57 name: string,
49abbbbe 58 podHost: string,
00a44645 59 tags: string[],
05a9feaa 60 thumbnailPath: string,
d38b8281
C
61 views: number,
62 likes: number,
63 dislikes: number,
92fb909c 64 nsfw: boolean
501bc6c2 65 }) {
df98563e
C
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
4fd8aa32 89
df98563e 90 this.by = Video.createByString(hash.author, hash.podHost)
501bc6c2
C
91 }
92
df98563e
C
93 isRemovableBy (user) {
94 return user && this.isLocal === true && (this.author === user.username || user.isAdmin() === true)
198b205c
GS
95 }
96
df98563e
C
97 isBlackistableBy (user) {
98 return user && user.isAdmin() === true && this.isLocal === false
501bc6c2 99 }
92fb909c 100
df98563e
C
101 isUpdatableBy (user) {
102 return user && this.isLocal === true && user.username === this.author
9eee32fc
C
103 }
104
df98563e 105 isVideoNSFWForUser (user: User) {
92fb909c 106 // If the video is NSFW and the user is not logged in, or the user does not want to display NSFW videos...
df98563e 107 return (this.nsfw && (!user || user.displayNSFW === false))
92fb909c 108 }
d8e689b8 109
df98563e 110 patch (values: Object) {
d8e689b8 111 Object.keys(values).forEach((key) => {
df98563e
C
112 this[key] = values[key]
113 })
d8e689b8
C
114 }
115
df98563e 116 toJSON () {
d8e689b8
C
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
df98563e 136 }
d8e689b8 137 }
501bc6c2 138}