mirror of
https://github.com/uetchy/namae.git
synced 2025-03-17 20:40:32 +09:00
31 lines
736 B
TypeScript
31 lines
736 B
TypeScript
import {send, sendError, fetch, NowResponse, NowRequest} 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://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);
|
|
}
|
|
}
|