]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/videos/shared/video.model.ts
f135ca707e77f795214bb22f3ee9dd1a3275f882
[github/Chocobozzz/PeerTube.git] / client / src / app / videos / shared / video.model.ts
1 import { User } from '../../shared';
2
3 export class Video {
4 author: string;
5 by: string;
6 createdAt: Date;
7 categoryLabel: string;
8 licenceLabel: string;
9 languageLabel: string;
10 description: string;
11 duration: string;
12 id: string;
13 isLocal: boolean;
14 magnetUri: string;
15 name: string;
16 podHost: string;
17 tags: string[];
18 thumbnailPath: string;
19 views: number;
20 likes: number;
21 dislikes: number;
22 nsfw: boolean;
23
24 private static createByString(author: string, podHost: string) {
25 return author + '@' + podHost;
26 }
27
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
37 constructor(hash: {
38 author: string,
39 createdAt: string,
40 categoryLabel: string,
41 licenceLabel: string,
42 languageLabel: string;
43 description: string,
44 duration: number;
45 id: string,
46 isLocal: boolean,
47 magnetUri: string,
48 name: string,
49 podHost: string,
50 tags: string[],
51 thumbnailPath: string,
52 views: number,
53 likes: number,
54 dislikes: number,
55 nsfw: boolean
56 }) {
57 this.author = hash.author;
58 this.createdAt = new Date(hash.createdAt);
59 this.categoryLabel = hash.categoryLabel;
60 this.licenceLabel = hash.licenceLabel;
61 this.languageLabel = hash.languageLabel;
62 this.description = hash.description;
63 this.duration = Video.createDurationString(hash.duration);
64 this.id = hash.id;
65 this.isLocal = hash.isLocal;
66 this.magnetUri = hash.magnetUri;
67 this.name = hash.name;
68 this.podHost = hash.podHost;
69 this.tags = hash.tags;
70 this.thumbnailPath = hash.thumbnailPath;
71 this.views = hash.views;
72 this.likes = hash.likes;
73 this.dislikes = hash.dislikes;
74 this.nsfw = hash.nsfw;
75
76 this.by = Video.createByString(hash.author, hash.podHost);
77 }
78
79 isRemovableBy(user: User) {
80 return this.isLocal === true && user && this.author === user.username;
81 }
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 }
87 }