fix: filter out onion relay reviews on browsers without onion support
This commit is contained in:
@@ -1,5 +1,10 @@
|
|||||||
export function isWebsocketUrl(url: string): boolean {
|
export function isWebsocketUrl(url: string): boolean {
|
||||||
return /^wss?:\/\/.+$/.test(url)
|
try {
|
||||||
|
const protocol = new URL(url).protocol
|
||||||
|
return protocol === 'ws:' || protocol === 'wss:'
|
||||||
|
} catch {
|
||||||
|
return false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isOnionUrl(url: string): boolean {
|
export function isOnionUrl(url: string): boolean {
|
||||||
|
|||||||
@@ -6,7 +6,9 @@ import { Button } from '@/components/ui/button'
|
|||||||
import { BIG_RELAY_URLS, ExtendedKind } from '@/constants'
|
import { BIG_RELAY_URLS, ExtendedKind } from '@/constants'
|
||||||
import PrimaryPageLayout from '@/layouts/PrimaryPageLayout'
|
import PrimaryPageLayout from '@/layouts/PrimaryPageLayout'
|
||||||
import { getReplaceableEventIdentifier } from '@/lib/event'
|
import { getReplaceableEventIdentifier } from '@/lib/event'
|
||||||
|
import { isLocalNetworkUrl, isOnionUrl, isWebsocketUrl } from '@/lib/url'
|
||||||
import { useUserTrust } from '@/providers/UserTrustProvider'
|
import { useUserTrust } from '@/providers/UserTrustProvider'
|
||||||
|
import storage from '@/services/local-storage.service'
|
||||||
import { TPageRef } from '@/types'
|
import { TPageRef } from '@/types'
|
||||||
import { Compass, Plus } from 'lucide-react'
|
import { Compass, Plus } from 'lucide-react'
|
||||||
import { NostrEvent } from 'nostr-tools'
|
import { NostrEvent } from 'nostr-tools'
|
||||||
@@ -24,12 +26,16 @@ const ExplorePage = forwardRef<TPageRef>((_, ref) => {
|
|||||||
const d = getReplaceableEventIdentifier(evt)
|
const d = getReplaceableEventIdentifier(evt)
|
||||||
if (!d) return false
|
if (!d) return false
|
||||||
|
|
||||||
try {
|
if (!isWebsocketUrl(d)) {
|
||||||
const url = new URL(d)
|
|
||||||
return url.hostname !== 'localhost'
|
|
||||||
} catch {
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
if (isLocalNetworkUrl(d)) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if (storage.getFilterOutOnionRelays() && isOnionUrl(d)) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
const content = useMemo(() => {
|
const content = useMemo(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user