]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/videos/shared/video.model.ts
b5d96f63a45b91b27eb8b355441d4eec8c2d5234
[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 categoryLabel: string;
6 description: string;
7 duration: string;
8 id: string;
9 isLocal: boolean;
10 magnetUri: string;
11 name: string;
12 podHost: string;
13 tags: string[];
14 thumbnailPath: string;
15 views: number;
16 likes: number;
17 dislikes: number;
18
19 private static createByString(author: string, podHost: string) {
20 return author + '@' + podHost;
21 }
22
23 private static createDurationString(duration: number) {
24 const minutes = Math.floor(duration / 60);
25 const seconds = duration % 60;
26 const minutes_padding = minutes >= 10 ? '' : '0';
27 const seconds_padding = seconds >= 10 ? '' : '0';
28
29 return minutes_padding + minutes.toString() + ':' + seconds_padding + seconds.toString();
30 }
31
32 constructor(hash: {
33 author: string,
34 createdAt: string,
35 categoryLabel: string,
36 description: string,
37 duration: number;
38 id: string,
39 isLocal: boolean,
40 magnetUri: string,
41 name: string,
42 podHost: string,
43 tags: string[],
44 thumbnailPath: string,
45 views: number,
46 likes: number,
47 dislikes: number,
48 }) {
49 this.author = hash.author;
50 this.createdAt = new Date(hash.createdAt);
51 this.categoryLabel = hash.categoryLabel;
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.podHost = hash.podHost;
59 this.tags = hash.tags;
60 this.thumbnailPath = hash.thumbnailPath;
61 this.views = hash.views;
62 this.likes = hash.likes;
63 this.dislikes = hash.dislikes;
64
65 this.by = Video.createByString(hash.author, hash.podHost);
66 }
67
68 isRemovableBy(user) {
69 return this.isLocal === true && user && this.author === user.username;
70 }
71 }