mirror of
https://github.com/uetchy/namae.git
synced 2025-03-16 20:20:38 +09:00
feat: add slack
This commit is contained in:
parent
2172878abf
commit
29e4b371ea
@ -3,12 +3,13 @@ import styled, { createGlobalStyle } from 'styled-components'
|
||||
import { useDeferredState } from './hooks/state'
|
||||
import { CardHolder } from './components/Card'
|
||||
import GithubCard from './components/GithubCard'
|
||||
import DomainCard from './components/DomainCard'
|
||||
import HomebrewCard from './components/HomebrewCard'
|
||||
import TwitterCard from './components/TwitterCard'
|
||||
import SlackCard from './components/SlackCard'
|
||||
import NpmCard from './components/NpmCard'
|
||||
import JsOrgCard from './components/JsOrgCard'
|
||||
import HomebrewCard from './components/HomebrewCard'
|
||||
import PypiCard from './components/PypiCard'
|
||||
import DomainCard from './components/DomainCard'
|
||||
import './App.css'
|
||||
|
||||
const GlobalStyle = createGlobalStyle`
|
||||
@ -45,9 +46,10 @@ export default function App() {
|
||||
<ResultHeader>Result for {query}</ResultHeader>
|
||||
<CardHolder>
|
||||
<GithubCard name={query} />
|
||||
<TwitterCard name={query} />
|
||||
<DomainCard name={query} />
|
||||
<HomebrewCard name={query} />
|
||||
<TwitterCard name={query} />
|
||||
<SlackCard name={query} />
|
||||
<NpmCard name={query} />
|
||||
<JsOrgCard name={query} />
|
||||
<PypiCard name={query} />
|
||||
|
18
src/components/SlackCard.js
Normal file
18
src/components/SlackCard.js
Normal file
@ -0,0 +1,18 @@
|
||||
import React from 'react'
|
||||
import { Card, CardTitle, DedicatedAvailability } from './Card'
|
||||
import { FaSlack } from 'react-icons/fa'
|
||||
|
||||
export default function SlackCard({ name }) {
|
||||
return (
|
||||
<Card key={name}>
|
||||
<CardTitle>Slack</CardTitle>
|
||||
<DedicatedAvailability
|
||||
name={name}
|
||||
provider="slack"
|
||||
url={`https://${name}.slack.com`}
|
||||
suffix=".slack.com"
|
||||
icon={<FaSlack />}
|
||||
/>
|
||||
</Card>
|
||||
)
|
||||
}
|
31
src/services/slack.js
Normal file
31
src/services/slack.js
Normal file
@ -0,0 +1,31 @@
|
||||
const fetch = require('isomorphic-unfetch')
|
||||
|
||||
async function getAvailability(name) {
|
||||
try {
|
||||
const response = await fetch(
|
||||
`https://${encodeURIComponent(name)}.slack.com`
|
||||
)
|
||||
return response.status !== 200
|
||||
} catch (err) {
|
||||
if (err.code === 'ENOTFOUND') {
|
||||
return true
|
||||
} else {
|
||||
throw new Error(err.message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = async (req, res) => {
|
||||
const name = req.query.name
|
||||
|
||||
if (!name) {
|
||||
return res.status(400).json({ error: 'no query given' })
|
||||
}
|
||||
|
||||
try {
|
||||
const availability = await getAvailability(name)
|
||||
res.json({ availability })
|
||||
} catch (err) {
|
||||
res.status(400).json({ error: err.message })
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user