diff options
Diffstat (limited to 'api/src/routes/gifs/trending-gifs.ts')
-rw-r--r-- | api/src/routes/gifs/trending-gifs.ts | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/api/src/routes/gifs/trending-gifs.ts b/api/src/routes/gifs/trending-gifs.ts new file mode 100644 index 00000000..76e791fa --- /dev/null +++ b/api/src/routes/gifs/trending-gifs.ts @@ -0,0 +1,37 @@ +import { Router, Response, Request } from "express"; +import fetch from "node-fetch"; +import { route } from "@fosscord/api"; + +const router = Router(); + +router.get("/", route({}), async (req: Request, res: Response) => { + // TODO: Custom providers and code quality + const { media_format, locale, provider } = 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 response = await fetch(`https://g.tenor.com/v1/trending?media_format=${media_format}&locale=${locale}&key=LIVDSRZULELA`, { + 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); +}); + +export default router; |