]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/videos/shared/video.model.ts
Update client modules
[github/Chocobozzz/PeerTube.git] / client / src / app / videos / shared / video.model.ts
CommitLineData
69f616ab 1import { Video as VideoServerModel } from '../../../../../shared';
92fb909c
C
2import { User } from '../../shared';
3
69f616ab 4export class Video implements VideoServerModel {
4fd8aa32
C
5 author: string;
6 by: string;
feb4bdfd 7 createdAt: Date;
6e07c3de 8 categoryLabel: string;
69f616ab 9 category: number;
d07137b9 10 licenceLabel: string;
69f616ab 11 licence: number;
db216afd 12 languageLabel: string;
69f616ab 13 language: number;
501bc6c2 14 description: string;
69f616ab
C
15 duration: number;
16 durationLabel: string;
4fd8aa32
C
17 id: string;
18 isLocal: boolean;
501bc6c2 19 magnetUri: string;
4fd8aa32 20 name: string;
49abbbbe 21 podHost: string;
00a44645 22 tags: string[];
501bc6c2 23 thumbnailPath: string;
05a9feaa 24 views: number;
d38b8281
C
25 likes: number;
26 dislikes: number;
92fb909c 27 nsfw: boolean;
aff038cd 28
49abbbbe
C
29 private static createByString(author: string, podHost: string) {
30 return author + '@' + podHost;
aff038cd
C
31 }
32
4fd8aa32
C
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
501bc6c2 42 constructor(hash: {
501bc6c2 43 author: string,
feb4bdfd 44 createdAt: string,
6e07c3de 45 categoryLabel: string,
69f616ab 46 category: number,
d07137b9 47 licenceLabel: string,
69f616ab 48 licence: number,
db216afd 49 languageLabel: string;
69f616ab 50 language: number;
4fd8aa32 51 description: string,
501bc6c2 52 duration: number;
4fd8aa32
C
53 id: string,
54 isLocal: boolean,
55 magnetUri: string,
56 name: string,
49abbbbe 57 podHost: string,
00a44645 58 tags: string[],
05a9feaa 59 thumbnailPath: string,
d38b8281
C
60 views: number,
61 likes: number,
62 dislikes: number,
92fb909c 63 nsfw: boolean
501bc6c2 64 }) {
4fd8aa32 65 this.author = hash.author;
feb4bdfd 66 this.createdAt = new Date(hash.createdAt);
6e07c3de 67 this.categoryLabel = hash.categoryLabel;
d8e689b8 68 this.category = hash.category;
d07137b9 69 this.licenceLabel = hash.licenceLabel;
d8e689b8 70 this.licence = hash.licence;
db216afd 71 this.languageLabel = hash.languageLabel;
d8e689b8 72 this.language = hash.language;
501bc6c2 73 this.description = hash.description;
69f616ab
C
74 this.duration = hash.duration;
75 this.durationLabel = Video.createDurationString(hash.duration);
4fd8aa32
C
76 this.id = hash.id;
77 this.isLocal = hash.isLocal;
501bc6c2 78 this.magnetUri = hash.magnetUri;
4fd8aa32 79 this.name = hash.name;
49abbbbe 80 this.podHost = hash.podHost;
00a44645 81 this.tags = hash.tags;
501bc6c2 82 this.thumbnailPath = hash.thumbnailPath;
05a9feaa 83 this.views = hash.views;
d38b8281
C
84 this.likes = hash.likes;
85 this.dislikes = hash.dislikes;
92fb909c 86 this.nsfw = hash.nsfw;
4fd8aa32 87
49abbbbe 88 this.by = Video.createByString(hash.author, hash.podHost);
501bc6c2
C
89 }
90
198b205c
GS
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;
501bc6c2 97 }
92fb909c 98
9eee32fc
C
99 isUpdatableBy(user) {
100 return user && this.isLocal === true && user.username === this.author;
101 }
102
92fb909c
C
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 }
d8e689b8
C
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 }
501bc6c2 136}