diff options
Diffstat (limited to 'api/src/routes/gifs/trending-gifs.ts')
-rw-r--r-- | api/src/routes/gifs/trending-gifs.ts | 27 |
1 files changed, 7 insertions, 20 deletions
diff --git a/api/src/routes/gifs/trending-gifs.ts b/api/src/routes/gifs/trending-gifs.ts index 76e791fa..b5f87222 100644 --- a/api/src/routes/gifs/trending-gifs.ts +++ b/api/src/routes/gifs/trending-gifs.ts @@ -1,37 +1,24 @@ import { Router, Response, Request } from "express"; import fetch from "node-fetch"; import { route } from "@fosscord/api"; +import { getGifApiKey, parseGifResult } from "./trending"; const router = Router(); router.get("/", route({}), async (req: Request, res: Response) => { - // TODO: Custom providers and code quality - const { media_format, locale, provider } = req.query; + // TODO: Custom providers + const { media_format, locale } = req.query; - const parseResult = (result: any) => { - return { - id: result.id, - title: result.title, - url: result.itemurl, - src: result.media[0].mp4.url, - gif_src: result.media[0].gif.url, - width: result.media[0].mp4.dims[0], - height: result.media[0].mp4.dims[1], - preview: result.media[0].mp4.preview - }; - }; + const apiKey = getGifApiKey(); - const response = await fetch(`https://g.tenor.com/v1/trending?media_format=${media_format}&locale=${locale}&key=LIVDSRZULELA`, { + const response = await fetch(`https://g.tenor.com/v1/trending?media_format=${media_format}&locale=${locale}&key=${apiKey}`, { method: "get", headers: { "Content-Type": "application/json" } }); const { results } = await response.json(); - let cache = new Array() as any[]; - results.forEach((result: any) => { - cache.push(parseResult(result)); - }); - res.json(cache).status(200); + + res.json(results.map(parseGifResult)).status(200); }); export default router; |