1
0
Fork 0
peertube/client/app/videos/shared/video.model.ts

65 lines
1.6 KiB
TypeScript
Raw Normal View History

export class Video {
2016-05-27 11:49:18 -04:00
author: string;
by: string;
createdDate: Date;
description: string;
2016-05-27 11:49:18 -04:00
duration: string;
id: string;
isLocal: boolean;
magnetUri: string;
2016-05-27 11:49:18 -04:00
name: string;
podUrl: string;
thumbnailPath: string;
2016-05-23 06:15:03 -04:00
2016-05-27 11:25:52 -04:00
private static createByString(author: string, podUrl: string) {
2016-05-23 06:15:03 -04:00
let [ host, port ] = podUrl.replace(/^https?:\/\//, '').split(':');
if (port === '80' || port === '443') {
port = '';
} else {
port = ':' + port;
}
return author + '@' + host + port;
}
2016-05-27 11:49:18 -04:00
private static createDurationString(duration: number) {
const minutes = Math.floor(duration / 60);
const seconds = duration % 60;
const minutes_padding = minutes >= 10 ? '' : '0';
const seconds_padding = seconds >= 10 ? '' : '0';
return minutes_padding + minutes.toString() + ':' + seconds_padding + seconds.toString();
}
constructor(hash: {
author: string,
createdDate: string,
2016-05-27 11:49:18 -04:00
description: string,
duration: number;
2016-05-27 11:49:18 -04:00
id: string,
isLocal: boolean,
magnetUri: string,
name: string,
podUrl: string,
thumbnailPath: string
}) {
2016-05-27 11:49:18 -04:00
this.author = hash.author;
this.createdDate = new Date(hash.createdDate);
this.description = hash.description;
2016-05-27 11:49:18 -04:00
this.duration = Video.createDurationString(hash.duration);
this.id = hash.id;
this.isLocal = hash.isLocal;
this.magnetUri = hash.magnetUri;
2016-05-27 11:49:18 -04:00
this.name = hash.name;
this.podUrl = hash.podUrl;
this.thumbnailPath = hash.thumbnailPath;
2016-05-27 11:49:18 -04:00
this.by = Video.createByString(hash.author, hash.podUrl);
}
2016-05-27 11:25:52 -04:00
isRemovableBy(user) {
return this.isLocal === true && user && this.author === user.username;
}
}