feat: add hint to e tags
This commit is contained in:
@@ -31,6 +31,47 @@ export function simplifyUrl(url: string): string {
|
||||
return url.replace('wss://', '').replace('ws://', '').replace(/\/$/, '')
|
||||
}
|
||||
|
||||
export function isLocalNetworkUrl(urlString: string): boolean {
|
||||
try {
|
||||
const url = new URL(urlString)
|
||||
const hostname = url.hostname
|
||||
|
||||
// Check if it's localhost
|
||||
if (hostname === 'localhost' || hostname === '::1') {
|
||||
return true
|
||||
}
|
||||
|
||||
// Check if it's an IPv4 local network address
|
||||
const ipv4Match = hostname.match(/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/)
|
||||
if (ipv4Match) {
|
||||
const [, a, b, c, d] = ipv4Match.map(Number)
|
||||
return (
|
||||
a === 10 ||
|
||||
(a === 172 && b >= 16 && b <= 31) ||
|
||||
(a === 192 && b === 168) ||
|
||||
(a === 127 && b === 0 && c === 0 && d === 1)
|
||||
)
|
||||
}
|
||||
|
||||
// Check if it's an IPv6 address
|
||||
if (hostname.includes(':')) {
|
||||
if (hostname === '::1') {
|
||||
return true // IPv6 loopback address
|
||||
}
|
||||
if (hostname.startsWith('fe80:')) {
|
||||
return true // Link-local address
|
||||
}
|
||||
if (hostname.startsWith('fc') || hostname.startsWith('fd')) {
|
||||
return true // Unique local address (ULA)
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
} catch {
|
||||
return false // Return false for invalid URLs
|
||||
}
|
||||
}
|
||||
|
||||
export function isImage(url: string) {
|
||||
try {
|
||||
const imageExtensions = ['.jpg', '.jpeg', '.png', '.gif', '.webp', '.heic', '.svg']
|
||||
|
||||
Reference in New Issue
Block a user