mirror of
https://github.com/nbd-wtf/nostr-tools.git
synced 2025-12-11 09:38:51 +00:00
use default fetch if in service worker (#23)
This commit is contained in:
12
nip05.js
12
nip05.js
@@ -1,9 +1,12 @@
|
|||||||
import fetch from 'cross-fetch'
|
import crossFetch from 'cross-fetch'
|
||||||
|
|
||||||
|
const f = (typeof XMLHttpRequest == 'function')
|
||||||
|
? crossFetch
|
||||||
|
: fetch
|
||||||
export async function searchDomain(domain, query = '') {
|
export async function searchDomain(domain, query = '') {
|
||||||
try {
|
try {
|
||||||
let res = await (
|
let res = await (
|
||||||
await fetch(`https://${domain}/.well-known/nostr.json?name=${query}`)
|
await f(`https://${domain}/.well-known/nostr.json?name=${query}`)
|
||||||
).json()
|
).json()
|
||||||
|
|
||||||
return res.names
|
return res.names
|
||||||
@@ -18,11 +21,12 @@ export async function queryName(fullname) {
|
|||||||
if (!domain) return null
|
if (!domain) return null
|
||||||
|
|
||||||
let res = await (
|
let res = await (
|
||||||
await fetch(`https://${domain}/.well-known/nostr.json?name=${name}`)
|
await f(`https://${domain}/.well-known/nostr.json?name=${name}`)
|
||||||
).json()
|
).json()
|
||||||
|
|
||||||
return res.names && res.names[name]
|
return res.names && res.names[name]
|
||||||
} catch (_) {
|
} catch (e) {
|
||||||
|
console.error(`${e}`)
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user