mirror of
https://github.com/uetchy/namae.git
synced 2025-03-16 20:20:38 +09:00
fix: use dedicated api for twittter
This commit is contained in:
parent
ec858f3473
commit
b8ce81b276
27
api/services/twitter.ts
Normal file
27
api/services/twitter.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import {send, sendError, fetch, NowResponse, NowRequest} from '../util/http';
|
||||
|
||||
export default async function handler(
|
||||
req: NowRequest,
|
||||
res: NowResponse,
|
||||
): Promise<void> {
|
||||
const {query} = req.query;
|
||||
|
||||
if (!query) {
|
||||
return sendError(res, new Error('No query given'));
|
||||
}
|
||||
|
||||
if (/[^a-zA-Z0-9_]/.test(query)) {
|
||||
return sendError(res, new Error('Invalid characters'));
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(
|
||||
`https://api.twitter.com/i/users/username_available.json?username=${query}`,
|
||||
'GET',
|
||||
).then((res) => res.json());
|
||||
const availability = response.valid;
|
||||
send(res, {availability});
|
||||
} catch (err) {
|
||||
sendError(res, err);
|
||||
}
|
||||
}
|
@ -7,16 +7,20 @@ import {Card, Repeater, DedicatedAvailability} from '../core';
|
||||
|
||||
const TwitterCard: React.FC<{query: string}> = ({query}) => {
|
||||
const {t} = useTranslation();
|
||||
const lowerCase = query.toLowerCase();
|
||||
const capitalCase = capitalize(query);
|
||||
|
||||
const names = [query, `${capitalCase}App`, `${lowerCase}hq`];
|
||||
const sanitizedQuery = query
|
||||
.replace(/[^0-9a-zA-Z_-]/g, '')
|
||||
.replace(/-/g, '_');
|
||||
const lowerCase = sanitizedQuery.toLowerCase();
|
||||
const capitalCase = capitalize(sanitizedQuery);
|
||||
|
||||
const names = [sanitizedQuery, `${capitalCase}App`, `${lowerCase}hq`];
|
||||
const moreNames = [
|
||||
`hey${lowerCase}`,
|
||||
`${capitalCase}Team`,
|
||||
`${lowerCase}-support`,
|
||||
`${lowerCase}_support`,
|
||||
`${lowerCase}_org`,
|
||||
`${lowerCase}-app`,
|
||||
`${lowerCase}_app`,
|
||||
`${capitalCase}JS`,
|
||||
];
|
||||
|
||||
@ -26,11 +30,10 @@ const TwitterCard: React.FC<{query: string}> = ({query}) => {
|
||||
{(name) => (
|
||||
<DedicatedAvailability
|
||||
name={name}
|
||||
query={`twitter.com/${name}`}
|
||||
service="existence"
|
||||
query={name}
|
||||
service="twitter"
|
||||
message="Go to Twitter"
|
||||
link={`https://twitter.com/${name}`}
|
||||
prefix="twitter.com/"
|
||||
icon={<FaTwitter />}
|
||||
/>
|
||||
)}
|
||||
|
Loading…
x
Reference in New Issue
Block a user