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