mirror of
https://github.com/uetchy/namae.git
synced 2025-03-17 04:30:31 +09:00
29 lines
700 B
TypeScript
29 lines
700 B
TypeScript
import {send, sendError, fetch, NowRequest, NowResponse} from '../util/http';
|
|
|
|
export default async function handler(
|
|
req: NowRequest,
|
|
res: NowResponse,
|
|
): Promise<void> {
|
|
const {query} = req.query;
|
|
|
|
if (!query) {
|
|
return sendError(res, new Error('No query given'));
|
|
}
|
|
|
|
if (/[^a-zA-Z0-9_-]/.test(query)) {
|
|
return sendError(res, new Error('Invalid characters'));
|
|
}
|
|
|
|
try {
|
|
const response = await fetch(
|
|
`https://packages.debian.org/buster/${encodeURIComponent(query)}`,
|
|
'GET',
|
|
);
|
|
const body = await response.text();
|
|
const availability = body.includes('No such package');
|
|
send(res, {availability});
|
|
} catch (err) {
|
|
sendError(res, err);
|
|
}
|
|
}
|