mirror of
https://github.com/uetchy/namae.git
synced 2025-08-20 01:48:12 +09:00
feat: spectrum
This commit is contained in:
23
api/services/spectrum.js
Normal file
23
api/services/spectrum.js
Normal file
@@ -0,0 +1,23 @@
|
||||
const { send, sendError, fetch } = require('../util/http')
|
||||
|
||||
module.exports = async (req, res) => {
|
||||
const { query } = req.query
|
||||
|
||||
if (!query) {
|
||||
return sendError(res, new Error('no query given'))
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user