11import { Component , Inject , OnInit , PLATFORM_ID } from '@angular/core' ;
2- import { filter , map , startWith , switchMap , take } from 'rxjs/operators' ;
2+ import { map , startWith , take } from 'rxjs/operators' ;
33import { ActivatedRoute , Router } from '@angular/router' ;
4- import { hasValue , isNotEmpty } from '../../shared/empty.util' ;
4+ import { isNotEmpty } from '../../shared/empty.util' ;
55import { getRemoteDataPayload } from '../../core/shared/operators' ;
66import { Bitstream } from '../../core/shared/bitstream.model' ;
77import { AuthorizationDataService } from '../../core/data/feature-authorization/authorization-data.service' ;
8- import { FeatureID } from '../../core/data/feature-authorization/feature-id' ;
98import { AuthService } from '../../core/auth/auth.service' ;
10- import { combineLatest as observableCombineLatest , Observable , of as observableOf } from 'rxjs' ;
9+ import { Observable } from 'rxjs' ;
1110import { FileService } from '../../core/shared/file.service' ;
1211import { HardRedirectService } from '../../core/services/hard-redirect.service' ;
13- import { getForbiddenRoute } from '../../app-routing-paths' ;
1412import { RemoteData } from '../../core/data/remote-data' ;
15- import { redirectOn4xx } from '../../core/shared/authorized.operators' ;
1613import { isPlatformServer , Location } from '@angular/common' ;
1714import { DSONameService } from '../../core/breadcrumbs/dso-name.service' ;
1815import { SignpostingDataService } from '../../core/data/signposting-data.service' ;
@@ -62,52 +59,18 @@ export class BitstreamDownloadPageComponent implements OnInit {
6259 }
6360
6461 ngOnInit ( ) : void {
65-
6662 this . bitstreamRD$ = this . route . data . pipe (
67- map ( ( data ) => data . bitstream ) ) ;
63+ map ( ( data ) => data . bitstream )
64+ ) ;
6865
6966 this . bitstream$ = this . bitstreamRD$ . pipe (
70- redirectOn4xx ( this . router , this . auth ) ,
7167 getRemoteDataPayload ( )
7268 ) ;
7369
7470 this . fileName$ = this . bitstream$ . pipe (
7571 map ( ( bitstream : Bitstream ) => this . dsoNameService . getName ( bitstream ) ) ,
76- startWith ( 'file' ) ,
72+ startWith ( 'file' )
7773 ) ;
78-
79- this . bitstream$ . pipe (
80- switchMap ( ( bitstream : Bitstream ) => {
81- const isAuthorized$ = this . authorizationService . isAuthorized ( FeatureID . CanDownload , isNotEmpty ( bitstream ) ? bitstream . self : undefined ) ;
82- const isLoggedIn$ = this . auth . isAuthenticated ( ) ;
83- return observableCombineLatest ( [ isAuthorized$ , isLoggedIn$ , observableOf ( bitstream ) ] ) ;
84- } ) ,
85- filter ( ( [ isAuthorized , isLoggedIn , bitstream ] : [ boolean , boolean , Bitstream ] ) => hasValue ( isAuthorized ) && hasValue ( isLoggedIn ) ) ,
86- take ( 1 ) ,
87- switchMap ( ( [ isAuthorized , isLoggedIn , bitstream ] : [ boolean , boolean , Bitstream ] ) => {
88- if ( isAuthorized && isLoggedIn ) {
89- return this . fileService . retrieveFileDownloadLink ( bitstream . _links . content . href ) . pipe (
90- filter ( ( fileLink ) => hasValue ( fileLink ) ) ,
91- take ( 1 ) ,
92- map ( ( fileLink ) => {
93- return [ isAuthorized , isLoggedIn , bitstream , fileLink ] ;
94- } ) ) ;
95- } else {
96- return [ [ isAuthorized , isLoggedIn , bitstream , '' ] ] ;
97- }
98- } )
99- ) . subscribe ( ( [ isAuthorized , isLoggedIn , bitstream , fileLink ] : [ boolean , boolean , Bitstream , string ] ) => {
100- if ( isAuthorized && isLoggedIn && isNotEmpty ( fileLink ) ) {
101- this . hardRedirectService . redirect ( fileLink ) ;
102- } else if ( isAuthorized && ! isLoggedIn ) {
103- this . hardRedirectService . redirect ( bitstream . _links . content . href ) ;
104- } else if ( ! isAuthorized && isLoggedIn ) {
105- this . router . navigateByUrl ( getForbiddenRoute ( ) , { skipLocationChange : true } ) ;
106- } else if ( ! isAuthorized && ! isLoggedIn ) {
107- this . auth . setRedirectUrl ( this . router . url ) ;
108- this . router . navigateByUrl ( 'login' ) ;
109- }
110- } ) ;
11174 }
11275
11376 /**
@@ -124,7 +87,6 @@ export class BitstreamDownloadPageComponent implements OnInit {
12487 signpostingLinks . forEach ( ( link : SignpostingLink ) => {
12588 links = links + ( isNotEmpty ( links ) ? ', ' : '' ) + `<${ link . href } > ; rel="${ link . rel } "` + ( isNotEmpty ( link . type ) ? ` ; type="${ link . type } " ` : ' ' ) ;
12689 } ) ;
127-
12890 this . responseService . setHeader ( 'Link' , links ) ;
12991 } ) ;
13092 } ) ;
0 commit comments