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