]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - client/src/app/videos/shared/video.model.ts
Update client modules
[github/Chocobozzz/PeerTube.git] / client / src / app / videos / shared / video.model.ts
... / ...
CommitLineData
1import { Video as VideoServerModel } from '../../../../../shared';
2import { User } from '../../shared';
3
4export class Video implements VideoServerModel {
5 author: string;
6 by: string;
7 createdAt: Date;
8 categoryLabel: string;
9 category: number;
10 licenceLabel: string;
11 licence: number;
12 languageLabel: string;
13 language: number;
14 description: string;
15 duration: number;
16 durationLabel: string;
17 id: string;
18 isLocal: boolean;
19 magnetUri: string;
20 name: string;
21 podHost: string;
22 tags: string[];
23 thumbnailPath: string;
24 views: number;
25 likes: number;
26 dislikes: number;
27 nsfw: boolean;
28
29 private static createByString(author: string, podHost: string) {
30 return author + '@' + podHost;
31 }
32
33 private static createDurationString(duration: number) {
34 const minutes = Math.floor(duration / 60);
35 const seconds = duration % 60;
36 const minutes_padding = minutes >= 10 ? '' : '0';
37 const seconds_padding = seconds >= 10 ? '' : '0';
38
39 return minutes_padding + minutes.toString() + ':' + seconds_padding + seconds.toString();
40 }
41
42 constructor(hash: {
43 author: string,
44 createdAt: string,
45 categoryLabel: string,
46 category: number,
47 licenceLabel: string,
48 licence: number,
49 languageLabel: string;
50 language: number;
51 description: string,
52 duration: number;
53 id: string,
54 isLocal: boolean,
55 magnetUri: string,
56 name: string,
57 podHost: string,
58 tags: string[],
59 thumbnailPath: string,
60 views: number,
61 likes: number,
62 dislikes: number,
63 nsfw: boolean
64 }) {
65 this.author = hash.author;
66 this.createdAt = new Date(hash.createdAt);
67 this.categoryLabel = hash.categoryLabel;
68 this.category = hash.category;
69 this.licenceLabel = hash.licenceLabel;
70 this.licence = hash.licence;
71 this.languageLabel = hash.languageLabel;
72 this.language = hash.language;
73 this.description = hash.description;
74 this.duration = hash.duration;
75 this.durationLabel = Video.createDurationString(hash.duration);
76 this.id = hash.id;
77 this.isLocal = hash.isLocal;
78 this.magnetUri = hash.magnetUri;
79 this.name = hash.name;
80 this.podHost = hash.podHost;
81 this.tags = hash.tags;
82 this.thumbnailPath = hash.thumbnailPath;
83 this.views = hash.views;
84 this.likes = hash.likes;
85 this.dislikes = hash.dislikes;
86 this.nsfw = hash.nsfw;
87
88 this.by = Video.createByString(hash.author, hash.podHost);
89 }
90
91 isRemovableBy(user) {
92 return user && this.isLocal === true && (this.author === user.username || user.isAdmin() === true);
93 }
94
95 isBlackistableBy(user) {
96 return user && user.isAdmin() === true && this.isLocal === false;
97 }
98
99 isUpdatableBy(user) {
100 return user && this.isLocal === true && user.username === this.author;
101 }
102
103 isVideoNSFWForUser(user: User) {
104 // If the video is NSFW and the user is not logged in, or the user does not want to display NSFW videos...
105 return (this.nsfw && (!user || user.displayNSFW === false));
106 }
107
108 patch(values: Object) {
109 Object.keys(values).forEach((key) => {
110 this[key] = values[key];
111 });
112 }
113
114 toJSON() {
115 return {
116 author: this.author,
117 createdAt: this.createdAt,
118 category: this.category,
119 licence: this.licence,
120 language: this.language,
121 description: this.description,
122 duration: this.duration,
123 id: this.id,
124 isLocal: this.isLocal,
125 magnetUri: this.magnetUri,
126 name: this.name,
127 podHost: this.podHost,
128 tags: this.tags,
129 thumbnailPath: this.thumbnailPath,
130 views: this.views,
131 likes: this.likes,
132 dislikes: this.dislikes,
133 nsfw: this.nsfw
134 };
135 }
136}