]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/app/videos/shared/video.model.ts
Do not prefix private attributes
[github/Chocobozzz/PeerTube.git] / client / app / videos / shared / video.model.ts
CommitLineData
501bc6c2
C
1export class Video {
2 id: string;
3 name: string;
4 description: string;
5 magnetUri: string;
6 podUrl: string;
7 isLocal: boolean;
8 thumbnailPath: string;
9 author: string;
10 createdDate: Date;
11 by: string;
12 duration: string;
13
ccf6ed16 14 private static createDurationString(duration: number) {
aff038cd
C
15 const minutes = Math.floor(duration / 60);
16 const seconds = duration % 60;
17 const minutes_padding = minutes >= 10 ? '' : '0';
18 const seconds_padding = seconds >= 10 ? '' : '0';
19
20 return minutes_padding + minutes.toString() + ':' + seconds_padding + seconds.toString();
21 }
22
ccf6ed16 23 private static createByString(author: string, podUrl: string) {
aff038cd
C
24 let [ host, port ] = podUrl.replace(/^https?:\/\//, '').split(':');
25
26 if (port === '80' || port === '443') {
27 port = '';
28 } else {
29 port = ':' + port;
30 }
31
32 return author + '@' + host + port;
33 }
34
501bc6c2
C
35 constructor(hash: {
36 id: string,
37 name: string,
38 description: string,
39 magnetUri: string,
40 podUrl: string,
41 isLocal: boolean,
42 thumbnailPath: string,
43 author: string,
44 createdDate: string,
45 duration: number;
46 }) {
47 this.id = hash.id;
48 this.name = hash.name;
49 this.description = hash.description;
50 this.magnetUri = hash.magnetUri;
51 this.podUrl = hash.podUrl;
52 this.isLocal = hash.isLocal;
53 this.thumbnailPath = hash.thumbnailPath;
54 this.author = hash.author;
55 this.createdDate = new Date(hash.createdDate);
56 this.duration = Video.createDurationString(hash.duration);
57 this.by = Video.createByString(hash.author, hash.podUrl);
58 }
59
ccf6ed16 60 isRemovableBy(user) {
501bc6c2
C
61 return this.isLocal === true && user && this.author === user.username;
62 }
501bc6c2 63}