diff options
author | Chocobozzz <me@florianbigard.com> | 2022-07-15 15:30:14 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-07-18 11:37:18 +0200 |
commit | 42b40636991b97fe818007fab19091764fc5db73 (patch) | |
tree | db431787c06ce898d22e91ff771f795219274fc6 /client/src/app/core/routing/redirect.service.ts | |
parent | 654d4ede7fa4d0faa71e49bcfab6b65a686397b2 (diff) | |
download | PeerTube-42b40636991b97fe818007fab19091764fc5db73.tar.gz PeerTube-42b40636991b97fe818007fab19091764fc5db73.tar.zst PeerTube-42b40636991b97fe818007fab19091764fc5db73.zip |
Add ability for client to create server logs
Diffstat (limited to 'client/src/app/core/routing/redirect.service.ts')
-rw-r--r-- | client/src/app/core/routing/redirect.service.ts | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/client/src/app/core/routing/redirect.service.ts b/client/src/app/core/routing/redirect.service.ts index 567fd432b..575b3b2a1 100644 --- a/client/src/app/core/routing/redirect.service.ts +++ b/client/src/app/core/routing/redirect.service.ts | |||
@@ -1,10 +1,11 @@ | |||
1 | import * as debug from 'debug' | 1 | import * as debug from 'debug' |
2 | import { Injectable } from '@angular/core' | 2 | import { Injectable } from '@angular/core' |
3 | import { NavigationCancel, NavigationEnd, Router } from '@angular/router' | 3 | import { NavigationCancel, NavigationEnd, Router } from '@angular/router' |
4 | import { logger } from '@root-helpers/logger' | ||
4 | import { ServerService } from '../server' | 5 | import { ServerService } from '../server' |
5 | import { SessionStorageService } from '../wrappers/storage.service' | 6 | import { SessionStorageService } from '../wrappers/storage.service' |
6 | 7 | ||
7 | const logger = debug('peertube:router:RedirectService') | 8 | const debugLogger = debug('peertube:router:RedirectService') |
8 | 9 | ||
9 | @Injectable() | 10 | @Injectable() |
10 | export class RedirectService { | 11 | export class RedirectService { |
@@ -40,7 +41,7 @@ export class RedirectService { | |||
40 | this.latestSessionUrl = this.storage.getItem(RedirectService.SESSION_STORAGE_LATEST_SESSION_URL_KEY) | 41 | this.latestSessionUrl = this.storage.getItem(RedirectService.SESSION_STORAGE_LATEST_SESSION_URL_KEY) |
41 | this.storage.removeItem(RedirectService.SESSION_STORAGE_LATEST_SESSION_URL_KEY) | 42 | this.storage.removeItem(RedirectService.SESSION_STORAGE_LATEST_SESSION_URL_KEY) |
42 | 43 | ||
43 | logger('Loaded latest session URL %s', this.latestSessionUrl) | 44 | debugLogger('Loaded latest session URL %s', this.latestSessionUrl) |
44 | 45 | ||
45 | // Track previous url | 46 | // Track previous url |
46 | this.currentUrl = this.router.url | 47 | this.currentUrl = this.router.url |
@@ -51,8 +52,8 @@ export class RedirectService { | |||
51 | this.previousUrl = this.currentUrl | 52 | this.previousUrl = this.currentUrl |
52 | this.currentUrl = event.url | 53 | this.currentUrl = event.url |
53 | 54 | ||
54 | logger('Previous URL is %s, current URL is %s', this.previousUrl, this.currentUrl) | 55 | debugLogger('Previous URL is %s, current URL is %s', this.previousUrl, this.currentUrl) |
55 | logger('Setting %s as latest URL in session storage.', this.currentUrl) | 56 | debugLogger('Setting %s as latest URL in session storage.', this.currentUrl) |
56 | 57 | ||
57 | this.storage.setItem(RedirectService.SESSION_STORAGE_LATEST_SESSION_URL_KEY, this.currentUrl) | 58 | this.storage.setItem(RedirectService.SESSION_STORAGE_LATEST_SESSION_URL_KEY, this.currentUrl) |
58 | } | 59 | } |
@@ -84,18 +85,14 @@ export class RedirectService { | |||
84 | 85 | ||
85 | this.redirectingToHomepage = true | 86 | this.redirectingToHomepage = true |
86 | 87 | ||
87 | console.log('Redirecting to %s...', this.defaultRoute) | 88 | logger.info(`Redirecting to ${this.defaultRoute}...`) |
88 | 89 | ||
89 | this.router.navigateByUrl(this.defaultRoute, { skipLocationChange }) | 90 | this.router.navigateByUrl(this.defaultRoute, { skipLocationChange }) |
90 | .then(() => this.redirectingToHomepage = false) | 91 | .then(() => this.redirectingToHomepage = false) |
91 | .catch(() => { | 92 | .catch(() => { |
92 | this.redirectingToHomepage = false | 93 | this.redirectingToHomepage = false |
93 | 94 | ||
94 | console.error( | 95 | logger.error(`Cannot navigate to ${this.defaultRoute}, resetting default route to ${RedirectService.INIT_DEFAULT_ROUTE}`) |
95 | 'Cannot navigate to %s, resetting default route to %s.', | ||
96 | this.defaultRoute, | ||
97 | RedirectService.INIT_DEFAULT_ROUTE | ||
98 | ) | ||
99 | 96 | ||
100 | this.defaultRoute = RedirectService.INIT_DEFAULT_ROUTE | 97 | this.defaultRoute = RedirectService.INIT_DEFAULT_ROUTE |
101 | return this.router.navigateByUrl(this.defaultRoute, { skipLocationChange }) | 98 | return this.router.navigateByUrl(this.defaultRoute, { skipLocationChange }) |
@@ -104,18 +101,18 @@ export class RedirectService { | |||
104 | } | 101 | } |
105 | 102 | ||
106 | private doRedirect (redirectUrl: string, fallbackRoute?: string) { | 103 | private doRedirect (redirectUrl: string, fallbackRoute?: string) { |
107 | logger('Redirecting on %s', redirectUrl) | 104 | debugLogger('Redirecting on %s', redirectUrl) |
108 | 105 | ||
109 | if (this.isValidRedirection(redirectUrl)) { | 106 | if (this.isValidRedirection(redirectUrl)) { |
110 | return this.router.navigateByUrl(redirectUrl) | 107 | return this.router.navigateByUrl(redirectUrl) |
111 | } | 108 | } |
112 | 109 | ||
113 | logger('%s is not a valid redirection, try fallback route %s', redirectUrl, fallbackRoute) | 110 | debugLogger('%s is not a valid redirection, try fallback route %s', redirectUrl, fallbackRoute) |
114 | if (fallbackRoute) { | 111 | if (fallbackRoute) { |
115 | return this.router.navigateByUrl(fallbackRoute) | 112 | return this.router.navigateByUrl(fallbackRoute) |
116 | } | 113 | } |
117 | 114 | ||
118 | logger('There was no fallback route, redirecting to homepage') | 115 | debugLogger('There was no fallback route, redirecting to homepage') |
119 | return this.redirectToHomepage() | 116 | return this.redirectToHomepage() |
120 | } | 117 | } |
121 | 118 | ||