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

31 lines
749 B
TypeScript
Raw Normal View History

2020-08-31 08:41:53 +09:00
import { send, sendError, fetch } from '../../../util/http';
import { NowRequest, NowResponse } from '@vercel/node';
2019-08-05 22:59:47 +09:00
2019-12-24 01:57:07 +09:00
export default async function handler(
req: NowRequest,
2020-08-20 00:57:33 +09:00
res: NowResponse
2019-12-24 01:57:07 +09:00
): Promise<void> {
2020-08-31 08:41:53 +09:00
const { query } = req.query;
2019-08-05 22:59:47 +09:00
2020-06-19 16:15:53 +09:00
if (!query || typeof query !== 'string') {
2020-08-31 08:41:53 +09:00
return sendError(res, new Error('No query given'));
2019-12-10 18:33:39 +09:00
}
if (/[^a-zA-Z0-9_-]/.test(query)) {
2020-08-31 08:41:53 +09:00
return sendError(res, new Error('Invalid characters'));
2019-08-05 22:59:47 +09:00
}
try {
const response = await fetch(
`https://api.launchpad.net/devel/ubuntu/+source/${encodeURIComponent(
2020-08-20 00:57:33 +09:00
query
2019-08-05 22:59:47 +09:00
)}`,
2020-08-20 00:57:33 +09:00
'GET'
2020-08-31 08:41:53 +09:00
);
const availability = response.status !== 200;
send(res, { availability });
2019-08-05 22:59:47 +09:00
} catch (err) {
2020-08-31 08:41:53 +09:00
sendError(res, err);
2019-08-05 22:59:47 +09:00
}
}