1
0
mirror of https://github.com/uetchy/namae.git synced 2025-08-20 18:08:11 +09:00

chore: cosmetic changes

This commit is contained in:
2019-09-17 14:30:26 +09:00
parent 2438518e3c
commit 6c84493360
56 changed files with 724 additions and 729 deletions

View File

@@ -1,38 +1,38 @@
import { send, sendError, fetch, NowRequest, NowResponse } from '../util/http'
import {send, sendError, fetch, NowRequest, NowResponse} from '../util/http';
interface App {
trackId: string
trackName: string
kind: string
version: string
price: string
trackViewUrl: string
trackId: string;
trackName: string;
kind: string;
version: string;
price: string;
trackViewUrl: string;
}
interface AppStoreResponse {
results: App[]
results: App[];
}
export default async function handler(
req: NowRequest<{ query: string; country: string }>,
res: NowResponse
req: NowRequest<{query: string; country: string}>,
res: NowResponse,
) {
const { query, country } = req.query
const {query, country} = req.query;
if (!query) {
return sendError(res, new Error('no query given'))
return sendError(res, new Error('no query given'));
}
const term = encodeURIComponent(query)
const countryCode = country || 'us'
const limit = 10
const term = encodeURIComponent(query);
const countryCode = country || 'us';
const limit = 10;
try {
const response = await fetch(
`https://itunes.apple.com/search?media=software&entity=software,iPadSoftware,macSoftware&country=${countryCode}&limit=${limit}&term=${term}`,
'GET'
)
const body: AppStoreResponse = await response.json()
'GET',
);
const body: AppStoreResponse = await response.json();
const apps = body.results.map((app) => ({
id: app.trackId,
name: app.trackName,
@@ -40,9 +40,9 @@ export default async function handler(
version: app.version,
price: app.price,
viewURL: app.trackViewUrl,
}))
send(res, { result: apps || [] })
}));
send(res, {result: apps || []});
} catch (err) {
sendError(res, err)
sendError(res, err);
}
}