Skip to content

feat: verify if audio is reachable during conversion#1059

Merged
FyreByrd merged 8 commits into
mainfrom
fix/warn-unreachable-audio
Jul 14, 2026
Merged

feat: verify if audio is reachable during conversion#1059
FyreByrd merged 8 commits into
mainfrom
fix/warn-unreachable-audio

Conversation

@FyreByrd

@FyreByrd FyreByrd commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

Supports #1036, #992

When parsing the config, check all specified audio sources for if their associated files are reachable via the fetch API.
If one of the files fails to be fetched, the audio source has download removed as an access method and a warning is printed.
If after these checks have run, an audio source has no remaining access methods an error is thrown and conversion fails.

Notes:

  • files are fetched using the OPTIONS method to mimic the browser's preflight check (and to save bandwidth and memory).
  • I have implemented a sampling method to limit the number of requests made for each audio source.
    • The starting sample size is the square root of the total number of files associated with a given source.
    • If the sample size is less than 10, it is set to 10.
    • If the sample size is larger than the total number of files, the sample size will instead consist of all files.

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Added preflight verification for downloadable media availability, so unavailable audio/video sources are automatically disabled during config generation.
  • Bug Fixes

    • Improved chapter number, footnote/xref, and cross-reference rendering by aligning feature-flag evaluation across the app.
    • More reliable BibleBrain-based audio link resolution and safer handling of audio source identifiers.
    • Search and sidebar now consistently apply the same configuration checks as the rest of the UI.
  • Chores

    • Reused shared array/audio/media utilities to keep behavior consistent.

FyreByrd added 3 commits July 7, 2026 11:07
The full convert config process had been running twice in order to have the program type at the beginning.
@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 37bb884d-a0fd-4198-bddf-b246afb3bb89

📥 Commits

Reviewing files that changed from the base of the PR and between f002e27 and cbfe64f.

📒 Files selected for processing (4)
  • convert/convertConfig.ts
  • src/lib/scripts/arrayUtils.ts
  • src/lib/scripts/mediaUtils.ts
  • src/routes/quiz/[collection]/[id]/+page.svelte
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/lib/scripts/mediaUtils.ts
  • convert/convertConfig.ts

📝 Walkthrough

Walkthrough

This PR centralizes configuration type guards and feature lookups, adds typed audio-source and BibleBrain media utilities, refactors conversion to extract program types and verify media access, and moves quiz randomization helpers into a shared module.

Changes

Config conversion and media verification

Layer / File(s) Summary
Audio source contract
config/index.d.ts
Adds AudioSource and applies it to AudioConfig.sources.
Program type extraction and conversion branching
convert/convertConfig.ts, convert/index.ts
Extracts program type from appdef.xml, uses isDAB/isSAB branches, and derives programType directly.
Media verification and async conversion
convert/convertConfig.ts
Verifies downloadable audio and SAB video access, updates failed source access methods, and makes conversion asynchronous.

Shared configuration and audio utilities

