Skip to content

Commit 326cfe6

Browse files
authored
UFAL/download-bitstreams-as-separated-api-calling (#969)
* added missing prefix * security: harden namespace handling in legacy bitstream redirect guard * harden legacy bitstream redirect namespace * removed security control * modified curl, download bitstreams based on the name as separeated api calling * remove -k argument from curl * removed debug console
1 parent 8c0af9f commit 326cfe6

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

src/app/bitstream-page/legacy-bitstream-url-redirect.guard.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
import { Observable } from 'rxjs';
1010
import { map } from 'rxjs/operators';
1111

12+
import { APP_CONFIG, AppConfig } from '../../config/app-config.interface';
1213
import { PAGE_NOT_FOUND_PATH } from '../app-routing-paths';
1314
import { BitstreamDataService } from '../core/data/bitstream-data.service';
1415
import { 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,9 @@ 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+
serverHardRedirectService.redirect(redirectUrl, 301);
5054
return false;
5155
} else {
5256
return router.createUrlTree([PAGE_NOT_FOUND_PATH]);

src/app/item-page/clarin-files-section/clarin-files-section.component.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,10 @@ export class ClarinFilesSectionComponent implements OnInit {
107107
return file.name;
108108
});
109109

110-
const url = `${this.halService.getRootHref()}/core/items/${this.item.id}/allzip?handleId=${this.itemHandle}`;
111-
this.command = `curl -o "allzip.zip" "${url}"`;
110+
// Generate curl command for individual bitstream downloads
111+
const baseUrl = `${this.halService.getRootHref()}/bitstream/${this.itemHandle}`;
112+
const fileNamesFormatted = fileNames.map((fileName, index) => `/${index}/${fileName}`).join(',');
113+
this.command = `curl -O ${baseUrl}{${fileNamesFormatted}}`;
112114
}
113115

114116
loadDownloadZipConfigProperties() {

0 commit comments

Comments
 (0)