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