mirror of
https://github.com/uetchy/namae.git
synced 2025-08-20 09:58:13 +09:00
feat: add archlinux
This commit is contained in:
28
api/services/archlinux/[query].ts
Normal file
28
api/services/archlinux/[query].ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { send, sendError, fetch } from '../../../util/http';
|
||||
import { NowRequest, NowResponse } from '@vercel/node';
|
||||
|
||||
export default async function handler(
|
||||
req: NowRequest,
|
||||
res: NowResponse
|
||||
): Promise<void> {
|
||||
const { query } = req.query;
|
||||
|
||||
if (!query || typeof query !== 'string') {
|
||||
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://archlinux.org/packages/?sort=&q=${encodeURIComponent(query)}`,
|
||||
'GET'
|
||||
).then((res) => res.text());
|
||||
const availability = !/<div id="exact-matches"/.test(response);
|
||||
send(res, { availability });
|
||||
} catch (err) {
|
||||
sendError(res, err);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user