66import {
77 Component ,
88 Inject ,
9+ inject ,
910 OnInit ,
1011 PLATFORM_ID ,
1112} from '@angular/core' ;
@@ -30,6 +31,7 @@ import {
3031import { getForbiddenRoute } from '../../app-routing-paths' ;
3132import { AuthService } from '../../core/auth/auth.service' ;
3233import { DSONameService } from '../../core/breadcrumbs/dso-name.service' ;
34+ import { ConfigurationDataService } from '../../core/data/configuration-data.service' ;
3335import { AuthorizationDataService } from '../../core/data/feature-authorization/authorization-data.service' ;
3436import { FeatureID } from '../../core/data/feature-authorization/feature-id' ;
3537import { RemoteData } from '../../core/data/remote-data' ;
@@ -64,6 +66,8 @@ export class BitstreamDownloadPageComponent implements OnInit {
6466 bitstream$ : Observable < Bitstream > ;
6567 bitstreamRD$ : Observable < RemoteData < Bitstream > > ;
6668
69+ configService = inject ( ConfigurationDataService ) ;
70+
6771 constructor (
6872 private route : ActivatedRoute ,
6973 protected router : Router ,
@@ -103,30 +107,33 @@ export class BitstreamDownloadPageComponent implements OnInit {
103107 switchMap ( ( bitstream : Bitstream ) => {
104108 const isAuthorized$ = this . authorizationService . isAuthorized ( FeatureID . CanDownload , isNotEmpty ( bitstream ) ? bitstream . self : undefined ) ;
105109 const isLoggedIn$ = this . auth . isAuthenticated ( ) ;
106- return observableCombineLatest ( [ isAuthorized$ , isLoggedIn$ , accessToken$ , observableOf ( bitstream ) ] ) ;
110+ const isMatomoEnabled$ = this . matomoService . isMatomoEnabled$ ( ) ;
111+ return observableCombineLatest ( [ isAuthorized$ , isLoggedIn$ , isMatomoEnabled$ , accessToken$ , observableOf ( bitstream ) ] ) ;
107112 } ) ,
108- filter ( ( [ isAuthorized , isLoggedIn , accessToken , bitstream ] : [ boolean , boolean , string , Bitstream ] ) => ( hasValue ( isAuthorized ) && hasValue ( isLoggedIn ) ) || hasValue ( accessToken ) ) ,
113+ filter ( ( [ isAuthorized , isLoggedIn , isMatomoEnabled , accessToken , bitstream ] : [ boolean , boolean , boolean , string , Bitstream ] ) => ( hasValue ( isAuthorized ) && hasValue ( isLoggedIn ) ) || hasValue ( accessToken ) ) ,
109114 take ( 1 ) ,
110- switchMap ( ( [ isAuthorized , isLoggedIn , accessToken , bitstream ] : [ boolean , boolean , string , Bitstream ] ) => {
115+ switchMap ( ( [ isAuthorized , isLoggedIn , isMatomoEnabled , accessToken , bitstream ] : [ boolean , boolean , boolean , string , Bitstream ] ) => {
111116 if ( isAuthorized && isLoggedIn ) {
112117 return this . fileService . retrieveFileDownloadLink ( bitstream . _links . content . href ) . pipe (
113118 filter ( ( fileLink ) => hasValue ( fileLink ) ) ,
114119 take ( 1 ) ,
115120 map ( ( fileLink ) => {
116- return [ isAuthorized , isLoggedIn , bitstream , fileLink ] ;
121+ return [ isAuthorized , isLoggedIn , isMatomoEnabled , bitstream , fileLink ] ;
117122 } ) ) ;
118123 } else if ( hasValue ( accessToken ) ) {
119- return [ [ isAuthorized , ! isLoggedIn , bitstream , '' , accessToken ] ] ;
124+ return [ [ isAuthorized , ! isLoggedIn , isMatomoEnabled , bitstream , '' , accessToken ] ] ;
120125 } else {
121- return [ [ isAuthorized , isLoggedIn , bitstream , bitstream . _links . content . href ] ] ;
126+ return [ [ isAuthorized , isLoggedIn , isMatomoEnabled , bitstream , bitstream . _links . content . href ] ] ;
122127 }
123128 } ) ,
124- switchMap ( ( [ isAuthorized , isLoggedIn , bitstream , fileLink , accessToken ] : [ boolean , boolean , Bitstream , string , string ] ) =>
125- this . matomoService . appendVisitorId ( fileLink )
126- . pipe (
129+ switchMap ( ( [ isAuthorized , isLoggedIn , isMatomoEnabled , bitstream , fileLink , accessToken ] : [ boolean , boolean , boolean , Bitstream , string , string ] ) => {
130+ if ( isMatomoEnabled ) {
131+ return this . matomoService . appendVisitorId ( fileLink ) . pipe (
127132 map ( ( fileLinkWithVisitorId ) => [ isAuthorized , isLoggedIn , bitstream , fileLinkWithVisitorId , accessToken ] ) ,
128- ) ,
129- ) ,
133+ ) ;
134+ }
135+ return observableOf ( [ isAuthorized , isLoggedIn , bitstream , fileLink , accessToken ] ) ;
136+ } ) ,
130137 ) . subscribe ( ( [ isAuthorized , isLoggedIn , bitstream , fileLink , accessToken ] : [ boolean , boolean , Bitstream , string , string ] ) => {
131138 if ( isAuthorized && isLoggedIn && isNotEmpty ( fileLink ) ) {
132139 this . hardRedirectService . redirect ( fileLink ) ;
0 commit comments