]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/videos/shared/video.model.ts
Client: add views information and sort
[github/Chocobozzz/PeerTube.git] / client / src / app / videos / shared / video.model.ts
1 export class Video {
2 author: string;
3 by: string;
4 createdAt: 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 views: number;
15
16 private static createByString(author: string, podHost: string) {
17 return author + '@' + podHost;
18 }
19
20 private static createDurationString(duration: number) {
21 const minutes = Math.floor(duration / 60);
22 const seconds = duration % 60;
23 const minutes_padding = minutes >= 10 ? '' : '0';
24 const seconds_padding = seconds >= 10 ? '' : '0';
25
26 return minutes_padding + minutes.toString() + ':' + seconds_padding + seconds.toString();
27 }
28
29 constructor(hash: {
30 author: string,
31 createdAt: string,
32 description: string,
33 duration: number;
34 id: string,
35 isLocal: boolean,
36 magnetUri: string,
37 name: string,
38 podHost: string,
39 tags: string[],
40 thumbnailPath: string,
41 views: number
42 }) {
43 this.author = hash.author;
44 this.createdAt = new Date(hash.createdAt);
45 this.description = hash.description;
46 this.duration = Video.createDurationString(hash.duration);
47 this.id = hash.id;
48 this.isLocal = hash.isLocal;
49 this.magnetUri = hash.magnetUri;
50 this.name = hash.name;
51 this.podHost = hash.podHost;
52 this.tags = hash.tags;
53 this.thumbnailPath = hash.thumbnailPath;
54 this.views = hash.views;
55
56 this.by = Video.createByString(hash.author, hash.podHost);
57 }
58
59 isRemovableBy(user) {
60 return this.isLocal === true && user && this.author === user.username;
61 }
62 }