1
0
mirror of https://github.com/uetchy/namae.git synced 2025-03-18 04:50:32 +09:00
namae/api/services/spectrum.ts

24 lines
607 B
TypeScript
Raw Normal View History

2019-08-30 16:40:22 +09:00
import { send, sendError, fetch, NowResponse, NowRequest } from '../util/http'
2019-08-14 15:13:57 +09:00
2019-08-30 16:40:22 +09:00
export default async function handler(req: NowRequest, res: NowResponse) {
2019-08-14 15:13:57 +09:00
const { query } = req.query
if (!query) {
return sendError(res, new Error('no query given'))
}
try {
const response = await fetch(
`https://spectrum.chat/${encodeURIComponent(query)}`,
'GET'
)
const body = await response.text()
const availability = body.includes(
'You may be trying to view something that is deleted'
)
send(res, { availability })
} catch (err) {
sendError(res, err)
}
}