mirror of
https://github.com/uetchy/namae.git
synced 2025-07-02 06:20:02 +09:00
feat: add AWS S3
This commit is contained in:
parent
fd7ba06cf5
commit
c2a1e281df
@ -10,6 +10,7 @@ import SlackCard from './components/SlackCard'
|
|||||||
import NpmCard from './components/NpmCard'
|
import NpmCard from './components/NpmCard'
|
||||||
import JsOrgCard from './components/JsOrgCard'
|
import JsOrgCard from './components/JsOrgCard'
|
||||||
import PypiCard from './components/PypiCard'
|
import PypiCard from './components/PypiCard'
|
||||||
|
import S3Card from './components/S3Card'
|
||||||
import './App.css'
|
import './App.css'
|
||||||
|
|
||||||
const GlobalStyle = createGlobalStyle`
|
const GlobalStyle = createGlobalStyle`
|
||||||
@ -53,6 +54,7 @@ export default function App() {
|
|||||||
<NpmCard name={query} />
|
<NpmCard name={query} />
|
||||||
<JsOrgCard name={query} />
|
<JsOrgCard name={query} />
|
||||||
<PypiCard name={query} />
|
<PypiCard name={query} />
|
||||||
|
<S3Card name={query} />
|
||||||
</CardHolder>
|
</CardHolder>
|
||||||
</Result>
|
</Result>
|
||||||
) : null}
|
) : null}
|
||||||
|
18
src/components/S3Card.js
Normal file
18
src/components/S3Card.js
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import { Card, CardTitle, DedicatedAvailability } from './Card'
|
||||||
|
import { FaAws } from 'react-icons/fa'
|
||||||
|
|
||||||
|
export default function S3Card({ name }) {
|
||||||
|
return (
|
||||||
|
<Card key={name}>
|
||||||
|
<CardTitle>AWS S3</CardTitle>
|
||||||
|
<DedicatedAvailability
|
||||||
|
name={name}
|
||||||
|
provider="s3"
|
||||||
|
url={`https://${name}.s3.amazonaws.com`}
|
||||||
|
suffix=".s3.amazonaws.com"
|
||||||
|
icon={<FaAws />}
|
||||||
|
/>
|
||||||
|
</Card>
|
||||||
|
)
|
||||||
|
}
|
23
src/services/s3.js
Normal file
23
src/services/s3.js
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
const fetch = require('isomorphic-unfetch')
|
||||||
|
|
||||||
|
async function getAvailability(name) {
|
||||||
|
const response = await fetch(
|
||||||
|
`https://${encodeURIComponent(name)}.s3.amazonaws.com`
|
||||||
|
)
|
||||||
|
return response.status !== 200
|
||||||
|
}
|
||||||
|
|
||||||
|
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