Layer / File(s) Summary
Configuration helpers and type guards
src/lib/scripts/configUtils.ts
Makes feature resolution and hasFeature configuration-explicit and adds isSAB/isDAB.
BibleBrain media resolution
src/lib/scripts/mediaUtils.ts, src/lib/data/audio.ts
Adds shared BibleBrain URL resolution and uses it for fcbh audio paths.
Configuration predicate imports
src/lib/data/stores/setting.ts, src/lib/components/*, src/routes/+page.svelte
Moves isSAB/isDAB imports to configUtils.
Feature lookup call sites
src/lib/components/ScriptureViewSofria.svelte, src/routes/text/+page.svelte
Passes scriptureConfig explicitly to feature lookup helpers.

Shared quiz array utilities

Layer / File(s) Summary
Array helpers and quiz integration
src/lib/scripts/arrayUtils.ts, src/routes/quiz/[collection]/[id]/+page.svelte
Adds reusable random-selection and in-place shuffle helpers and uses them in quiz question and answer generation.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant convertConfig
  participant verifyMediaAvailability
  participant getBibleBrainUrl
  participant RemoteServer

  convertConfig->>verifyMediaAvailability: await verifyMediaAvailability(config, verbose)
  verifyMediaAvailability->>getBibleBrainUrl: resolve fcbh media path
  getBibleBrainUrl->>RemoteServer: fetch BibleBrain API
  RemoteServer-->>getBibleBrainUrl: path or error
  verifyMediaAvailability->>RemoteServer: fetch media URL with OPTIONS
  RemoteServer-->>verifyMediaAvailability: CORS and allowed methods
  verifyMediaAvailability-->>convertConfig: verified config or error
Loading

Possibly related PRs

Suggested reviewers: chrisvire

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding audio reachability verification during conversion.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/warn-unreachable-audio

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install timed out. The project may have too many dependencies for the sandbox.


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.

@FyreByrd
FyreByrd requested review from TheNonPirate and eomerdws July 8, 2026 22:08
@FyreByrd FyreByrd changed the title feat: verify if audio is reachable via fetch feat: verify if audio is reachable during conversion Jul 8, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 5

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@convert/convertConfig.ts`:
- Around line 1388-1422: The remote verification block in convertConfig’s
Promise.all(fetch(...)) calls is unbounded and can hang or overload hosts. Add a
timeout and limit concurrent HEAD requests for the source.media verification
path, and apply the same fix to the similar verification block referenced by the
comment. Update the logic around getBibleBrainUrl/path resolution and the
fetch(..., { method: 'HEAD' }) branch so stalled requests fail fast and large
batches are processed in controlled parallelism.
- Around line 1401-1403: The download URL construction in the `source.type ===
'download'` branch ignores `source.folder`, which can make valid `AudioSource`
entries look unreachable. Update the path-building logic in `convertConfig` to
include `source.folder` when composing the HEAD/download URL, alongside the
existing `source.address` and selected filename, so download availability checks
match the actual source layout.
- Around line 1332-1335: The verification source map in convertConfig should not
exclude `fcbh` entries just because they lack `download` in `accessMethods`,
since that bypasses the `source.type === 'fcbh'` validation path. Update the
`sources` निर्माण in the `Object.entries(config.audio?.sources ?? {})` chain so
`fcbh` sources are retained in the verification set, while keeping the existing
download-based filtering for other source types. Use the `sources` map-building
logic and the `source.type` validation branch as the key places to adjust.
- Around line 1391-1397: The BibleBrain lookup in the `getBibleBrainUrl()` call
can reject before returning an `{ error }`, so `Promise.all` aborts instead of
handling the failure per item. Update the logic around the `source.type ===
'fcbh' && v.type === 'book'` path in `convertConfig.ts` to catch rejected
lookups for each media item, set `pass = false`, and continue so the intended
access-method fallback still runs. Keep the handling localized to the existing
`getBibleBrainUrl`/`res.error` flow and preserve the current logging with the
item context (`key`, `v.collection`, `v.book`, `v.chapter`).

In `@src/lib/scripts/mediaUtils.ts`:
- Around line 16-31: The BibleBrain helper currently throws on fetch, JSON
parsing, or missing data instead of consistently returning an error object.
Update the request flow in the media utility helper that builds the BibleBrain
URL and parses the response so it catches network/parse failures and also treats
a missing data[0].path as an error case. Make the helper always resolve to the
same union shape by returning { error } for failures and only returning { path }
when the response contains a valid path.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 08d55e98-442c-4ebe-a4e2-74eaa14b1aa4

📥 Commits

Reviewing files that changed from the base of the PR and between df25c99 and f002e27.

📒 Files selected for processing (12)
  • config/index.d.ts
  • convert/convertConfig.ts
  • convert/index.ts
  • src/lib/components/ScriptureViewSofria.svelte
  • src/lib/components/SearchForm.svelte
  • src/lib/components/Sidebar.svelte
  • src/lib/data/audio.ts
  • src/lib/data/stores/setting.ts
  • src/lib/scripts/configUtils.ts
  • src/lib/scripts/mediaUtils.ts
  • src/routes/+page.svelte
  • src/routes/text/+page.svelte

Comment thread convert/convertConfig.ts
Comment thread convert/convertConfig.ts
Comment thread convert/convertConfig.ts
Comment thread convert/convertConfig.ts
Comment thread src/lib/scripts/mediaUtils.ts Outdated
@TheNonPirate

TheNonPirate commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Does this occur when running npm run convert? What sort of warning is printed? I tested this by just running npm run convert on the project that I've been working on that has some unfetchable audio, and it didn't print anything out of the ordinary (I saw no warnings about unreachable audio).

@TheNonPirate

Copy link
Copy Markdown
Contributor

I'm guessing that since npm run convert runs in the console, not the browser, it doesn't have the CORS issue, so it won't fail, meaning that it won't recognize which audio cannot be fetched.

@FyreByrd

FyreByrd commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator Author

I'm guessing that since npm run convert runs in the console, not the browser, it doesn't have the CORS issue, so it won't fail, meaning that it won't recognize which audio cannot be fetched.

Yeah... I have that concern too, but I'm not quite sure what the best workaround would be...

@TheNonPirate

Copy link
Copy Markdown
Contributor

From a bit of asking a chatbot and testing some things, it seems that response.headers.get('Access-Control-Allow-Origin') inside the fetch response returns * if CORS would allow it and null if it would not, so you could probably use that to determine whether the audio is reachable or not.

@eomerdws eomerdws left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You might consider changing that one variable name if it is a typo. Otherwise It looks good to me.

I do like moving getRandomItem and shuffleArray (with the refactored name) moved into its own exported location.

Comment thread convert/convertConfig.ts Outdated
@FyreByrd
FyreByrd merged commit 0d717bc into main Jul 14, 2026
4 checks passed
@FyreByrd
FyreByrd deleted the fix/warn-unreachable-audio branch July 14, 2026 13:43
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.

3 participants