aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/angular/videos/video.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/angular/videos/video.ts')
-rw-r--r--client/angular/videos/video.ts60
1 files changed, 60 insertions, 0 deletions
diff --git a/client/angular/videos/video.ts b/client/angular/videos/video.ts
new file mode 100644
index 000000000..32ff64eb3
--- /dev/null
+++ b/client/angular/videos/video.ts
@@ -0,0 +1,60 @@
1export class Video {
2 id: string;
3 name: string;
4 description: string;
5 magnetUri: string;
6 podUrl: string;
7 isLocal: boolean;
8 thumbnailPath: string;
9 author: string;
10 createdDate: Date;
11 by: string;
12 duration: string;
13
14 constructor(hash: {
15 id: string,
16 name: string,
17 description: string,
18 magnetUri: string,
19 podUrl: string,
20 isLocal: boolean,
21 thumbnailPath: string,
22 author: string,
23 createdDate: string,
24 duration: number;
25 }) {
26 this.id = hash.id;
27 this.name = hash.name;
28 this.description = hash.description;
29 this.magnetUri = hash.magnetUri;
30 this.podUrl = hash.podUrl;
31 this.isLocal = hash.isLocal;
32 this.thumbnailPath = hash.thumbnailPath;
33 this.author = hash.author;
34 this.createdDate = new Date(hash.createdDate);
35 this.duration = Video.createDurationString(hash.duration);
36 this.by = Video.createByString(hash.author, hash.podUrl);
37 }
38
39 isRemovableBy(user): boolean {
40 return this.isLocal === true && user && this.author === user.username;
41 }
42
43 private static createDurationString(duration: number): string {
44 const minutes = Math.floor(duration / 60);
45 const seconds = duration % 60;
46 const minutes_padding = minutes >= 10 ? '' : '0';
47 const seconds_padding = seconds >= 10 ? '' : '0'
48
49 return minutes_padding + minutes.toString() + ':' + seconds_padding + seconds.toString();
50 }
51
52 private static createByString(author: string, podUrl: string): string {
53 let [ host, port ] = podUrl.replace(/^https?:\/\//, '').split(':');
54
55 if (port === '80' || port === '443') port = '';
56 else port = ':' + port;
57
58 return author + '@' + host + port;
59 }
60}