improve url validation
This commit is contained in:
@@ -12,8 +12,21 @@ type CheckResponse = {
|
|||||||
|
|
||||||
function extractDomain(url: string): string {
|
function extractDomain(url: string): string {
|
||||||
try {
|
try {
|
||||||
const urlObj = new URL(url)
|
// Clean up the URL first
|
||||||
return urlObj.hostname.replace('www.', '')
|
let cleanUrl = url.trim()
|
||||||
|
if (!cleanUrl.startsWith('http://') && !cleanUrl.startsWith('https://')) {
|
||||||
|
cleanUrl = 'https://' + cleanUrl
|
||||||
|
}
|
||||||
|
|
||||||
|
const urlObj = new URL(cleanUrl)
|
||||||
|
let domain = urlObj.hostname.toLowerCase()
|
||||||
|
|
||||||
|
// Remove common prefixes
|
||||||
|
domain = domain.replace(/^www\./, '')
|
||||||
|
domain = domain.replace(/^m\./, '')
|
||||||
|
domain = domain.replace(/^mobile\./, '')
|
||||||
|
|
||||||
|
return domain
|
||||||
} catch {
|
} catch {
|
||||||
return ''
|
return ''
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user