]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - 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
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
92fb909c 88 isRemovableBy(user: User) {
501bc6c2
C
89 return this.isLocal === true && user && this.author === user.username;
90 }
92fb909c
C
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 }
d8e689b8
C
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 }
501bc6c2 125}