]>
Commit | Line | Data |
---|---|---|
19b7ebfa RK |
1 | import { Component, OnInit } from '@angular/core' |
2 | import { Title } from '@angular/platform-browser' | |
ab398a05 | 3 | import { Router } from '@angular/router' |
19b7ebfa | 4 | import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' |
a51bad1a C |
5 | @Component({ |
6 | selector: 'my-page-not-found', | |
7 | templateUrl: './page-not-found.component.html', | |
8 | styleUrls: [ './page-not-found.component.scss' ] | |
9 | }) | |
19b7ebfa RK |
10 | export class PageNotFoundComponent implements OnInit { |
11 | status = HttpStatusCode.NOT_FOUND_404 | |
012580d9 | 12 | type: 'video' | 'other' = 'other' |
a51bad1a | 13 | |
19b7ebfa | 14 | public constructor ( |
ab398a05 RK |
15 | private titleService: Title, |
16 | private router: Router | |
17 | ) { | |
18 | const state = this.router.getCurrentNavigation()?.extras.state | |
19 | this.type = state?.type || this.type | |
20 | this.status = state?.obj.status || this.status | |
21 | } | |
19b7ebfa RK |
22 | |
23 | ngOnInit () { | |
24 | if (this.pathname.includes('teapot')) { | |
25 | this.status = HttpStatusCode.I_AM_A_TEAPOT_418 | |
26 | this.titleService.setTitle($localize`I'm a teapot` + ' - PeerTube') | |
27 | } | |
28 | } | |
29 | ||
30 | get pathname () { | |
31 | return window.location.pathname | |
32 | } | |
33 | ||
34 | getMascotName () { | |
35 | switch (this.status) { | |
36 | case HttpStatusCode.I_AM_A_TEAPOT_418: | |
37 | return 'happy' | |
ab398a05 RK |
38 | case HttpStatusCode.FORBIDDEN_403: |
39 | return 'arguing' | |
19b7ebfa RK |
40 | case HttpStatusCode.NOT_FOUND_404: |
41 | default: | |
42 | return 'defeated' | |
43 | } | |
44 | } | |
a51bad1a | 45 | } |