b51a0e9de4561ecb5de27eff159af436e08241bd
[oweals/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   podHost: string;
12   tags: string[];
13   thumbnailPath: string;
14
15   private static createByString(author: string, podHost: string) {
16     return author + '@' + podHost;
17   }
18
19   private static createDurationString(duration: number) {
20     const minutes = Math.floor(duration / 60);
21     const seconds = duration % 60;
22     const minutes_padding = minutes >= 10 ? '' : '0';
23     const seconds_padding = seconds >= 10 ? '' : '0';
24
25     return minutes_padding + minutes.toString() + ':' + seconds_padding + seconds.toString();
26   }
27
28   constructor(hash: {
29     author: string,
30     createdDate: string,
31     description: string,
32     duration: number;
33     id: string,
34     isLocal: boolean,
35     magnetUri: string,
36     name: string,
37     podHost: string,
38     tags: string[],
39     thumbnailPath: string
40   }) {
41     this.author  = hash.author;
42     this.createdDate = new Date(hash.createdDate);
43     this.description = hash.description;
44     this.duration = Video.createDurationString(hash.duration);
45     this.id = hash.id;
46     this.isLocal = hash.isLocal;
47     this.magnetUri = hash.magnetUri;
48     this.name = hash.name;
49     this.podHost = hash.podHost;
50     this.tags = hash.tags;
51     this.thumbnailPath = hash.thumbnailPath;
52
53     this.by = Video.createByString(hash.author, hash.podHost);
54   }
55
56   isRemovableBy(user) {
57     return this.isLocal === true && user && this.author === user.username;
58   }
59 }