aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/videos/shared/video.model.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/videos/shared/video.model.ts')
-rw-r--r--client/src/app/videos/shared/video.model.ts88
1 files changed, 2 insertions, 86 deletions
diff --git a/client/src/app/videos/shared/video.model.ts b/client/src/app/videos/shared/video.model.ts
index 6e8dfaa6f..7f2871032 100644
--- a/client/src/app/videos/shared/video.model.ts
+++ b/client/src/app/videos/shared/video.model.ts
@@ -1,6 +1,5 @@
1import { Video as VideoServerModel, VideoFile } from '../../../../../shared' 1import { Video as VideoServerModel } from '../../../../../shared'
2import { User } from '../../shared' 2import { User } from '../../shared'
3import { VideoResolution } from '../../../../../shared/models/videos/video-resolution.enum'
4 3
5export class Video implements VideoServerModel { 4export class Video implements VideoServerModel {
6 author: string 5 author: string
@@ -32,7 +31,6 @@ export class Video implements VideoServerModel {
32 likes: number 31 likes: number
33 dislikes: number 32 dislikes: number
34 nsfw: boolean 33 nsfw: boolean
35 files: VideoFile[]
36 34
37 private static createByString (author: string, podHost: string) { 35 private static createByString (author: string, podHost: string) {
38 return author + '@' + podHost 36 return author + '@' + podHost
@@ -47,32 +45,7 @@ export class Video implements VideoServerModel {
47 return minutesPadding + minutes.toString() + ':' + secondsPadding + seconds.toString() 45 return minutesPadding + minutes.toString() + ':' + secondsPadding + seconds.toString()
48 } 46 }
49 47
50 constructor (hash: { 48 constructor (hash: VideoServerModel) {
51 author: string,
52 createdAt: Date | string,
53 categoryLabel: string,
54 category: number,
55 licenceLabel: string,
56 licence: number,
57 languageLabel: string
58 language: number
59 description: string,
60 duration: number
61 id: number,
62 uuid: string,
63 isLocal: boolean,
64 name: string,
65 podHost: string,
66 tags: string[],
67 thumbnailPath: string,
68 previewPath: string,
69 embedPath: string,
70 views: number,
71 likes: number,
72 dislikes: number,
73 nsfw: boolean,
74 files: VideoFile[]
75 }) {
76 let absoluteAPIUrl = API_URL 49 let absoluteAPIUrl = API_URL
77 if (!absoluteAPIUrl) { 50 if (!absoluteAPIUrl) {
78 // The API is on the same domain 51 // The API is on the same domain
@@ -106,69 +79,12 @@ export class Video implements VideoServerModel {
106 this.likes = hash.likes 79 this.likes = hash.likes
107 this.dislikes = hash.dislikes 80 this.dislikes = hash.dislikes
108 this.nsfw = hash.nsfw 81 this.nsfw = hash.nsfw
109 this.files = hash.files
110 82
111 this.by = Video.createByString(hash.author, hash.podHost) 83 this.by = Video.createByString(hash.author, hash.podHost)
112 } 84 }
113 85
114 isRemovableBy (user) {
115 return user && this.isLocal === true && (this.author === user.username || user.isAdmin() === true)
116 }
117
118 isBlackistableBy (user) {
119 return user && user.isAdmin() === true && this.isLocal === false
120 }
121
122 isUpdatableBy (user) {
123 return user && this.isLocal === true && user.username === this.author
124 }
125
126 isVideoNSFWForUser (user: User) { 86 isVideoNSFWForUser (user: User) {
127 // If the video is NSFW and the user is not logged in, or the user does not want to display NSFW videos... 87 // If the video is NSFW and the user is not logged in, or the user does not want to display NSFW videos...
128 return (this.nsfw && (!user || user.displayNSFW === false)) 88 return (this.nsfw && (!user || user.displayNSFW === false))
129 } 89 }
130
131 getAppropriateMagnetUri (actualDownloadSpeed = 0) {
132 if (this.files === undefined || this.files.length === 0) return ''
133 if (this.files.length === 1) return this.files[0].magnetUri
134
135 // Find first video that is good for our download speed (remember they are sorted)
136 let betterResolutionFile = this.files.find(f => actualDownloadSpeed > (f.size / this.duration))
137
138 // If the download speed is too bad, return the lowest resolution we have
139 if (betterResolutionFile === undefined) {
140 betterResolutionFile = this.files.find(f => f.resolution === VideoResolution.H_240P)
141 }
142
143 return betterResolutionFile.magnetUri
144 }
145
146 patch (values: Object) {
147 Object.keys(values).forEach((key) => {
148 this[key] = values[key]
149 })
150 }
151
152 toJSON () {
153 return {
154 author: this.author,
155 createdAt: this.createdAt,
156 category: this.category,
157 licence: this.licence,
158 language: this.language,
159 description: this.description,
160 duration: this.duration,
161 id: this.id,
162 isLocal: this.isLocal,
163 name: this.name,
164 podHost: this.podHost,
165 tags: this.tags,
166 thumbnailPath: this.thumbnailPath,
167 views: this.views,
168 likes: this.likes,
169 dislikes: this.dislikes,
170 nsfw: this.nsfw,
171 files: this.files
172 }
173 }
174} 90}