1
0
mirror of https://github.com/uetchy/namae.git synced 2025-03-17 20:40:32 +09:00
namae/api/services/debian.ts

22 lines
572 B
TypeScript
Raw Normal View History

2019-08-30 16:40:22 +09:00
import { send, sendError, fetch, NowRequest, NowResponse } from '../util/http'
2019-08-05 22:59:47 +09:00
2019-08-30 16:40:22 +09:00
export default async function handler(req: NowRequest, res: NowResponse) {
2019-08-06 01:17:45 +09:00
const { query } = req.query
2019-08-05 22:59:47 +09:00
2019-08-06 01:17:45 +09:00
if (!query) {
2019-08-05 22:59:47 +09:00
return sendError(res, new Error('no query given'))
}
try {
const response = await fetch(
2019-08-06 01:17:45 +09:00
`https://packages.debian.org/buster/${encodeURIComponent(query)}`,
2019-08-05 22:59:47 +09:00
'GET'
)
const body = await response.text()
const availability = body.includes('No such package')
2019-08-06 01:17:45 +09:00
send(res, { availability })
2019-08-05 22:59:47 +09:00
} catch (err) {
sendError(res, err)
}
}