fix: normalize user's website urls

This commit is contained in:
codytseng
2025-02-06 15:28:06 +08:00
parent 372e7a9976
commit 9af2121efe
2 changed files with 15 additions and 3 deletions

View File

@@ -15,6 +15,18 @@ export function normalizeUrl(url: string): string {
return p.toString()
}
export function normalizeHttpUrl(url: string): string {
if (url.indexOf('://') === -1) url = 'https://' + url
const p = new URL(url)
p.pathname = p.pathname.replace(/\/+/g, '/')
if (p.pathname.endsWith('/')) p.pathname = p.pathname.slice(0, -1)
if ((p.port === '80' && p.protocol === 'http:') || (p.port === '443' && p.protocol === 'https:'))
p.port = ''
p.searchParams.sort()
p.hash = ''
return p.toString()
}
export function simplifyUrl(url: string): string {
return url.replace('wss://', '').replace('ws://', '').replace(/\/$/, '')
}