Skip to content

Conversation

@Paurikova2
Copy link
Collaborator

@Paurikova2 Paurikova2 commented Sep 9, 2025

Phases MP MM MB MR JM Total
ETA 0.5 0 0 0 0 0
Developing 1 0 0 0 0 0
Review 0 0 0 0 0 0
Total - - - - - 0
ETA est. 0
ETA cust. - - - - - 0

Problem description

When a bitstream is downloaded by name (e.g., https://dev-5.pc:8443/repository/bitstream/123456789/2-5947/0/test.txt), it redirects to https://dev-5.pc:8443/bitstreams/525188bc-7d2e-4ed6-a6d7-1a4b031b67b7/download, but the /repository prefix is missing in the redirected URL.

Summary by CodeRabbit

  • Bug Fixes

    • Legacy bitstream links now redirect correctly when a UI namespace is configured, preventing broken downloads.
    • Redirects use a permanent (301) redirect to improve bookmarking and SEO.
    • Falls back to a not-found page when the target bitstream cannot be resolved.
  • New Features

    • Namespace-aware redirect behavior that sanitizes configured namespaces to avoid malformed redirects.
    • Multi-file curl download support using shell brace expansion to fetch individual bitstreams with remote filenames.

@coderabbitai
Copy link

coderabbitai bot commented Sep 9, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Adds APP_CONFIG injection to the legacy bitstream redirect guard and makes its redirect namespace-aware; updates CLARIN files section to produce a brace-expansion multi-file curl command using a new bitstream base URL pattern.

Changes

Cohort / File(s) Summary
Bitstream legacy redirect guard
src/app/bitstream-page/legacy-bitstream-url-redirect.guard.ts
Imports APP_CONFIG and AppConfig; injects appConfig: AppConfig = inject(APP_CONFIG) into the guard; trims trailing slash from appConfig.ui.nameSpace via `nameSpace?.replace(//$/, '')
CLARIN files curl command
src/app/item-page/clarin-files-section/clarin-files-section.component.ts
Replaces single ZIP curl generation with a brace-expansion multi-file command: builds baseUrl as rootHref + '/bitstream/' + itemHandle; constructs fileNamesFormatted as comma-separated /{index}/{filename} entries from files; sets command to curl -O ${baseUrl}{${fileNamesFormatted}}; preserves canShowCurlDownload logic.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor U as User
  participant R as Router
  participant G as legacyBitstreamURLRedirectGuard
  participant S as Bitstream Service
  participant C as APP_CONFIG
  participant SH as ServerHardRedirectService

  U->>R: Navigate to legacy bitstream URL
  R->>G: Activate guard
  G->>S: Fetch bitstream by UUID
  S-->>G: RemoteData (success / error)

  alt Success
    G->>C: Read appConfig.ui.nameSpace
    Note right of G: Sanitize nameSpace\n(nameSpace?.replace(/\/$/, '') || '')
    G->>SH: getCurrentOrigin()
    Note right of G: Build redirectUrl: new URL(nameSpace + `/bitstreams/${uuid}/download`, origin).href
    G->>SH: redirect(redirectUrl, 301)
    G-->>R: return false
  else Not found / Error
    G-->>R: return UrlTree -> PAGE_NOT_FOUND_PATH
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • vidiecan

Pre-merge checks (2 passed, 1 warning)

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The pull request description includes the effort table and a problem description but does not follow the repository template’s required structure: it lacks the “Reported issues” and “Not-reported issues” subsections under Problem description and omits the Analysis and Problems sections. Update the description to include “### Reported issues” and “### Not-reported issues” subsections with relevant details, and add the “## Analysis” and “## Problems” sections (or remove unused template headings) to fully comply with the required template.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The current title “UFAL/download-bitstreams-as-separated-api-calling” mentions bitstream download but does not clearly summarize the main fix of restoring the “/repository” prefix and is phrased as a generic feature rather than the specific issue addressed.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.

Poem

I hop through old paths with a twitch of my nose,
Trim the trailing slash where the wild root grows.
I whisper the new link and nudge it to roam,
A 301 spring sends it safely back home.
Curl braces click as I gather files in my loam. 🐇✨

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f29708d and d03e3e5.

📒 Files selected for processing (1)
  • src/app/bitstream-page/legacy-bitstream-url-redirect.guard.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/app/bitstream-page/legacy-bitstream-url-redirect.guard.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: tests (20.x)
  • GitHub Check: tests (18.x)
  • GitHub Check: dspace-angular / docker-build (linux/amd64, ubuntu-latest, true)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/bitstream-downloading-missing-repository-prefix

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/app/bitstream-page/legacy-bitstream-url-redirect.guard.ts (1)

51-55: Add focused tests for namespace permutations.
Please add guard tests covering ui.nameSpace of: "", "/repository", "repository", "/repository/", and an absolute-like value ("http://x") to confirm sanitization and final URL.

I can draft the spec with mocks for BitstreamDataService and HardRedirectService if helpful.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8a393e3 and c1b3493.

📒 Files selected for processing (1)
  • src/app/bitstream-page/legacy-bitstream-url-redirect.guard.ts (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/app/bitstream-page/legacy-bitstream-url-redirect.guard.ts (1)
src/config/app-config.interface.ts (2)
  • AppConfig (71-71)
  • APP_CONFIG (72-72)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: dspace-angular / docker-build (linux/amd64, ubuntu-latest, true)
  • GitHub Check: tests (18.x)
  • GitHub Check: tests (20.x)
🔇 Additional comments (3)
src/app/bitstream-page/legacy-bitstream-url-redirect.guard.ts (3)

12-12: LGTM: config token import is correct.
Import path and symbols look right for AppConfig injection.


34-34: LGTM: inject(APP_CONFIG) usage in functional guard.
Consistent with existing DI pattern in this guard.


54-54: Confirm 301 usage policy.
Do we want 301 in all environments, or only in production/SSR? If not universal, gate via env flag or HardRedirectService behavior.

@Paurikova2 Paurikova2 requested a review from Copilot September 9, 2025 12:40

This comment was marked as outdated.

@Paurikova2 Paurikova2 linked an issue Sep 9, 2025 that may be closed by this pull request
@Paurikova2 Paurikova2 changed the title fix/missing-repository-prefix-for-bitstream-downloading UFAL/download-bitstreams-as-separated-api-calling Sep 9, 2025
@Paurikova2 Paurikova2 requested a review from Copilot September 9, 2025 13:52
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a bug in legacy bitstream URL redirects where redirects were missing the configured UI namespace prefix, causing broken downloads. It also updates the curl command generation to use individual bitstream downloads instead of a bulk zip approach.

  • Fixes legacy bitstream URL redirects to properly include UI namespace prefix
  • Updates curl command generation to use individual file downloads instead of zip
  • Adds debug logging for redirect URL generation

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/app/item-page/clarin-files-section/clarin-files-section.component.ts Updates curl command generation to use individual bitstream downloads instead of bulk zip
src/app/bitstream-page/legacy-bitstream-url-redirect.guard.ts Fixes redirect URL to include configured UI namespace prefix and adds debug logging

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (2)
src/app/item-page/clarin-files-section/clarin-files-section.component.ts (2)

110-114: Brace expansion is brittle with commas/braces in filenames and shell portability.

Brace lists break on commas/braces in filenames and don’t work in all shells (e.g., Windows cmd). A safer alternative is multiple URLs in one curl command.

Alternative:

const urls = this.listOfFiles.value.map((file, index) =>
  `${baseUrl}/${(file as any).sequenceId ?? index}/${encodeURIComponent(file.name)}`
);
this.command = `curl -L -OJ ${urls.join(' ')} -k`;

110-114: Avoid -k by default; make it config-driven or omit in production.

-k disables TLS verification and shouldn’t be encouraged broadly.

Example:

const insecure = this.appConfig?.ui?.allowSelfSigned === true ? ' -k' : '';
this.command = `curl -L -OJ ${baseUrl}{${fileNamesFormatted}}${insecure}`;
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0f240e6 and 62b74ce.

📒 Files selected for processing (1)
  • src/app/item-page/clarin-files-section/clarin-files-section.component.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: dspace-angular / docker-build (linux/amd64, ubuntu-latest, true)
  • GitHub Check: tests (18.x)
  • GitHub Check: tests (20.x)
🔇 Additional comments (1)
src/app/item-page/clarin-files-section/clarin-files-section.component.ts (1)

110-114: Remove sequenceId refactor suggestion. MetadataBitstream does not define a sequenceId property, so using file.sequenceId won’t compile; keeping the current index-based mapping is correct.

Likely an incorrect or invalid review comment.

@milanmajchrak milanmajchrak merged commit 326cfe6 into dtq-dev Sep 25, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix/missing-repository-prefix-for-bitstream-downloading UFAL/Download files using command line - now it is downloading all files as ZIP

4 participants