mirror of
https://github.com/oceanprotocol/ens-proxy.git
synced 2024-11-15 09:45:02 +01:00
27 lines
797 B
TypeScript
27 lines
797 B
TypeScript
import { NextApiRequest, NextApiResponse } from 'next'
|
|
import { getEns } from './_utils'
|
|
|
|
export async function getEnsName(accountId: string) {
|
|
const ens = await getEns()
|
|
let name = await ens.getName(accountId)
|
|
|
|
// Check to be sure the reverse record is correct.
|
|
const reverseAccountId = await ens.name(name.name).getAddress()
|
|
if (accountId.toLowerCase() !== reverseAccountId.toLowerCase()) name = null
|
|
return name
|
|
}
|
|
|
|
export default async function nameApi(
|
|
request: NextApiRequest,
|
|
response: NextApiResponse
|
|
) {
|
|
try {
|
|
const accountId = String(request.query.accountId)
|
|
const name = await getEnsName(accountId)
|
|
response.setHeader('Cache-Control', 's-maxage=86400')
|
|
response.status(200).send(name)
|
|
} catch (error) {
|
|
response.status(500).send(`${error}`)
|
|
}
|
|
}
|