fix: catch some errors
This commit is contained in:
@@ -333,12 +333,16 @@ export function extractEmbeddedEventIds(event: Event) {
|
|||||||
const embeddedEventIds: string[] = []
|
const embeddedEventIds: string[] = []
|
||||||
const embeddedNoteRegex = /nostr:(note1[a-z0-9]{58}|nevent1[a-z0-9]+)/g
|
const embeddedNoteRegex = /nostr:(note1[a-z0-9]{58}|nevent1[a-z0-9]+)/g
|
||||||
;(event.content.match(embeddedNoteRegex) || []).forEach((note) => {
|
;(event.content.match(embeddedNoteRegex) || []).forEach((note) => {
|
||||||
|
try {
|
||||||
const { type, data } = nip19.decode(note.split(':')[1])
|
const { type, data } = nip19.decode(note.split(':')[1])
|
||||||
if (type === 'nevent') {
|
if (type === 'nevent') {
|
||||||
embeddedEventIds.push(data.id)
|
embeddedEventIds.push(data.id)
|
||||||
} else if (type === 'note') {
|
} else if (type === 'note') {
|
||||||
embeddedEventIds.push(data)
|
embeddedEventIds.push(data)
|
||||||
}
|
}
|
||||||
|
} catch {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
})
|
})
|
||||||
EVENT_EMBEDDED_EVENT_IDS_CACHE.set(event.id, embeddedEventIds)
|
EVENT_EMBEDDED_EVENT_IDS_CACHE.set(event.id, embeddedEventIds)
|
||||||
return embeddedEventIds
|
return embeddedEventIds
|
||||||
|
|||||||
@@ -16,15 +16,23 @@ export function normalizeUrl(url: string): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function normalizeHttpUrl(url: string): string {
|
export function normalizeHttpUrl(url: string): string {
|
||||||
|
try {
|
||||||
if (url.indexOf('://') === -1) url = 'https://' + url
|
if (url.indexOf('://') === -1) url = 'https://' + url
|
||||||
const p = new URL(url)
|
const p = new URL(url)
|
||||||
p.pathname = p.pathname.replace(/\/+/g, '/')
|
p.pathname = p.pathname.replace(/\/+/g, '/')
|
||||||
if (p.pathname.endsWith('/')) p.pathname = p.pathname.slice(0, -1)
|
if (p.pathname.endsWith('/')) p.pathname = p.pathname.slice(0, -1)
|
||||||
if ((p.port === '80' && p.protocol === 'http:') || (p.port === '443' && p.protocol === 'https:'))
|
if (
|
||||||
|
(p.port === '80' && p.protocol === 'http:') ||
|
||||||
|
(p.port === '443' && p.protocol === 'https:')
|
||||||
|
)
|
||||||
p.port = ''
|
p.port = ''
|
||||||
p.searchParams.sort()
|
p.searchParams.sort()
|
||||||
p.hash = ''
|
p.hash = ''
|
||||||
return p.toString()
|
return p.toString()
|
||||||
|
} catch {
|
||||||
|
console.error('Invalid URL:', url)
|
||||||
|
return url
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function simplifyUrl(url: string): string {
|
export function simplifyUrl(url: string): string {
|
||||||
|
|||||||
Reference in New Issue
Block a user