]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/videos/shared/video.model.ts
Client: Handle NSFW video
[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 description: string;
10 duration: string;
11 id: string;
12 isLocal: boolean;
13 magnetUri: string;
14 name: string;
15 podHost: string;
16 tags: string[];
17 thumbnailPath: string;
18 views: number;
19 likes: number;
20 dislikes: number;
21 nsfw: boolean;
22
23 private static createByString(author: string, podHost: string) {
24 return author + '@' + podHost;
25 }
26
27 private static createDurationString(duration: number) {
28 const minutes = Math.floor(duration / 60);
29 const seconds = duration % 60;
30 const minutes_padding = minutes >= 10 ? '' : '0';
31 const seconds_padding = seconds >= 10 ? '' : '0';
32
33 return minutes_padding + minutes.toString() + ':' + seconds_padding + seconds.toString();
34 }
35
36 constructor(hash: {
37 author: string,
38 createdAt: string,
39 categoryLabel: string,
40 licenceLabel: string,
41 description: string,
42 duration: number;
43 id: string,
44 isLocal: boolean,
45 magnetUri: string,
46 name: string,
47 podHost: string,
48 tags: string[],
49 thumbnailPath: string,
50 views: number,
51 likes: number,
52 dislikes: number,
53 nsfw: boolean
54 }) {
55 this.author = hash.author;
56 this.createdAt = new Date(hash.createdAt);
57 this.categoryLabel = hash.categoryLabel;
58 this.licenceLabel = hash.licenceLabel;
59 this.description = hash.description;
60 this.duration = Video.createDurationString(hash.duration);
61 this.id = hash.id;
62 this.isLocal = hash.isLocal;
63 this.magnetUri = hash.magnetUri;
64 this.name = hash.name;
65 this.podHost = hash.podHost;
66 this.tags = hash.tags;
67 this.thumbnailPath = hash.thumbnailPath;
68 this.views = hash.views;
69 this.likes = hash.likes;
70 this.dislikes = hash.dislikes;
71 this.nsfw = hash.nsfw;
72
73 this.by = Video.createByString(hash.author, hash.podHost);
74 }
75
76 isRemovableBy(user: User) {
77 return this.isLocal === true && user && this.author === user.username;
78 }
79
80 isVideoNSFWForUser(user: User) {
81 // If the video is NSFW and the user is not logged in, or the user does not want to display NSFW videos...
82 return (this.nsfw && (!user || user.displayNSFW === false));
83 }
84 }