Skip to content

Commit 7c19657

Browse files
milanmajchrakclaude
andcommitted
LINDAT/fix(fe): redirect anonymous bitstream download on the server too
SSR rendered /bitstreams/<uuid>/download as 200 HTML for anonymous requests, because window.location.replace does nothing in Node. The anonymous branch now goes through HardRedirectService, which answers 302 on the server and location.replace in the browser. The logged-in branch is unchanged. Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com> (cherry picked from commit 8430a3d) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 7f16e81 commit 7c19657

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

‎src/app/bitstream-page/clarin-bitstream-download-page/clarin-bitstream-download-page.component.spec.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ describe('ClarinBitstreamDownloadPageComponent', () => {
3737

3838
beforeEach(async () => {
3939
authService = jasmine.createSpyObj('authService', {
40-
isAuthenticated: observableOf(true),
40+
isAuthenticated: observableOf(false),
4141
setRedirectUrl: {}
4242
});
4343
authorizationService = jasmine.createSpyObj('authorizationSerivice', {
@@ -70,7 +70,7 @@ describe('ClarinBitstreamDownloadPageComponent', () => {
7070
};
7171
router = jasmine.createSpyObj('router', ['navigateByUrl']);
7272
requestService = getMockRequestService();
73-
halService = Object.assign(new HALEndpointServiceStub(url));
73+
halService = Object.assign(new HALEndpointServiceStub(url), { getRootHref: () => url }) as any;
7474
rdbService = getMockRemoteDataBuildService();
7575

7676
await TestBed.configureTestingModule({
@@ -100,4 +100,8 @@ describe('ClarinBitstreamDownloadPageComponent', () => {
100100
it('should create', () => {
101101
expect(component).toBeTruthy();
102102
});
103+
104+
it('should redirect an anonymous user to the bitstream content through HardRedirectService', () => {
105+
expect(hardRedirectService.redirect).toHaveBeenCalledWith('bitstream-content-link');
106+
});
103107
});

‎src/app/bitstream-page/clarin-bitstream-download-page/clarin-bitstream-download-page.component.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,9 @@ export class ClarinBitstreamDownloadPageComponent implements OnInit {
132132
window.location.replace(fileLink);
133133
} else if ((isAuthorized || isAuthorizedByClarin) && !isLoggedIn) {
134134
this.downloadStatus.next(RequestEntryState.Success);
135-
window.location.replace(bitstreamURL);
135+
// Server-side too, so crawlers get a 302. Logged-in users keep the client-side
136+
// redirect: a server 302 right after login left the browser on the login page.
137+
this.hardRedirectService.redirect(bitstreamURL);
136138
} else if (!(isAuthorized || isAuthorizedByClarin) && isLoggedIn &&
137139
this.downloadStatus.value === RequestEntryState.Error) {
138140
// this.downloadStatus is `ERROR` - no CLARIN exception is thrown up

0 commit comments

Comments
 (0)