-
Notifications
You must be signed in to change notification settings - Fork 0
Allow localhost in audio proxy #222
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 |
|---|---|---|
|
|
@@ -392,7 +392,12 @@ const LEVEL_INFO = { | |
| * @returns {string} 套用 Proxy 後的網址,或原網址。 | ||
| */ | ||
| function applyAudioProxy(url) { | ||
| if (!url || !url.startsWith('https://elearning.hakka.gov.tw/')) { | ||
| if (!url) return url; | ||
|
|
||
| const isHakkaGov = url.startsWith('https://elearning.hakka.gov.tw/'); | ||
| const isLocalhost = /^https?:\/\/localhost([:/]|$)/.test(url); | ||
|
Comment on lines
+397
to
+398
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This validation logic, including the domain string and regex, is duplicated from |
||
|
|
||
| if (!isHakkaGov && !isLocalhost) { | ||
| return url; | ||
| } | ||
| // 在本機開發或特定測試環境下,可能需要根據環境調整路徑 | ||
|
|
||
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.
To improve maintainability and avoid duplicating magic strings and regexes, consider defining the allowed domain and the localhost regex as constants. This logic is also duplicated in
main.js. If possible, creating a shared utility function likeisAllowedAudioUrl(url)would be even better to ensure consistency between client and server validation.