]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+page-not-found/page-not-found.component.ts
redirect to login on 401, display error variants in 404 component
[github/Chocobozzz/PeerTube.git] / client / src / app / +page-not-found / page-not-found.component.ts
CommitLineData
19b7ebfa
RK
1import { Component, OnInit } from '@angular/core'
2import { Title } from '@angular/platform-browser'
ab398a05 3import { Router } from '@angular/router'
19b7ebfa 4import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes'
a51bad1a
C
5
6@Component({
7 selector: 'my-page-not-found',
8 templateUrl: './page-not-found.component.html',
9 styleUrls: [ './page-not-found.component.scss' ]
10})
19b7ebfa
RK
11export class PageNotFoundComponent implements OnInit {
12 status = HttpStatusCode.NOT_FOUND_404
ab398a05 13 type: string
a51bad1a 14
19b7ebfa 15 public constructor (
ab398a05
RK
16 private titleService: Title,
17 private router: Router
18 ) {
19 const state = this.router.getCurrentNavigation()?.extras.state
20 this.type = state?.type || this.type
21 this.status = state?.obj.status || this.status
22 }
19b7ebfa
RK
23
24 ngOnInit () {
25 if (this.pathname.includes('teapot')) {
26 this.status = HttpStatusCode.I_AM_A_TEAPOT_418
27 this.titleService.setTitle($localize`I'm a teapot` + ' - PeerTube')
28 }
29 }
30
31 get pathname () {
32 return window.location.pathname
33 }
34
ab398a05
RK
35 getRessourceName () {
36 switch (this.type) {
37 case 'video':
38 return $localize`video`
39 default:
40 return $localize`ressource`
41 }
42 }
43
19b7ebfa
RK
44 getMascotName () {
45 switch (this.status) {
46 case HttpStatusCode.I_AM_A_TEAPOT_418:
47 return 'happy'
ab398a05
RK
48 case HttpStatusCode.FORBIDDEN_403:
49 return 'arguing'
19b7ebfa
RK
50 case HttpStatusCode.NOT_FOUND_404:
51 default:
52 return 'defeated'
53 }
54 }
a51bad1a 55}