aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/app/videos/shared/video.model.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-05-27 16:23:10 +0200
committerChocobozzz <florian.bigard@gmail.com>2016-05-27 16:23:10 +0200
commit41a2aee38cf812510010da09de9bae53590ec119 (patch)
tree79d55d6ae0ef6f66ccb88890cf1ef1946dc65fb4 /client/app/videos/shared/video.model.ts
parent157cb9c9713e08ff70078660a32dd77ecb87eabc (diff)
downloadPeerTube-41a2aee38cf812510010da09de9bae53590ec119.tar.gz
PeerTube-41a2aee38cf812510010da09de9bae53590ec119.tar.zst
PeerTube-41a2aee38cf812510010da09de9bae53590ec119.zip
Follow the angular styleguide for the directories structure
Diffstat (limited to 'client/app/videos/shared/video.model.ts')
-rw-r--r--client/app/videos/shared/video.model.ts63
1 files changed, 63 insertions, 0 deletions
diff --git a/client/app/videos/shared/video.model.ts b/client/app/videos/shared/video.model.ts
new file mode 100644
index 000000000..eec537c9e
--- /dev/null
+++ b/client/app/videos/shared/video.model.ts
@@ -0,0 +1,63 @@
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 private static createDurationString(duration: number): string {
15 const minutes = Math.floor(duration / 60);
16 const seconds = duration % 60;
17 const minutes_padding = minutes >= 10 ? '' : '0';
18 const seconds_padding = seconds >= 10 ? '' : '0';
19
20 return minutes_padding + minutes.toString() + ':' + seconds_padding + seconds.toString();
21 }
22
23 private static createByString(author: string, podUrl: string): string {
24 let [ host, port ] = podUrl.replace(/^https?:\/\//, '').split(':');
25
26 if (port === '80' || port === '443') {
27 port = '';
28 } else {
29 port = ':' + port;
30 }
31
32 return author + '@' + host + port;
33 }
34
35 constructor(hash: {
36 id: string,
37 name: string,
38 description: string,
39 magnetUri: string,
40 podUrl: string,
41 isLocal: boolean,
42 thumbnailPath: string,
43 author: string,
44 createdDate: string,
45 duration: number;
46 }) {
47 this.id = hash.id;
48 this.name = hash.name;
49 this.description = hash.description;
50 this.magnetUri = hash.magnetUri;
51 this.podUrl = hash.podUrl;
52 this.isLocal = hash.isLocal;
53 this.thumbnailPath = hash.thumbnailPath;
54 this.author = hash.author;
55 this.createdDate = new Date(hash.createdDate);
56 this.duration = Video.createDurationString(hash.duration);
57 this.by = Video.createByString(hash.author, hash.podUrl);
58 }
59
60 isRemovableBy(user): boolean {
61 return this.isLocal === true && user && this.author === user.username;
62 }
63}