mirror of
https://github.com/uetchy/namae.git
synced 2025-03-17 12:30:32 +09:00
feat: add nta
This commit is contained in:
parent
f2e45bac4b
commit
b07b597d2e
94
api/services/nta.ts
Normal file
94
api/services/nta.ts
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
import { send, sendError, fetch, NowRequest, NowResponse } from '../util/http'
|
||||||
|
|
||||||
|
const APPLICATION_ID = process.env.NTA_APPLICATION_ID
|
||||||
|
|
||||||
|
export default async function handler(
|
||||||
|
req: NowRequest<{ query: string; country: string }>,
|
||||||
|
res: NowResponse
|
||||||
|
) {
|
||||||
|
const { query } = req.query
|
||||||
|
|
||||||
|
if (!query) {
|
||||||
|
return sendError(res, new Error('no query given'))
|
||||||
|
}
|
||||||
|
|
||||||
|
const encodedQuery = encodeURIComponent(
|
||||||
|
query.replace(/[A-Za-z0-9]/g, (str) =>
|
||||||
|
String.fromCharCode(str.charCodeAt(0) + 0xfee0)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch(
|
||||||
|
`https://api.houjin-bangou.nta.go.jp/4/name?id=${APPLICATION_ID}&name=${encodedQuery}&mode=1&target=1&type=02`,
|
||||||
|
'GET'
|
||||||
|
)
|
||||||
|
const body: string[] = (await response.text()).split('\n').slice(0, -1)
|
||||||
|
const header = body.shift()!.split(',')
|
||||||
|
const result = body.map((csv) => {
|
||||||
|
const entry = csv.split(',').map((item) =>
|
||||||
|
item
|
||||||
|
.replace(/(^"|"$)/g, '')
|
||||||
|
.replace(/[A-Za-z0-9]/g, (str) =>
|
||||||
|
String.fromCharCode(str.charCodeAt(0) - 0xfee0)
|
||||||
|
)
|
||||||
|
.replace(/ /g, ' ')
|
||||||
|
)
|
||||||
|
|
||||||
|
return {
|
||||||
|
index: entry[0],
|
||||||
|
orgID: entry[1],
|
||||||
|
name: entry[6],
|
||||||
|
englishName: entry[24],
|
||||||
|
phoneticName: entry[28],
|
||||||
|
type: entry[8],
|
||||||
|
created: entry[22],
|
||||||
|
lastUpdate: entry[4],
|
||||||
|
lastModified: entry[5],
|
||||||
|
imageID: entry[7],
|
||||||
|
location: {
|
||||||
|
pref: entry[9],
|
||||||
|
city: entry[10],
|
||||||
|
address: entry[11],
|
||||||
|
imageID: entry[12],
|
||||||
|
prefCode: entry[13],
|
||||||
|
cityCode: entry[14],
|
||||||
|
postalCode: entry[15],
|
||||||
|
englishPref: entry[25],
|
||||||
|
englishAddress: entry[26],
|
||||||
|
},
|
||||||
|
foreignLocation: {
|
||||||
|
address: entry[16],
|
||||||
|
imageID: entry[17],
|
||||||
|
englishForeignLocation: entry[27],
|
||||||
|
},
|
||||||
|
historyCount: entry[23],
|
||||||
|
closedAt: entry[18],
|
||||||
|
closedReason: entry[19],
|
||||||
|
successorOrgID: entry[20],
|
||||||
|
memo: entry[21],
|
||||||
|
excluded: entry[29],
|
||||||
|
processSection: entry[2],
|
||||||
|
modifiedSection: entry[3],
|
||||||
|
}
|
||||||
|
})
|
||||||
|
console.log(header)
|
||||||
|
|
||||||
|
send(res, {
|
||||||
|
meta: {
|
||||||
|
lastUpdate: header[0],
|
||||||
|
count: parseInt(header[1]),
|
||||||
|
cursor: parseInt(header[2]),
|
||||||
|
pages: parseInt(header[3]),
|
||||||
|
},
|
||||||
|
result:
|
||||||
|
result.map((entry) => ({
|
||||||
|
name: entry.name,
|
||||||
|
phoneticName: entry.phoneticName,
|
||||||
|
englishName: entry.englishName,
|
||||||
|
})) || [],
|
||||||
|
})
|
||||||
|
} catch (err) {
|
||||||
|
sendError(res, err)
|
||||||
|
}
|
||||||
|
}
|
5
now.json
5
now.json
@ -22,5 +22,8 @@
|
|||||||
"src": "/(.*)",
|
"src": "/(.*)",
|
||||||
"dest": "/web/$1"
|
"dest": "/web/$1"
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
"env": {
|
||||||
|
"NTA_APPLICATION_ID": "@namae-nta-application-id"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,9 +20,11 @@
|
|||||||
"google": "Google Search",
|
"google": "Google Search",
|
||||||
"spectrum": "Spectrum",
|
"spectrum": "Spectrum",
|
||||||
"heroku": "Heroku",
|
"heroku": "Heroku",
|
||||||
"now": "ZEIT Now"
|
"now": "ZEIT Now",
|
||||||
|
"nta": "Company (JP)"
|
||||||
},
|
},
|
||||||
"countryCode": "us",
|
"countryCode": "us",
|
||||||
"try": "suggestions",
|
"try": "suggestions",
|
||||||
"showMore": "show more"
|
"showMore": "show more",
|
||||||
|
"noResult": "No Result"
|
||||||
}
|
}
|
||||||
|
@ -20,9 +20,11 @@
|
|||||||
"google": "Google 検索",
|
"google": "Google 検索",
|
||||||
"spectrum": "Spectrum",
|
"spectrum": "Spectrum",
|
||||||
"heroku": "Heroku",
|
"heroku": "Heroku",
|
||||||
"now": "ZEIT Now"
|
"now": "ZEIT Now",
|
||||||
|
"nta": "法人"
|
||||||
},
|
},
|
||||||
"countryCode": "jp",
|
"countryCode": "jp",
|
||||||
"try": "全自動名前考え機",
|
"try": "全自動名前考え機",
|
||||||
"showMore": "もっと見る"
|
"showMore": "もっと見る",
|
||||||
|
"noResult": "該当なし"
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@ import GithubSearchCard from './components/cards/github-search'
|
|||||||
import AppStoreCard from './components/cards/appstore'
|
import AppStoreCard from './components/cards/appstore'
|
||||||
import HerokuCard from './components/cards/heroku'
|
import HerokuCard from './components/cards/heroku'
|
||||||
import NowCard from './components/cards/now'
|
import NowCard from './components/cards/now'
|
||||||
|
import NtaCard from './components/cards/nta'
|
||||||
|
|
||||||
import Welcome from './components/Welcome'
|
import Welcome from './components/Welcome'
|
||||||
import Footer from './components/Footer'
|
import Footer from './components/Footer'
|
||||||
@ -34,7 +35,10 @@ export default function App() {
|
|||||||
const [inputValue, setInputValue] = useState('')
|
const [inputValue, setInputValue] = useState('')
|
||||||
const [suggested, setSuggested] = useState(false)
|
const [suggested, setSuggested] = useState(false)
|
||||||
const inputRef = useRef()
|
const inputRef = useRef()
|
||||||
const { t } = useTranslation()
|
const {
|
||||||
|
t,
|
||||||
|
i18n: { language },
|
||||||
|
} = useTranslation()
|
||||||
|
|
||||||
const queryGiven = query && query.length > 0
|
const queryGiven = query && query.length > 0
|
||||||
|
|
||||||
@ -114,6 +118,7 @@ export default function App() {
|
|||||||
<Cards>
|
<Cards>
|
||||||
<GithubSearchCard query={query} />
|
<GithubSearchCard query={query} />
|
||||||
<AppStoreCard query={query} />
|
<AppStoreCard query={query} />
|
||||||
|
{language === 'ja' ? <NtaCard query={query} /> : null}
|
||||||
</Cards>
|
</Cards>
|
||||||
</SearchResult>
|
</SearchResult>
|
||||||
) : (
|
) : (
|
||||||
|
@ -14,6 +14,7 @@ import {
|
|||||||
FaSlack,
|
FaSlack,
|
||||||
FaAws,
|
FaAws,
|
||||||
FaJsSquare,
|
FaJsSquare,
|
||||||
|
FaBuilding,
|
||||||
} from 'react-icons/fa'
|
} from 'react-icons/fa'
|
||||||
import { IoIosBeer } from 'react-icons/io'
|
import { IoIosBeer } from 'react-icons/io'
|
||||||
import { DiRust, DiHeroku } from 'react-icons/di'
|
import { DiRust, DiHeroku } from 'react-icons/di'
|
||||||
@ -82,6 +83,9 @@ export default function Welcome() {
|
|||||||
<ListItem>
|
<ListItem>
|
||||||
<FaAppStore /> {t('providers.appStore')}
|
<FaAppStore /> {t('providers.appStore')}
|
||||||
</ListItem>
|
</ListItem>
|
||||||
|
<ListItem>
|
||||||
|
<FaBuilding /> {t('providers.nta')}
|
||||||
|
</ListItem>
|
||||||
</List>
|
</List>
|
||||||
</Container>
|
</Container>
|
||||||
)
|
)
|
||||||
|
@ -26,7 +26,7 @@ function Search({ query }) {
|
|||||||
/>
|
/>
|
||||||
))
|
))
|
||||||
) : (
|
) : (
|
||||||
<Result title="No Result" icon={<FaInfoCircle />} />
|
<Result title={t('noResult')} icon={<FaInfoCircle />} />
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
|
@ -6,6 +6,7 @@ import { FaGithub, FaInfoCircle } from 'react-icons/fa'
|
|||||||
import { Card, Result } from '../Cards'
|
import { Card, Result } from '../Cards'
|
||||||
|
|
||||||
function Search({ query }) {
|
function Search({ query }) {
|
||||||
|
const { t } = useTranslation()
|
||||||
const searchQuery = encodeURIComponent(`${query} in:name`)
|
const searchQuery = encodeURIComponent(`${query} in:name`)
|
||||||
const limit = 10
|
const limit = 10
|
||||||
const response = useFetch(
|
const response = useFetch(
|
||||||
@ -28,7 +29,7 @@ function Search({ query }) {
|
|||||||
/>
|
/>
|
||||||
))
|
))
|
||||||
) : (
|
) : (
|
||||||
<Result title="No Result" icon={<FaInfoCircle />} />
|
<Result title={t('noResult')} icon={<FaInfoCircle />} />
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
|
40
web/src/components/cards/nta.js
Normal file
40
web/src/components/cards/nta.js
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import useFetch from 'fetch-suspense'
|
||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import { FaBuilding, FaInfoCircle } from 'react-icons/fa'
|
||||||
|
|
||||||
|
import { Card, Result } from '../Cards'
|
||||||
|
|
||||||
|
function Search({ query }) {
|
||||||
|
const { t } = useTranslation()
|
||||||
|
const term = encodeURIComponent(query)
|
||||||
|
const response = useFetch(`/availability/nta/${term}`)
|
||||||
|
const apps = response.result
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{apps.length > 0 ? (
|
||||||
|
apps.map((app, i) => (
|
||||||
|
<Result
|
||||||
|
title={app.name}
|
||||||
|
message={`Phonetic: ${app.phoneticName}`}
|
||||||
|
icon={<FaBuilding />}
|
||||||
|
key={i}
|
||||||
|
/>
|
||||||
|
))
|
||||||
|
) : (
|
||||||
|
<Result title={t('noResult')} icon={<FaInfoCircle />} />
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function NtaCard({ query }) {
|
||||||
|
const { t } = useTranslation()
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Card title={t('providers.nta')}>
|
||||||
|
<Search query={query} />
|
||||||
|
</Card>
|
||||||
|
)
|
||||||
|
}
|
@ -14,7 +14,7 @@ i18n
|
|||||||
backends: [LocalStorageBackend, XHR],
|
backends: [LocalStorageBackend, XHR],
|
||||||
backendOptions: [
|
backendOptions: [
|
||||||
{
|
{
|
||||||
versions: { en: '1.3', ja: '1.3' },
|
versions: { en: '1.5', ja: '1.5' },
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user