99import { Observable } from 'rxjs' ;
1010import { map } from 'rxjs/operators' ;
1111
12+ import { APP_CONFIG , AppConfig } from '../../config/app-config.interface' ;
1213import { PAGE_NOT_FOUND_PATH } from '../app-routing-paths' ;
1314import { BitstreamDataService } from '../core/data/bitstream-data.service' ;
1415import { RemoteData } from '../core/data/remote-data' ;
@@ -30,6 +31,7 @@ export const legacyBitstreamURLRedirectGuard: CanActivateFn = (
3031 bitstreamDataService : BitstreamDataService = inject ( BitstreamDataService ) ,
3132 serverHardRedirectService : HardRedirectService = inject ( HardRedirectService ) ,
3233 router : Router = inject ( Router ) ,
34+ appConfig : AppConfig = inject ( APP_CONFIG ) ,
3335) : Observable < UrlTree | boolean > => {
3436 const prefix = route . params . prefix ;
3537 const suffix = route . params . suffix ;
@@ -46,7 +48,10 @@ export const legacyBitstreamURLRedirectGuard: CanActivateFn = (
4648 getFirstCompletedRemoteData ( ) ,
4749 map ( ( rd : RemoteData < Bitstream > ) => {
4850 if ( rd . hasSucceeded && ! rd . hasNoContent ) {
49- serverHardRedirectService . redirect ( new URL ( `/bitstreams/${ rd . payload . uuid } /download` , serverHardRedirectService . getCurrentOrigin ( ) ) . href , 301 ) ;
51+ const nameSpace = appConfig . ui . nameSpace ?. replace ( / \/ $ / , '' ) || '' ;
52+ const redirectUrl = new URL ( nameSpace + `/bitstreams/${ rd . payload . uuid } /download` , serverHardRedirectService . getCurrentOrigin ( ) ) . href ;
53+ console . log ( 'Legacy bitstream URL redirecting to:' , redirectUrl ) ;
54+ serverHardRedirectService . redirect ( redirectUrl , 301 ) ;
5055 return false ;
5156 } else {
5257 return router . createUrlTree ( [ PAGE_NOT_FOUND_PATH ] ) ;
0 commit comments