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