-
Notifications
You must be signed in to change notification settings - Fork 11
fix(audio): verse recitation URLs should return absolute paths, not relative #45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,33 @@ type GetVerseRecitationOptions = BaseApiParams & { | |
| fields?: Partial<Record<VerseRecitationField, boolean>>; | ||
| }; | ||
|
|
||
| /** | ||
| * Base URL for verse audio files from Quran.com | ||
| * Used to convert relative paths to absolute URLs | ||
| */ | ||
| const AUDIO_BASE_URL = "https://verses.quran.com"; | ||
|
|
||
| /** | ||
| * Normalize verse recitation data by adding absolute audioUrl | ||
| * The API returns relative paths in the 'url' field, but we want | ||
| * to provide absolute URLs for consistency with chapter recitations | ||
| */ | ||
| function normalizeVerseRecitations( | ||
| audioFiles: VerseRecitation[], | ||
| ): VerseRecitation[] { | ||
| return audioFiles.map((file) => { | ||
| // If url is already absolute, use it; otherwise prepend the base URL | ||
| const absoluteUrl = file.url.startsWith("http") | ||
| ? file.url | ||
| : `${AUDIO_BASE_URL}/${file.url}`; | ||
|
|
||
|
Comment on lines
+31
to
+39
|
||
| return { | ||
| ...file, | ||
| audioUrl: absoluteUrl, | ||
| }; | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Audio API methods | ||
| */ | ||
|
|
@@ -86,7 +113,10 @@ export class QuranAudio { | |
| options, | ||
| ); | ||
|
|
||
| return data; | ||
| return { | ||
| ...data, | ||
| audioFiles: normalizeVerseRecitations(data.audioFiles), | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -109,6 +139,9 @@ export class QuranAudio { | |
| pagination: Pagination; | ||
| }>(`/content/api/v4/recitations/${recitationId}/by_ayah/${key}`, options); | ||
|
|
||
| return data; | ||
| return { | ||
| ...data, | ||
| audioFiles: normalizeVerseRecitations(data.audioFiles), | ||
| }; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -11,7 +11,10 @@ export interface ChapterRecitation { | |||||
|
|
||||||
| export interface VerseRecitation { | ||||||
| verseKey: VerseKey; | ||||||
| /** Relative URL path (e.g., "AbdulBaset/Murattal/mp3/002255.mp3") */ | ||||||
| url: string; | ||||||
| /** Absolute URL (e.g., "https://download.quranicaudio.com/qdc/AbdulBaset/Murattal/mp3/002255.mp3") */ | ||||||
|
||||||
| /** Absolute URL (e.g., "https://download.quranicaudio.com/qdc/AbdulBaset/Murattal/mp3/002255.mp3") */ | |
| /** Absolute URL (e.g., "https://verses.quran.com/AbdulBaset/Murattal/mp3/002255.mp3") */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The normalization logic has an untested branch when
file.urlis already absolute (startsWith("http")). Adding a test case for an already-absoluteurlwould help prevent regressions and clarify expected behavior (e.g., whetheraudioUrlshould equalurlin that case).