]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/videos/shared/video.model.ts
Fix tests
[github/Chocobozzz/PeerTube.git] / client / src / app / videos / shared / video.model.ts
CommitLineData
92fb909c
C
1import { User } from '../../shared';
2
501bc6c2 3export class Video {
4fd8aa32
C
4 author: string;
5 by: string;
feb4bdfd 6 createdAt: Date;
6e07c3de 7 categoryLabel: string;
d8e689b8 8 category: string;
d07137b9 9 licenceLabel: string;
d8e689b8 10 licence: string;
db216afd 11 languageLabel: string;
d8e689b8 12 language: string;
501bc6c2 13 description: string;
4fd8aa32
C
14 duration: string;
15 id: string;
16 isLocal: boolean;
501bc6c2 17 magnetUri: string;
4fd8aa32 18 name: string;
49abbbbe 19 podHost: string;
00a44645 20 tags: string[];
501bc6c2 21 thumbnailPath: string;
05a9feaa 22 views: number;
d38b8281
C
23 likes: number;
24 dislikes: number;
92fb909c 25 nsfw: boolean;
aff038cd 26
49abbbbe
C
27 private static createByString(author: string, podHost: string) {
28 return author + '@' + podHost;
aff038cd
C
29 }
30
4fd8aa32
C
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
501bc6c2 40 constructor(hash: {
501bc6c2 41 author: string,
feb4bdfd 42 createdAt: string,
6e07c3de 43 categoryLabel: string,
d8e689b8 44 category: string,
d07137b9 45 licenceLabel: string,
d8e689b8 46 licence: string,
db216afd 47 languageLabel: string;
d8e689b8 48 language: string;
4fd8aa32 49 description: string,
501bc6c2 50 duration: number;
4fd8aa32
C
51 id: string,
52 isLocal: boolean,
53 magnetUri: string,
54 name: string,
49abbbbe 55 podHost: string,
00a44645 56 tags: string[],
05a9feaa 57 thumbnailPath: string,
d38b8281
C
58 views: number,
59 likes: number,
60 dislikes: number,
92fb909c 61 nsfw: boolean
501bc6c2 62 }) {
4fd8aa32 63 this.author = hash.author;
feb4bdfd 64 this.createdAt = new Date(hash.createdAt);
6e07c3de 65 this.categoryLabel = hash.categoryLabel;
d8e689b8 66 this.category = hash.category;
d07137b9 67 this.licenceLabel = hash.licenceLabel;
d8e689b8 68 this.licence = hash.licence;
db216afd 69 this.languageLabel = hash.languageLabel;
d8e689b8 70 this.language = hash.language;
501bc6c2 71 this.description = hash.description;
4fd8aa32
C
72 this.duration = Video.createDurationString(hash.duration);
73 this.id = hash.id;
74 this.isLocal = hash.isLocal;
501bc6c2 75 this.magnetUri = hash.magnetUri;
4fd8aa32 76 this.name = hash.name;
49abbbbe 77 this.podHost = hash.podHost;
00a44645 78 this.tags = hash.tags;
501bc6c2 79 this.thumbnailPath = hash.thumbnailPath;
05a9feaa 80 this.views = hash.views;
d38b8281
C
81 this.likes = hash.likes;
82 this.dislikes = hash.dislikes;
92fb909c 83 this.nsfw = hash.nsfw;
4fd8aa32 84
49abbbbe 85 this.by = Video.createByString(hash.author, hash.podHost);
501bc6c2
C
86 }
87
198b205c
GS
88 isRemovableBy(user) {
89 return user && this.isLocal === true && (this.author === user.username || user.isAdmin() === true);
90 }
91
92 isBlackistableBy(user) {
93 return user && user.isAdmin() === true && this.isLocal === false;
501bc6c2 94 }
92fb909c
C
95
96 isVideoNSFWForUser(user: User) {
97 // If the video is NSFW and the user is not logged in, or the user does not want to display NSFW videos...
98 return (this.nsfw && (!user || user.displayNSFW === false));
99 }
d8e689b8
C
100
101 patch(values: Object) {
102 Object.keys(values).forEach((key) => {
103 this[key] = values[key];
104 });
105 }
106
107 toJSON() {
108 return {
109 author: this.author,
110 createdAt: this.createdAt,
111 category: this.category,
112 licence: this.licence,
113 language: this.language,
114 description: this.description,
115 duration: this.duration,
116 id: this.id,
117 isLocal: this.isLocal,
118 magnetUri: this.magnetUri,
119 name: this.name,
120 podHost: this.podHost,
121 tags: this.tags,
122 thumbnailPath: this.thumbnailPath,
123 views: this.views,
124 likes: this.likes,
125 dislikes: this.dislikes,
126 nsfw: this.nsfw
127 };
128 }
501bc6c2 129}