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