1
0
mirror of https://github.com/uetchy/namae.git synced 2025-03-18 21:10:32 +09:00

24 lines
611 B
TypeScript
Raw Normal View History

2019-09-17 14:30:26 +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-09-17 14:30:26 +09:00
const {query} = req.query;
2019-08-14 15:13:57 +09:00
if (!query) {
2019-09-17 14:30:26 +09:00
return sendError(res, new Error('no query given'));
2019-08-14 15:13:57 +09:00
}
try {
const response = await fetch(
`https://spectrum.chat/${encodeURIComponent(query)}`,
2019-09-17 14:30:26 +09:00
'GET',
);
const body = await response.text();
2019-08-14 15:13:57 +09:00
const availability = body.includes(
2019-09-17 14:30:26 +09:00
'You may be trying to view something that is deleted',
);
send(res, {availability});
2019-08-14 15:13:57 +09:00
} catch (err) {
2019-09-17 14:30:26 +09:00
sendError(res, err);
2019-08-14 15:13:57 +09:00
}
}