]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/app.component.ts
BEARKING CHANGE: Update videos API response
[github/Chocobozzz/PeerTube.git] / client / src / app / app.component.ts
index 3af33ba2b47c8d1922b36edf13e07ec07bef0a4c..84435b5dbddcfddc2ab03228bc3b3adcb859c7b9 100644 (file)
@@ -1,6 +1,7 @@
 import { Component, OnInit } from '@angular/core'
+import { DomSanitizer, SafeHtml } from '@angular/platform-browser'
 import { GuardsCheckStart, Router } from '@angular/router'
-import { AuthService, ServerService } from '@app/core'
+import { AuthService, RedirectService, ServerService } from '@app/core'
 import { isInSmallView } from '@app/shared/misc/utils'
 
 @Component({
@@ -24,10 +25,14 @@ export class AppComponent implements OnInit {
 
   isMenuDisplayed = true
 
+  customCSS: SafeHtml
+
   constructor (
     private router: Router,
     private authService: AuthService,
-    private serverService: ServerService
+    private serverService: ServerService,
+    private domSanitizer: DomSanitizer,
+    private redirectService: RedirectService
   ) {}
 
   get serverVersion () {
@@ -39,6 +44,13 @@ export class AppComponent implements OnInit {
   }
 
   ngOnInit () {
+    document.getElementById('incompatible-browser').className += ' browser-ok'
+
+    const pathname = window.location.pathname
+    if (!pathname || pathname === '/') {
+      this.redirectService.redirectToHomepage()
+    }
+
     this.authService.loadClientCredentials()
 
     if (this.authService.isLoggedIn()) {
@@ -66,6 +78,26 @@ export class AppComponent implements OnInit {
         }
       }
     )
+
+    this.serverService.configLoaded
+      .subscribe(() => {
+        const config = this.serverService.getConfig()
+
+        // We test customCSS in case or the admin removed the css
+        if (this.customCSS || config.instance.customizations.css) {
+          const styleTag = '<style>' + config.instance.customizations.css + '</style>'
+          this.customCSS = this.domSanitizer.bypassSecurityTrustHtml(styleTag)
+        }
+
+        if (config.instance.customizations.javascript) {
+          try {
+            // tslint:disable:no-eval
+            eval(config.instance.customizations.javascript)
+          } catch (err) {
+            console.error('Cannot eval custom JavaScript.', err)
+          }
+        }
+      })
   }
 
   toggleMenu () {