mirror of
https://github.com/uetchy/namae.git
synced 2025-03-16 12:10:32 +09:00
feat: support for Chrome Web Store
This commit is contained in:
parent
096ce42e20
commit
3cb7f4c3b5
34
api/services/chrome-web-store/[query].ts
Normal file
34
api/services/chrome-web-store/[query].ts
Normal file
@ -0,0 +1,34 @@
|
||||
import { send, sendError, fetch } from '../../../util/http';
|
||||
import { VercelRequest, VercelResponse } from '@vercel/node';
|
||||
|
||||
export default async function handler(
|
||||
req: VercelRequest,
|
||||
res: VercelResponse
|
||||
): Promise<void> {
|
||||
const { query } = req.query;
|
||||
|
||||
if (!query || typeof query !== 'string') {
|
||||
return sendError(res, new Error('No query given'));
|
||||
}
|
||||
|
||||
const term = encodeURIComponent(query);
|
||||
|
||||
try {
|
||||
const response = await fetch(
|
||||
`https://chrome.google.com/webstore/ajax/item?hl=en&pv=20210820&count=112&category=extensions&searchTerm=${term}`,
|
||||
'POST'
|
||||
);
|
||||
const body = await response.text();
|
||||
const json = JSON.parse(body.slice(5));
|
||||
console.log(json[1][1][0]);
|
||||
const items = json[1][1].map((item: any) => ({
|
||||
id: item[0],
|
||||
name: item[1],
|
||||
description: item[6],
|
||||
url: item[37],
|
||||
}));
|
||||
send(res, { result: items.slice(0, 10) });
|
||||
} catch (err: any) {
|
||||
sendError(res, err);
|
||||
}
|
||||
}
|
@ -43,7 +43,8 @@
|
||||
"spectrum": "Spectrum",
|
||||
"reddit": "Reddit",
|
||||
"twitter": "Twitter",
|
||||
"cloudflare": "Cloudflare Pages"
|
||||
"cloudflare": "Cloudflare Pages",
|
||||
"chromeWebStore": "Chrome Web Store"
|
||||
},
|
||||
"showMore": "show more",
|
||||
"title": "Grab a slick name for your new app",
|
||||
|
@ -16,7 +16,7 @@ import {
|
||||
} from 'react-icons/fa';
|
||||
import { IoIosBeer, IoMdAppstore } from 'react-icons/io';
|
||||
import { MdDomain } from 'react-icons/md';
|
||||
import { RiBuilding2Fill, RiNpmjsFill } from 'react-icons/ri';
|
||||
import { RiBuilding2Fill, RiChromeFill, RiNpmjsFill } from 'react-icons/ri';
|
||||
import {
|
||||
SiAppstore,
|
||||
SiArchlinux,
|
||||
@ -60,6 +60,7 @@ const supportedProviders: Record<string, React.ReactNode> = {
|
||||
githubSearch: <FaGithubAlt />,
|
||||
appStore: <SiAppstore />,
|
||||
playStore: <IoMdAppstore />,
|
||||
chromeWebStore: <RiChromeFill />,
|
||||
nta: <RiBuilding2Fill />,
|
||||
};
|
||||
|
||||
|
@ -3,6 +3,7 @@ import { useTranslation } from 'react-i18next';
|
||||
import styled from 'styled-components';
|
||||
import { mobile } from '../../util/css';
|
||||
import AppStoreCard from './providers/AppStore';
|
||||
import ChromeWebStoreCard from './providers/ChromeWebStore';
|
||||
import CloudflareCard from './providers/Cloudflare';
|
||||
import CratesioCard from './providers/Cratesio';
|
||||
import DomainCard from './providers/Domains';
|
||||
@ -64,6 +65,7 @@ const Index: React.FC<{ query: string }> = ({ query }) => {
|
||||
<GithubSearchCard query={query} />
|
||||
<AppStoreCard query={query} />
|
||||
<PlayStoreCard query={query} />
|
||||
<ChromeWebStoreCard query={query} />
|
||||
{language === 'ja' ? <NtaCard query={query} /> : null}
|
||||
</Cards>
|
||||
</>
|
||||
|
54
src/components/cards/providers/ChromeWebStore.tsx
Normal file
54
src/components/cards/providers/ChromeWebStore.tsx
Normal file
@ -0,0 +1,54 @@
|
||||
import useFetch from 'fetch-suspense';
|
||||
import React from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { RiChromeFill } from 'react-icons/ri';
|
||||
import { Card, Result } from '../core';
|
||||
|
||||
const Search: React.FC<{ query: string }> = ({ query }) => {
|
||||
const { t } = useTranslation();
|
||||
const response = useFetch(
|
||||
`/api/services/chrome-web-store/${encodeURIComponent(query)}`
|
||||
) as {
|
||||
result: Array<{
|
||||
name: string;
|
||||
url: string;
|
||||
description: string;
|
||||
id: string;
|
||||
}>;
|
||||
};
|
||||
const apps = response.result;
|
||||
|
||||
return (
|
||||
<>
|
||||
{apps && apps.length > 0 ? (
|
||||
apps.map((app) => (
|
||||
<Result
|
||||
title={app.name}
|
||||
message={app.description}
|
||||
link={app.url}
|
||||
icon={<RiChromeFill />}
|
||||
key={app.id}
|
||||
/>
|
||||
))
|
||||
) : (
|
||||
<Result
|
||||
title={t('noResult')}
|
||||
message={t('noResult')}
|
||||
icon={<RiChromeFill />}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
const ChromeWebStoreCard: React.FC<{ query: string }> = ({ query }) => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
return (
|
||||
<Card title={t('providers.chromeWebStore')}>
|
||||
<Search query={query} />
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
|
||||
export default ChromeWebStoreCard;
|
@ -5,7 +5,7 @@ import XHR from 'i18next-xhr-backend';
|
||||
import LanguageDetector from 'i18next-browser-languagedetector';
|
||||
import { initReactI18next } from 'react-i18next';
|
||||
|
||||
const TRANSLATION_VERSION = '10';
|
||||
const TRANSLATION_VERSION = '11';
|
||||
|
||||
i18n
|
||||
.use(Backend)
|
||||
|
Loading…
x
Reference in New Issue
Block a user