]>
Commit | Line | Data |
---|---|---|
404b54e1 | 1 | import { |
47564bbe C |
2 | UserRight, VideoChannel, VideoDetails as VideoDetailsServerModel, VideoFile, VideoPrivacy, |
3 | VideoResolution | |
404b54e1 | 4 | } from '../../../../../shared' |
47564bbe C |
5 | import { Account } from '../../../../../shared/models/actors' |
6 | import { AuthUser } from '../../core' | |
7 | import { Video } from '../../shared/video/video.model' | |
404b54e1 C |
8 | |
9 | export class VideoDetails extends Video implements VideoDetailsServerModel { | |
b1fa3eba | 10 | accountName: string |
404b54e1 C |
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 | |
60862425 | 27 | serverHost: string |
404b54e1 C |
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 | |
2de96f4d | 39 | descriptionPath: string |
404b54e1 C |
40 | files: VideoFile[] |
41 | channel: VideoChannel | |
fd45e8f4 C |
42 | privacy: VideoPrivacy |
43 | privacyLabel: string | |
b1fa3eba | 44 | account: Account |
6a9e1d42 C |
45 | likesPercent: number |
46 | dislikesPercent: number | |
47564bbe | 47 | commentsEnabled: boolean |
404b54e1 C |
48 | |
49 | constructor (hash: VideoDetailsServerModel) { | |
50 | super(hash) | |
51 | ||
fd45e8f4 C |
52 | this.privacy = hash.privacy |
53 | this.privacyLabel = hash.privacyLabel | |
2de96f4d | 54 | this.descriptionPath = hash.descriptionPath |
404b54e1 C |
55 | this.files = hash.files |
56 | this.channel = hash.channel | |
b1fa3eba | 57 | this.account = hash.account |
d48ff09d | 58 | this.tags = hash.tags |
47564bbe | 59 | this.commentsEnabled = hash.commentsEnabled |
6a9e1d42 C |
60 | |
61 | this.likesPercent = (this.likes / (this.likes + this.dislikes)) * 100 | |
62 | this.dislikesPercent = (this.dislikes / (this.likes + this.dislikes)) * 100 | |
404b54e1 C |
63 | } |
64 | ||
65 | getAppropriateMagnetUri (actualDownloadSpeed = 0) { | |
66 | if (this.files === undefined || this.files.length === 0) return '' | |
67 | if (this.files.length === 1) return this.files[0].magnetUri | |
68 | ||
69 | // Find first video that is good for our download speed (remember they are sorted) | |
70 | let betterResolutionFile = this.files.find(f => actualDownloadSpeed > (f.size / this.duration)) | |
71 | ||
72 | // If the download speed is too bad, return the lowest resolution we have | |
73 | if (betterResolutionFile === undefined) { | |
74 | betterResolutionFile = this.files.find(f => f.resolution === VideoResolution.H_240P) | |
75 | } | |
76 | ||
77 | return betterResolutionFile.magnetUri | |
78 | } | |
79 | ||
954605a8 | 80 | isRemovableBy (user: AuthUser) { |
b1fa3eba | 81 | return user && this.isLocal === true && (this.accountName === user.username || user.hasRight(UserRight.REMOVE_ANY_VIDEO)) |
404b54e1 C |
82 | } |
83 | ||
954605a8 C |
84 | isBlackistableBy (user: AuthUser) { |
85 | return user && user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) === true && this.isLocal === false | |
404b54e1 C |
86 | } |
87 | ||
954605a8 | 88 | isUpdatableBy (user: AuthUser) { |
b1fa3eba | 89 | return user && this.isLocal === true && user.username === this.accountName |
404b54e1 C |
90 | } |
91 | } |