]>
Commit | Line | Data |
---|---|---|
501bc6c2 | 1 | export class Video { |
4fd8aa32 C |
2 | author: string; |
3 | by: string; | |
4 | createdDate: Date; | |
501bc6c2 | 5 | description: string; |
4fd8aa32 C |
6 | duration: string; |
7 | id: string; | |
8 | isLocal: boolean; | |
501bc6c2 | 9 | magnetUri: string; |
4fd8aa32 | 10 | name: string; |
501bc6c2 | 11 | podUrl: string; |
00a44645 | 12 | tags: string[]; |
501bc6c2 | 13 | thumbnailPath: string; |
aff038cd | 14 | |
ccf6ed16 | 15 | private static createByString(author: string, podUrl: string) { |
aff038cd C |
16 | let [ host, port ] = podUrl.replace(/^https?:\/\//, '').split(':'); |
17 | ||
18 | if (port === '80' || port === '443') { | |
19 | port = ''; | |
20 | } else { | |
21 | port = ':' + port; | |
22 | } | |
23 | ||
24 | return author + '@' + host + port; | |
25 | } | |
26 | ||
4fd8aa32 C |
27 | private static createDurationString(duration: number) { |
28 | const minutes = Math.floor(duration / 60); | |
29 | const seconds = duration % 60; | |
30 | const minutes_padding = minutes >= 10 ? '' : '0'; | |
31 | const seconds_padding = seconds >= 10 ? '' : '0'; | |
32 | ||
33 | return minutes_padding + minutes.toString() + ':' + seconds_padding + seconds.toString(); | |
34 | } | |
35 | ||
501bc6c2 | 36 | constructor(hash: { |
501bc6c2 C |
37 | author: string, |
38 | createdDate: string, | |
4fd8aa32 | 39 | description: string, |
501bc6c2 | 40 | duration: number; |
4fd8aa32 C |
41 | id: string, |
42 | isLocal: boolean, | |
43 | magnetUri: string, | |
44 | name: string, | |
45 | podUrl: string, | |
00a44645 | 46 | tags: string[], |
4fd8aa32 | 47 | thumbnailPath: string |
501bc6c2 | 48 | }) { |
4fd8aa32 C |
49 | this.author = hash.author; |
50 | this.createdDate = new Date(hash.createdDate); | |
501bc6c2 | 51 | this.description = hash.description; |
4fd8aa32 C |
52 | this.duration = Video.createDurationString(hash.duration); |
53 | this.id = hash.id; | |
54 | this.isLocal = hash.isLocal; | |
501bc6c2 | 55 | this.magnetUri = hash.magnetUri; |
4fd8aa32 | 56 | this.name = hash.name; |
501bc6c2 | 57 | this.podUrl = hash.podUrl; |
00a44645 | 58 | this.tags = hash.tags; |
501bc6c2 | 59 | this.thumbnailPath = hash.thumbnailPath; |
4fd8aa32 | 60 | |
501bc6c2 C |
61 | this.by = Video.createByString(hash.author, hash.podUrl); |
62 | } | |
63 | ||
ccf6ed16 | 64 | isRemovableBy(user) { |
501bc6c2 C |
65 | return this.isLocal === true && user && this.author === user.username; |
66 | } | |
501bc6c2 | 67 | } |