]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/videos/shared/video.model.ts
65417f751e6c3b67d2246ca31b1ed275f437b451
[github/Chocobozzz/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 podUrl: string;
12 tags: string[];
13 thumbnailPath: string;
14
15 private static createByString(author: string, podUrl: string) {
16 let [ host, port ] = podUrl.replace(/^https?:\/\//, '').split(':');
17
18 if (port === '80' || port === '443') {
19 port = '';
20 } else {
21 port = ':' + port;
22 }
23
24 return author + '@' + host + port;
25 }
26
27 private static createDurationString(duration: number) {
28 const minutes = Math.floor(duration / 60);
29 const seconds = duration % 60;
30 const minutes_padding = minutes >= 10 ? '' : '0';
31 const seconds_padding = seconds >= 10 ? '' : '0';
32
33 return minutes_padding + minutes.toString() + ':' + seconds_padding + seconds.toString();
34 }
35
36 constructor(hash: {
37 author: string,
38 createdDate: string,
39 description: string,
40 duration: number;
41 id: string,
42 isLocal: boolean,
43 magnetUri: string,
44 name: string,
45 podUrl: string,
46 tags: string[],
47 thumbnailPath: string
48 }) {
49 this.author = hash.author;
50 this.createdDate = new Date(hash.createdDate);
51 this.description = hash.description;
52 this.duration = Video.createDurationString(hash.duration);
53 this.id = hash.id;
54 this.isLocal = hash.isLocal;
55 this.magnetUri = hash.magnetUri;
56 this.name = hash.name;
57 this.podUrl = hash.podUrl;
58 this.tags = hash.tags;
59 this.thumbnailPath = hash.thumbnailPath;
60
61 this.by = Video.createByString(hash.author, hash.podUrl);
62 }
63
64 isRemovableBy(user) {
65 return this.isLocal === true && user && this.author === user.username;
66 }
67 }