diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-10-25 16:43:19 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-10-26 09:11:38 +0200 |
commit | 404b54e14f6623c1644a8c87ca22f4bab98d5484 (patch) | |
tree | 5fbe6cb637f35abae08e4c98a537447cbf4607d6 /client/src/app/videos/shared/video-details.model.ts | |
parent | f5028693a896a3076dd286ac0030e3d8f78f5ebf (diff) | |
download | PeerTube-404b54e14f6623c1644a8c87ca22f4bab98d5484.tar.gz PeerTube-404b54e14f6623c1644a8c87ca22f4bab98d5484.tar.zst PeerTube-404b54e14f6623c1644a8c87ca22f4bab98d5484.zip |
Adapt client with video channels
Diffstat (limited to 'client/src/app/videos/shared/video-details.model.ts')
-rw-r--r-- | client/src/app/videos/shared/video-details.model.ts | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/client/src/app/videos/shared/video-details.model.ts b/client/src/app/videos/shared/video-details.model.ts new file mode 100644 index 000000000..e99a5ce2e --- /dev/null +++ b/client/src/app/videos/shared/video-details.model.ts | |||
@@ -0,0 +1,75 @@ | |||
1 | import { Video } from './video.model' | ||
2 | import { | ||
3 | VideoDetails as VideoDetailsServerModel, | ||
4 | VideoFile, | ||
5 | VideoChannel, | ||
6 | VideoResolution | ||
7 | } from '../../../../../shared' | ||
8 | |||
9 | export class VideoDetails extends Video implements VideoDetailsServerModel { | ||
10 | author: string | ||
11 | by: string | ||
12 | createdAt: Date | ||
13 | updatedAt: Date | ||
14 | categoryLabel: string | ||
15 | category: number | ||
16 | licenceLabel: string | ||
17 | licence: number | ||
18 | languageLabel: string | ||
19 | language: number | ||
20 | description: string | ||
21 | duration: number | ||
22 | durationLabel: string | ||
23 | id: number | ||
24 | uuid: string | ||
25 | isLocal: boolean | ||
26 | name: string | ||
27 | podHost: string | ||
28 | tags: string[] | ||
29 | thumbnailPath: string | ||
30 | thumbnailUrl: string | ||
31 | previewPath: string | ||
32 | previewUrl: string | ||
33 | embedPath: string | ||
34 | embedUrl: string | ||
35 | views: number | ||
36 | likes: number | ||
37 | dislikes: number | ||
38 | nsfw: boolean | ||
39 | files: VideoFile[] | ||
40 | channel: VideoChannel | ||
41 | |||
42 | constructor (hash: VideoDetailsServerModel) { | ||
43 | super(hash) | ||
44 | |||
45 | this.files = hash.files | ||
46 | this.channel = hash.channel | ||
47 | } | ||
48 | |||
49 | getAppropriateMagnetUri (actualDownloadSpeed = 0) { | ||
50 | if (this.files === undefined || this.files.length === 0) return '' | ||
51 | if (this.files.length === 1) return this.files[0].magnetUri | ||
52 | |||
53 | // Find first video that is good for our download speed (remember they are sorted) | ||
54 | let betterResolutionFile = this.files.find(f => actualDownloadSpeed > (f.size / this.duration)) | ||
55 | |||
56 | // If the download speed is too bad, return the lowest resolution we have | ||
57 | if (betterResolutionFile === undefined) { | ||
58 | betterResolutionFile = this.files.find(f => f.resolution === VideoResolution.H_240P) | ||
59 | } | ||
60 | |||
61 | return betterResolutionFile.magnetUri | ||
62 | } | ||
63 | |||
64 | isRemovableBy (user) { | ||
65 | return user && this.isLocal === true && (this.author === user.username || user.isAdmin() === true) | ||
66 | } | ||
67 | |||
68 | isBlackistableBy (user) { | ||
69 | return user && user.isAdmin() === true && this.isLocal === false | ||
70 | } | ||
71 | |||
72 | isUpdatableBy (user) { | ||
73 | return user && this.isLocal === true && user.username === this.author | ||
74 | } | ||
75 | } | ||