aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/core/routing
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
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')
-rw-r--r--client/src/app/core/routing/custom-reuse-strategy.ts7
-rw-r--r--client/src/app/core/routing/redirect.service.ts23
-rw-r--r--client/src/app/core/routing/scroll.service.ts9
3 files changed, 19 insertions, 20 deletions
diff --git a/client/src/app/core/routing/custom-reuse-strategy.ts b/client/src/app/core/routing/custom-reuse-strategy.ts
index 5d3ad2e67..269b9d193 100644
--- a/client/src/app/core/routing/custom-reuse-strategy.ts
+++ b/client/src/app/core/routing/custom-reuse-strategy.ts
@@ -1,5 +1,6 @@
1import { ComponentRef, Injectable } from '@angular/core' 1import { ComponentRef, Injectable } from '@angular/core'
2import { ActivatedRouteSnapshot, DetachedRouteHandle, RouteReuseStrategy } from '@angular/router' 2import { ActivatedRouteSnapshot, DetachedRouteHandle, RouteReuseStrategy } from '@angular/router'
3import { logger } from '@root-helpers/logger'
3import { DisableForReuseHook } from './disable-for-reuse-hook' 4import { DisableForReuseHook } from './disable-for-reuse-hook'
4import { PeerTubeRouterService, RouterSetting } from './peertube-router.service' 5import { PeerTubeRouterService, RouterSetting } from './peertube-router.service'
5 6
@@ -22,7 +23,7 @@ export class CustomReuseStrategy implements RouteReuseStrategy {
22 const key = this.generateKey(route) 23 const key = this.generateKey(route)
23 this.recentlyUsed = key 24 this.recentlyUsed = key
24 25
25 console.log('Storing component %s to reuse later.', key) 26 logger.info(`Storing component ${key} to reuse later.`)
26 27
27 const componentRef = (handle as any).componentRef as ComponentRef<DisableForReuseHook> 28 const componentRef = (handle as any).componentRef as ComponentRef<DisableForReuseHook>
28 componentRef.instance.disableForReuse() 29 componentRef.instance.disableForReuse()
@@ -46,7 +47,7 @@ export class CustomReuseStrategy implements RouteReuseStrategy {
46 const key = this.generateKey(route) 47 const key = this.generateKey(route)
47 this.recentlyUsed = key 48 this.recentlyUsed = key
48 49
49 console.log('Reusing component %s.', key) 50 logger.info(`Reusing component ${key}.`)
50 51
51 const handle = this.storedRouteHandles.get(key) 52 const handle = this.storedRouteHandles.get(key)
52 if (!handle) return handle; 53 if (!handle) return handle;
@@ -66,7 +67,7 @@ export class CustomReuseStrategy implements RouteReuseStrategy {
66 this.storedRouteHandles.forEach((r, key) => { 67 this.storedRouteHandles.forEach((r, key) => {
67 if (key === this.recentlyUsed) return 68 if (key === this.recentlyUsed) return
68 69
69 console.log('Removing stored component %s.', key); 70 logger.info(`Removing stored component ${key}`);
70 71
71 (r as any).componentRef.destroy() 72 (r as any).componentRef.destroy()
72 this.storedRouteHandles.delete(key) 73 this.storedRouteHandles.delete(key)
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
diff --git a/client/src/app/core/routing/scroll.service.ts b/client/src/app/core/routing/scroll.service.ts
index 6d37fde71..0966255b3 100644
--- a/client/src/app/core/routing/scroll.service.ts
+++ b/client/src/app/core/routing/scroll.service.ts
@@ -4,8 +4,9 @@ import { ViewportScroller } from '@angular/common'
4import { Injectable } from '@angular/core' 4import { Injectable } from '@angular/core'
5import { RouterSetting } from '../' 5import { RouterSetting } from '../'
6import { PeerTubeRouterService } from './peertube-router.service' 6import { PeerTubeRouterService } from './peertube-router.service'
7import { logger } from '@root-helpers/logger'
7 8
8const logger = debug('peertube:main:ScrollService') 9const debugLogger = debug('peertube:main:ScrollService')
9 10
10@Injectable() 11@Injectable()
11export class ScrollService { 12export class ScrollService {
@@ -57,8 +58,8 @@ export class ScrollService {
57 if (nextSearchParams.toString() !== previousSearchParams.toString()) { 58 if (nextSearchParams.toString() !== previousSearchParams.toString()) {
58 this.resetScroll = true 59 this.resetScroll = true
59 } 60 }
60 } catch (e) { 61 } catch (err) {
61 console.error('Cannot parse URL to check next scroll.', e) 62 logger.error('Cannot parse URL to check next scroll.', err)
62 this.resetScroll = true 63 this.resetScroll = true
63 } 64 }
64 }) 65 })
@@ -67,7 +68,7 @@ export class ScrollService {
67 private consumeScroll () { 68 private consumeScroll () {
68 // Handle anchors/restore position 69 // Handle anchors/restore position
69 this.peertubeRouter.getScrollEvents().subscribe(e => { 70 this.peertubeRouter.getScrollEvents().subscribe(e => {
70 logger('Will schedule scroll after router event %o.', { e, resetScroll: this.resetScroll }) 71 debugLogger('Will schedule scroll after router event %o.', { e, resetScroll: this.resetScroll })
71 72
72 // scrollToAnchor first to preserve anchor position when using history navigation 73 // scrollToAnchor first to preserve anchor position when using history navigation
73 if (e.anchor) { 74 if (e.anchor) {