mirror of
https://github.com/uetchy/namae.git
synced 2025-08-20 01:48:12 +09:00
feat: Heroku and Now
This commit is contained in:
@@ -4,7 +4,7 @@ module.exports = async (req, res) => {
|
||||
const { query, country } = req.query
|
||||
|
||||
if (!query) {
|
||||
return res.status(400).json({ error: 'no query given' })
|
||||
return sendError(res, new Error('no query given'))
|
||||
}
|
||||
|
||||
const term = encodeURIComponent(query)
|
||||
|
@@ -1,19 +0,0 @@
|
||||
const { send, sendError, fetch } = require('../util/http')
|
||||
|
||||
module.exports = async (req, res) => {
|
||||
const { query } = req.query
|
||||
|
||||
if (!query) {
|
||||
return res.status(400).json({ error: 'no query given' })
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(
|
||||
`https://crates.io/api/v1/crates/${encodeURIComponent(query)}`
|
||||
)
|
||||
const availability = response.status !== 200
|
||||
send(res, { availability })
|
||||
} catch (err) {
|
||||
sendError(res, err)
|
||||
}
|
||||
}
|
25
api/services/existence.js
Normal file
25
api/services/existence.js
Normal file
@@ -0,0 +1,25 @@
|
||||
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'))
|
||||
}
|
||||
|
||||
if (
|
||||
!/^[(http(s)?):\/\/(www\.)?a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)$/.test(
|
||||
query
|
||||
)
|
||||
) {
|
||||
return sendError(res, new Error('invalid characters'))
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(`https://${query}`)
|
||||
const availability = response.status === 404
|
||||
send(res, { availability })
|
||||
} catch (err) {
|
||||
sendError(res, err)
|
||||
}
|
||||
}
|
@@ -1,13 +1,15 @@
|
||||
import provider from './github'
|
||||
import provider from './existence'
|
||||
import nock from 'nock'
|
||||
|
||||
test('return false if name is taken', async () => {
|
||||
const result = await mockProvider(provider, { query: 'uetchy' })
|
||||
const result = await mockProvider(provider, { query: 'github.com/uetchy' })
|
||||
expect(result).toStrictEqual({ availability: false })
|
||||
})
|
||||
|
||||
test('return true if name is not taken', async () => {
|
||||
const result = await mockProvider(provider, { query: 'uetchyasdf' })
|
||||
const result = await mockProvider(provider, {
|
||||
query: 'github.com/uetchyasdf',
|
||||
})
|
||||
expect(result).toStrictEqual({ availability: true })
|
||||
})
|
||||
|
@@ -1,19 +0,0 @@
|
||||
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://github.com/${encodeURIComponent(query)}`
|
||||
)
|
||||
const availability = response.status !== 200
|
||||
send(res, { availability })
|
||||
} catch (err) {
|
||||
sendError(res, err)
|
||||
}
|
||||
}
|
@@ -1,19 +0,0 @@
|
||||
const { send, sendError, fetch } = require('../util/http')
|
||||
const googleIt = require('google-it')
|
||||
|
||||
module.exports = async (req, res) => {
|
||||
const { query } = req.query
|
||||
|
||||
return send(res, { result: [] }) // DISABLE
|
||||
|
||||
if (!query) {
|
||||
return res.status(400).json({ error: 'no query given' })
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await googleIt({ query: query })
|
||||
send(res, { result: result || [] })
|
||||
} catch (err) {
|
||||
sendError(res, err)
|
||||
}
|
||||
}
|
@@ -1,19 +0,0 @@
|
||||
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://pypi.org/pypi/${encodeURIComponent(query)}/json`
|
||||
)
|
||||
const availability = response.status !== 200
|
||||
send(res, { availability })
|
||||
} catch (err) {
|
||||
sendError(res, err)
|
||||
}
|
||||
}
|
@@ -1,19 +0,0 @@
|
||||
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://rubygems.org/gems/${encodeURIComponent(query)}`
|
||||
)
|
||||
const availability = response.status !== 200
|
||||
send(res, { availability })
|
||||
} catch (err) {
|
||||
sendError(res, err)
|
||||
}
|
||||
}
|
@@ -1,19 +0,0 @@
|
||||
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://${encodeURIComponent(query)}.s3.amazonaws.com`
|
||||
)
|
||||
const availability = response.status !== 200
|
||||
send(res, { availability })
|
||||
} catch (err) {
|
||||
sendError(res, err)
|
||||
}
|
||||
}
|
@@ -1,21 +0,0 @@
|
||||
const { send, sendError, fetch } = require('../util/http')
|
||||
|
||||
async function getAvailability(name) {}
|
||||
|
||||
module.exports = async (req, res) => {
|
||||
const { query } = req.query
|
||||
|
||||
if (!query) {
|
||||
return res.status(400).json({ error: 'no query given' })
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(
|
||||
`https://twitter.com/${encodeURIComponent(query)}`
|
||||
)
|
||||
const availability = response.status !== 200
|
||||
send(res, { availability })
|
||||
} catch (err) {
|
||||
sendError(res, err)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user