mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-19 18:45:15 +02:00
fix(web): extract single tryGetHostname helper (DRY, unified fallback)
Fixes #1368 Previously, was duplicated in 4 places with 3 subtly different fallback behaviors: 1. inline-citation.tsx: returned on error 2. markdown-text.tsx: returned on error 3. assistant-message.tsx: returned on error 4. citation.tsx: returned on error Created canonical in that: - Returns - Strips prefix from hostname - Returns on invalid URL (safest contract) Updated all 4 call sites: - inline-citation.tsx: (preserves original fallback) - markdown-text.tsx: (preserves original fallback) - assistant-message.tsx: (drop-in, both return ) - citation.tsx: (drop-in, both return ) Co-authored-by: guangyang1206 <guangyang1206@users.noreply.github.com>
This commit is contained in:
parent
1119f557df
commit
f096548a16
5 changed files with 24 additions and 38 deletions
14
surfsense_web/lib/url.ts
Normal file
14
surfsense_web/lib/url.ts
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
/**
|
||||
* Extract a normalized hostname from a URL. Strips a leading `www.`.
|
||||
* Returns `undefined` if the input is not a parseable URL.
|
||||
*
|
||||
* This is the canonical replacement for the four previously-duplicated
|
||||
* `extractDomain` helpers that had subtly different error fallbacks.
|
||||
*/
|
||||
export function tryGetHostname(url: string): string | undefined {
|
||||
try {
|
||||
return new URL(url).hostname.replace(/^www\./, "");
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue