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