]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/videos/shared/video.model.ts
Client: support signup
[github/Chocobozzz/PeerTube.git] / client / src / app / videos / shared / video.model.ts
CommitLineData
92fb909c
C
1import { User } from '../../shared';
2
501bc6c2 3export class Video {
4fd8aa32
C
4 author: string;
5 by: string;
feb4bdfd 6 createdAt: Date;
6e07c3de 7 categoryLabel: string;
d07137b9 8 licenceLabel: string;
db216afd 9 languageLabel: string;
501bc6c2 10 description: string;
4fd8aa32
C
11 duration: string;
12 id: string;
13 isLocal: boolean;
501bc6c2 14 magnetUri: string;
4fd8aa32 15 name: string;
49abbbbe 16 podHost: string;
00a44645 17 tags: string[];
501bc6c2 18 thumbnailPath: string;
05a9feaa 19 views: number;
d38b8281
C
20 likes: number;
21 dislikes: number;
92fb909c 22 nsfw: boolean;
aff038cd 23
49abbbbe
C
24 private static createByString(author: string, podHost: string) {
25 return author + '@' + podHost;
aff038cd
C
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 38 author: string,
feb4bdfd 39 createdAt: string,
6e07c3de 40 categoryLabel: string,
d07137b9 41 licenceLabel: string,
db216afd 42 languageLabel: string;
4fd8aa32 43 description: string,
501bc6c2 44 duration: number;
4fd8aa32
C
45 id: string,
46 isLocal: boolean,
47 magnetUri: string,
48 name: string,
49abbbbe 49 podHost: string,
00a44645 50 tags: string[],
05a9feaa 51 thumbnailPath: string,
d38b8281
C
52 views: number,
53 likes: number,
54 dislikes: number,
92fb909c 55 nsfw: boolean
501bc6c2 56 }) {
4fd8aa32 57 this.author = hash.author;
feb4bdfd 58 this.createdAt = new Date(hash.createdAt);
6e07c3de 59 this.categoryLabel = hash.categoryLabel;
d07137b9 60 this.licenceLabel = hash.licenceLabel;
db216afd 61 this.languageLabel = hash.languageLabel;
501bc6c2 62 this.description = hash.description;
4fd8aa32
C
63 this.duration = Video.createDurationString(hash.duration);
64 this.id = hash.id;
65 this.isLocal = hash.isLocal;
501bc6c2 66 this.magnetUri = hash.magnetUri;
4fd8aa32 67 this.name = hash.name;
49abbbbe 68 this.podHost = hash.podHost;
00a44645 69 this.tags = hash.tags;
501bc6c2 70 this.thumbnailPath = hash.thumbnailPath;
05a9feaa 71 this.views = hash.views;
d38b8281
C
72 this.likes = hash.likes;
73 this.dislikes = hash.dislikes;
92fb909c 74 this.nsfw = hash.nsfw;
4fd8aa32 75
49abbbbe 76 this.by = Video.createByString(hash.author, hash.podHost);
501bc6c2
C
77 }
78
92fb909c 79 isRemovableBy(user: User) {
501bc6c2
C
80 return this.isLocal === true && user && this.author === user.username;
81 }
92fb909c
C
82
83 isVideoNSFWForUser(user: User) {
84 // If the video is NSFW and the user is not logged in, or the user does not want to display NSFW videos...
85 return (this.nsfw && (!user || user.displayNSFW === false));
86 }
501bc6c2 87}