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