mirror of
https://github.com/uetchy/namae.git
synced 2025-08-20 18:08:11 +09:00
style: prettier
This commit is contained in:
@@ -1,39 +1,39 @@
|
||||
import { send, sendError, fetch } from '../../../util/http'
|
||||
import { NowRequest, NowResponse } from '@vercel/node'
|
||||
import { send, sendError, fetch } from '../../../util/http';
|
||||
import { NowRequest, NowResponse } from '@vercel/node';
|
||||
|
||||
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,
|
||||
res: NowResponse
|
||||
): Promise<void> {
|
||||
const { query, country } = req.query
|
||||
const { query, country } = req.query;
|
||||
|
||||
if (!query || typeof query !== 'string') {
|
||||
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()
|
||||
);
|
||||
const body: AppStoreResponse = await response.json();
|
||||
const apps = body.results.map((app) => ({
|
||||
id: app.trackId,
|
||||
name: app.trackName,
|
||||
@@ -41,9 +41,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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user