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