]>
Commit | Line | Data |
---|---|---|
1 | import { Component, OnInit } from '@angular/core' | |
2 | import { Title } from '@angular/platform-browser' | |
3 | import { Router } from '@angular/router' | |
4 | import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' | |
5 | @Component({ | |
6 | selector: 'my-page-not-found', | |
7 | templateUrl: './page-not-found.component.html', | |
8 | styleUrls: [ './page-not-found.component.scss' ] | |
9 | }) | |
10 | export class PageNotFoundComponent implements OnInit { | |
11 | status = HttpStatusCode.NOT_FOUND_404 | |
12 | type: 'video' | 'other' = 'other' | |
13 | ||
14 | public constructor ( | |
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 | } | |
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' | |
38 | case HttpStatusCode.FORBIDDEN_403: | |
39 | return 'arguing' | |
40 | case HttpStatusCode.NOT_FOUND_404: | |
41 | default: | |
42 | return 'defeated' | |
43 | } | |
44 | } | |
45 | } |