]>
Commit | Line | Data |
---|---|---|
404b54e1 | 1 | import { Video } from './video.model' |
954605a8 | 2 | import { AuthUser } from '../../core' |
404b54e1 C |
3 | import { |
4 | VideoDetails as VideoDetailsServerModel, | |
5 | VideoFile, | |
6 | VideoChannel, | |
954605a8 C |
7 | VideoResolution, |
8 | UserRight | |
404b54e1 C |
9 | } from '../../../../../shared' |
10 | ||
11 | export class VideoDetails extends Video implements VideoDetailsServerModel { | |
12 | author: string | |
13 | by: string | |
14 | createdAt: Date | |
15 | updatedAt: Date | |
16 | categoryLabel: string | |
17 | category: number | |
18 | licenceLabel: string | |
19 | licence: number | |
20 | languageLabel: string | |
21 | language: number | |
22 | description: string | |
23 | duration: number | |
24 | durationLabel: string | |
25 | id: number | |
26 | uuid: string | |
27 | isLocal: boolean | |
28 | name: string | |
29 | podHost: string | |
30 | tags: string[] | |
31 | thumbnailPath: string | |
32 | thumbnailUrl: string | |
33 | previewPath: string | |
34 | previewUrl: string | |
35 | embedPath: string | |
36 | embedUrl: string | |
37 | views: number | |
38 | likes: number | |
39 | dislikes: number | |
40 | nsfw: boolean | |
41 | files: VideoFile[] | |
42 | channel: VideoChannel | |
43 | ||
44 | constructor (hash: VideoDetailsServerModel) { | |
45 | super(hash) | |
46 | ||
47 | this.files = hash.files | |
48 | this.channel = hash.channel | |
49 | } | |
50 | ||
51 | getAppropriateMagnetUri (actualDownloadSpeed = 0) { | |
52 | if (this.files === undefined || this.files.length === 0) return '' | |
53 | if (this.files.length === 1) return this.files[0].magnetUri | |
54 | ||
55 | // Find first video that is good for our download speed (remember they are sorted) | |
56 | let betterResolutionFile = this.files.find(f => actualDownloadSpeed > (f.size / this.duration)) | |
57 | ||
58 | // If the download speed is too bad, return the lowest resolution we have | |
59 | if (betterResolutionFile === undefined) { | |
60 | betterResolutionFile = this.files.find(f => f.resolution === VideoResolution.H_240P) | |
61 | } | |
62 | ||
63 | return betterResolutionFile.magnetUri | |
64 | } | |
65 | ||
954605a8 C |
66 | isRemovableBy (user: AuthUser) { |
67 | return user && this.isLocal === true && (this.author === user.username || user.hasRight(UserRight.REMOVE_ANY_VIDEO)) | |
404b54e1 C |
68 | } |
69 | ||
954605a8 C |
70 | isBlackistableBy (user: AuthUser) { |
71 | return user && user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) === true && this.isLocal === false | |
404b54e1 C |
72 | } |
73 | ||
954605a8 | 74 | isUpdatableBy (user: AuthUser) { |
404b54e1 C |
75 | return user && this.isLocal === true && user.username === this.author |
76 | } | |
77 | } |