From 92fb909c9b4a92a00b0d0da7629e6fb003de281b Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 4 Apr 2017 21:37:03 +0200 Subject: Client: Handle NSFW video --- client/src/app/app.component.ts | 4 +- client/src/app/core/auth/auth-user.model.ts | 15 ++++++-- client/src/app/core/config/config.service.ts | 36 ++++++++++++++++++ client/src/app/core/config/index.ts | 1 + client/src/app/core/core.module.ts | 4 +- client/src/app/core/index.ts | 1 + client/src/app/shared/users/user.model.ts | 10 ++++- client/src/app/videos/shared/video.model.ts | 12 +++++- .../app/videos/video-add/video-add.component.html | 8 ++++ .../app/videos/video-add/video-add.component.ts | 3 ++ .../video-list/video-miniature.component.html | 8 +++- .../video-list/video-miniature.component.scss | 15 ++++++++ .../videos/video-list/video-miniature.component.ts | 14 ++++++- .../videos/video-watch/video-watch.component.ts | 44 ++++++++++++++++------ .../app/videos/video-watch/webtorrent.service.ts | 4 ++ 15 files changed, 157 insertions(+), 22 deletions(-) create mode 100644 client/src/app/core/config/config.service.ts create mode 100644 client/src/app/core/config/index.ts diff --git a/client/src/app/app.component.ts b/client/src/app/app.component.ts index 4e33fae52..3c06b320e 100644 --- a/client/src/app/app.component.ts +++ b/client/src/app/app.component.ts @@ -1,7 +1,7 @@ import { Component, OnInit, ViewContainerRef } from '@angular/core'; import { Router } from '@angular/router'; -import { AuthService } from './core'; +import { AuthService, ConfigService } from './core'; import { VideoService } from './videos'; import { UserService } from './shared'; @@ -27,6 +27,7 @@ export class AppComponent implements OnInit { constructor( private router: Router, private authService: AuthService, + private configService: ConfigService, private userService: UserService, private videoService: VideoService, viewContainerRef: ViewContainerRef @@ -38,6 +39,7 @@ export class AppComponent implements OnInit { this.userService.checkTokenValidity(); } + this.configService.loadConfig(); this.videoService.loadVideoCategories(); this.videoService.loadVideoLicences(); } diff --git a/client/src/app/core/auth/auth-user.model.ts b/client/src/app/core/auth/auth-user.model.ts index 5d61954d6..cb7e88d19 100644 --- a/client/src/app/core/auth/auth-user.model.ts +++ b/client/src/app/core/auth/auth-user.model.ts @@ -5,7 +5,8 @@ export class AuthUser extends User { private static KEYS = { ID: 'id', ROLE: 'role', - USERNAME: 'username' + USERNAME: 'username', + DISPLAY_NSFW: 'display_nsfw' }; tokens: Tokens; @@ -17,7 +18,8 @@ export class AuthUser extends User { { id: parseInt(localStorage.getItem(this.KEYS.ID)), username: localStorage.getItem(this.KEYS.USERNAME), - role: localStorage.getItem(this.KEYS.ROLE) + role: localStorage.getItem(this.KEYS.ROLE), + displayNSFW: localStorage.getItem(this.KEYS.DISPLAY_NSFW) === 'true' }, Tokens.load() ); @@ -30,10 +32,16 @@ export class AuthUser extends User { localStorage.removeItem(this.KEYS.USERNAME); localStorage.removeItem(this.KEYS.ID); localStorage.removeItem(this.KEYS.ROLE); + localStorage.removeItem(this.KEYS.DISPLAY_NSFW); Tokens.flush(); } - constructor(userHash: { id: number, username: string, role: string }, hashTokens: any) { + constructor(userHash: { + id: number, + username: string, + role: string, + displayNSFW: boolean + }, hashTokens: any) { super(userHash); this.tokens = new Tokens(hashTokens); } @@ -59,6 +67,7 @@ export class AuthUser extends User { localStorage.setItem(AuthUser.KEYS.ID, this.id.toString()); localStorage.setItem(AuthUser.KEYS.USERNAME, this.username); localStorage.setItem(AuthUser.KEYS.ROLE, this.role); + localStorage.setItem(AuthUser.KEYS.DISPLAY_NSFW, JSON.stringify(this.displayNSFW); this.tokens.save(); } } diff --git a/client/src/app/core/config/config.service.ts b/client/src/app/core/config/config.service.ts new file mode 100644 index 000000000..295e68c36 --- /dev/null +++ b/client/src/app/core/config/config.service.ts @@ -0,0 +1,36 @@ +import { Injectable } from '@angular/core'; +import { Http } from '@angular/http'; + +import { RestExtractor } from '../../shared/rest'; + +@Injectable() +export class ConfigService { + private static BASE_CONFIG_URL = '/api/v1/config/'; + + private config: { + signup: { + enabled: boolean + } + } = { + signup: { + enabled: false + } + }; + + constructor( + private http: Http, + private restExtractor: RestExtractor, + ) {} + + loadConfig() { + this.http.get(ConfigService.BASE_CONFIG_URL) + .map(this.restExtractor.extractDataGet) + .subscribe(data => { + this.config = data; + }); + } + + getConfig() { + return this.config; + } +} diff --git a/client/src/app/core/config/index.ts b/client/src/app/core/config/index.ts new file mode 100644 index 000000000..90392254a --- /dev/null +++ b/client/src/app/core/config/index.ts @@ -0,0 +1 @@ +export * from './config.service'; diff --git a/client/src/app/core/core.module.ts b/client/src/app/core/core.module.ts index ae2930552..9a5ee5221 100644 --- a/client/src/app/core/core.module.ts +++ b/client/src/app/core/core.module.ts @@ -7,6 +7,7 @@ import { SimpleNotificationsModule } from 'angular2-notifications'; import { ModalModule } from 'ng2-bootstrap/modal'; import { AuthService } from './auth'; +import { ConfigService } from './config'; import { ConfirmComponent, ConfirmService } from './confirm'; import { MenuComponent, MenuAdminComponent } from './menu'; import { throwIfAlreadyLoaded } from './module-import-guard'; @@ -37,7 +38,8 @@ import { throwIfAlreadyLoaded } from './module-import-guard'; providers: [ AuthService, - ConfirmService + ConfirmService, + ConfigService ] }) export class CoreModule { diff --git a/client/src/app/core/index.ts b/client/src/app/core/index.ts index 9b4dd1999..96b28658b 100644 --- a/client/src/app/core/index.ts +++ b/client/src/app/core/index.ts @@ -1,4 +1,5 @@ export * from './auth'; +export * from './config'; export * from './confirm'; export * from './menu'; export * from './core.module' diff --git a/client/src/app/shared/users/user.model.ts b/client/src/app/shared/users/user.model.ts index 52d89e004..f7859f495 100644 --- a/client/src/app/shared/users/user.model.ts +++ b/client/src/app/shared/users/user.model.ts @@ -2,12 +2,20 @@ export class User { id: number; username: string; role: string; + displayNSFW: boolean; createdAt: Date; - constructor(hash: { id: number, username: string, role: string, createdAt?: Date }) { + constructor(hash: { + id: number, + username: string, + role: string, + displayNSFW?: boolean, + createdAt?: Date, + }) { this.id = hash.id; this.username = hash.username; this.role = hash.role; + this.displayNSFW = hash.displayNSFW; if (hash.createdAt) { this.createdAt = hash.createdAt; diff --git a/client/src/app/videos/shared/video.model.ts b/client/src/app/videos/shared/video.model.ts index 5ed622dce..3c588c446 100644 --- a/client/src/app/videos/shared/video.model.ts +++ b/client/src/app/videos/shared/video.model.ts @@ -1,3 +1,5 @@ +import { User } from '../../shared'; + export class Video { author: string; by: string; @@ -16,6 +18,7 @@ export class Video { views: number; likes: number; dislikes: number; + nsfw: boolean; private static createByString(author: string, podHost: string) { return author + '@' + podHost; @@ -47,6 +50,7 @@ export class Video { views: number, likes: number, dislikes: number, + nsfw: boolean }) { this.author = hash.author; this.createdAt = new Date(hash.createdAt); @@ -64,11 +68,17 @@ export class Video { this.views = hash.views; this.likes = hash.likes; this.dislikes = hash.dislikes; + this.nsfw = hash.nsfw; this.by = Video.createByString(hash.author, hash.podHost); } - isRemovableBy(user) { + isRemovableBy(user: User) { return this.isLocal === true && user && this.author === user.username; } + + isVideoNSFWForUser(user: User) { + // If the video is NSFW and the user is not logged in, or the user does not want to display NSFW videos... + return (this.nsfw && (!user || user.displayNSFW === false)); + } } diff --git a/client/src/app/videos/video-add/video-add.component.html b/client/src/app/videos/video-add/video-add.component.html index 97a3c846a..a3c25c14b 100644 --- a/client/src/app/videos/video-add/video-add.component.html +++ b/client/src/app/videos/video-add/video-add.component.html @@ -14,6 +14,14 @@ +
+ + +
+