mirror of
https://github.com/oceanprotocol/ens-proxy.git
synced 2024-11-15 01:35:14 +01:00
43 lines
1.0 KiB
TypeScript
43 lines
1.0 KiB
TypeScript
import type { VercelRequest, VercelResponse } from '@vercel/node'
|
|
import { getProvider } from './_utils'
|
|
|
|
export async function getEnsTextRecords(
|
|
ensName: string
|
|
): Promise<{ key: string; value: string }[]> {
|
|
const texts = [
|
|
'url',
|
|
'com.twitter',
|
|
'com.github',
|
|
'org.telegram',
|
|
'com.discord',
|
|
'com.reddit'
|
|
]
|
|
|
|
const records = []
|
|
const provider = await getProvider()
|
|
const resolver = await provider.getResolver(ensName)
|
|
|
|
for (let index = 0; index < texts?.length; index++) {
|
|
const key = texts[index]
|
|
const value = await resolver.getText(key)
|
|
value && records.push({ key, value })
|
|
}
|
|
|
|
return records
|
|
}
|
|
|
|
export default async function ensTextApi(
|
|
request: VercelRequest,
|
|
response: VercelResponse
|
|
) {
|
|
try {
|
|
const ensName = String(request.query.name)
|
|
const records = await getEnsTextRecords(ensName)
|
|
|
|
response.setHeader('Cache-Control', 'max-age=0, s-maxage=86400')
|
|
response.status(200).send(records)
|
|
} catch (error) {
|
|
response.status(500).send(`${error}`)
|
|
}
|
|
}
|