]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/videos/shared/video.model.ts
Client: add more informations to watch video view
[github/Chocobozzz/PeerTube.git] / client / src / app / videos / shared / video.model.ts
1 export class Video {
2 author: string;
3 by: string;
4 createdDate: Date;
5 description: string;
6 duration: string;
7 id: string;
8 isLocal: boolean;
9 magnetUri: string;
10 name: string;
11 podUrl: string;
12 tags: string[];
13 thumbnailPath: string;
14
15 private static createByString(author: string, podUrl: string) {
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
25 return author + '@' + host + port;
26 }
27
28 private static createDurationString(duration: number) {
29 const minutes = Math.floor(duration / 60);
30 const seconds = duration % 60;
31 const minutes_padding = minutes >= 10 ? '' : '0';
32 const seconds_padding = seconds >= 10 ? '' : '0';
33
34 return minutes_padding + minutes.toString() + ':' + seconds_padding + seconds.toString();
35 }
36
37 constructor(hash: {
38 author: string,
39 createdDate: string,
40 description: string,
41 duration: number;
42 id: string,
43 isLocal: boolean,
44 magnetUri: string,
45 name: string,
46 podUrl: string,
47 tags: string[],
48 thumbnailPath: string
49 }) {
50 this.author = hash.author;
51 this.createdDate = new Date(hash.createdDate);
52 this.description = hash.description;
53 this.duration = Video.createDurationString(hash.duration);
54 this.id = hash.id;
55 this.isLocal = hash.isLocal;
56 this.magnetUri = hash.magnetUri;
57 this.name = hash.name;
58 this.podUrl = hash.podUrl;
59 this.tags = hash.tags;
60 this.thumbnailPath = hash.thumbnailPath;
61
62 this.by = Video.createByString(hash.author, hash.podUrl);
63 }
64
65 isRemovableBy(user) {
66 return this.isLocal === true && user && this.author === user.username;
67 }
68 }