aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/core/routing/redirect.service.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-07-15 15:30:14 +0200
committerChocobozzz <me@florianbigard.com>2022-07-18 11:37:18 +0200
commit42b40636991b97fe818007fab19091764fc5db73 (patch)
treedb431787c06ce898d22e91ff771f795219274fc6 /client/src/app/core/routing/redirect.service.ts
parent654d4ede7fa4d0faa71e49bcfab6b65a686397b2 (diff)
downloadPeerTube-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.ts23
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 @@
1import * as debug from 'debug' 1import * as debug from 'debug'
2import { Injectable } from '@angular/core' 2import { Injectable } from '@angular/core'
3import { NavigationCancel, NavigationEnd, Router } from '@angular/router' 3import { NavigationCancel, NavigationEnd, Router } from '@angular/router'
4import { logger } from '@root-helpers/logger'
4import { ServerService } from '../server' 5import { ServerService } from '../server'
5import { SessionStorageService } from '../wrappers/storage.service' 6import { SessionStorageService } from '../wrappers/storage.service'
6 7
7const logger = debug('peertube:router:RedirectService') 8const debugLogger = debug('peertube:router:RedirectService')
8 9
9@Injectable() 10@Injectable()
10export class RedirectService { 11export 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