diff options
author | Madeline <46743919+MaddyUnderStars@users.noreply.github.com> | 2023-01-20 18:10:47 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-20 18:10:47 +1100 |
commit | 084dc0be08555891cad4c2bb984822a62ec5ec9f (patch) | |
tree | ed2ca0fafefa2224ae32761f955f63935422a97d /src/api/routes/gifs | |
parent | fix: route file regex (#956) (diff) | |
download | server-084dc0be08555891cad4c2bb984822a62ec5ec9f.tar.xz |
Add ESLint (#941)
* Add eslint, switch to lint-staged for precommit * Fix all ESLint errors * Update GH workflow to check prettier and eslint
Diffstat (limited to 'src/api/routes/gifs')
-rw-r--r-- | src/api/routes/gifs/search.ts | 2 | ||||
-rw-r--r-- | src/api/routes/gifs/trending-gifs.ts | 2 | ||||
-rw-r--r-- | src/api/routes/gifs/trending.ts | 61 |
3 files changed, 58 insertions, 7 deletions
diff --git a/src/api/routes/gifs/search.ts b/src/api/routes/gifs/search.ts index 02022004..ae63d643 100644 --- a/src/api/routes/gifs/search.ts +++ b/src/api/routes/gifs/search.ts @@ -41,7 +41,7 @@ router.get("/", route({}), async (req: Request, res: Response) => { }, ); - const { results } = (await response.json()) as any; // TODO: types + const { results } = await response.json(); res.json(results.map(parseGifResult)).status(200); }); diff --git a/src/api/routes/gifs/trending-gifs.ts b/src/api/routes/gifs/trending-gifs.ts index d3fdb00a..d0698fa0 100644 --- a/src/api/routes/gifs/trending-gifs.ts +++ b/src/api/routes/gifs/trending-gifs.ts @@ -41,7 +41,7 @@ router.get("/", route({}), async (req: Request, res: Response) => { }, ); - const { results } = (await response.json()) as any; // TODO: types + const { results } = await response.json(); res.json(results.map(parseGifResult)).status(200); }); diff --git a/src/api/routes/gifs/trending.ts b/src/api/routes/gifs/trending.ts index 5dc43e85..5c872df8 100644 --- a/src/api/routes/gifs/trending.ts +++ b/src/api/routes/gifs/trending.ts @@ -25,7 +25,57 @@ import { HTTPError } from "lambert-server"; const router = Router(); -export function parseGifResult(result: any) { +// TODO: Move somewhere else +enum TENOR_GIF_TYPES { + gif, + mediumgif, + tinygif, + nanogif, + mp4, + loopedmp4, + tinymp4, + nanomp4, + webm, + tinywebm, + nanowebm, +} + +type TENOR_MEDIA = { + preview: string; + url: string; + dims: number[]; + size: number; +}; + +type TENOR_GIF = { + created: number; + hasaudio: boolean; + id: string; + media: { [type in keyof typeof TENOR_GIF_TYPES]: TENOR_MEDIA }[]; + tags: string[]; + title: string; + itemurl: string; + hascaption: boolean; + url: string; +}; + +type TENOR_CATEGORY = { + searchterm: string; + path: string; + image: string; + name: string; +}; + +type TENOR_CATEGORIES_RESULTS = { + tags: TENOR_CATEGORY[]; +}; + +type TENOR_TRENDING_RESULTS = { + next: string; + results: TENOR_GIF[]; +}; + +export function parseGifResult(result: TENOR_GIF) { return { id: result.id, title: result.title, @@ -50,7 +100,8 @@ export function getGifApiKey() { router.get("/", route({}), async (req: Request, res: Response) => { // TODO: Custom providers // TODO: return gifs as mp4 - const { media_format, locale } = req.query; + // const { media_format, locale } = req.query; + const { locale } = req.query; const apiKey = getGifApiKey(); @@ -75,11 +126,11 @@ router.get("/", route({}), async (req: Request, res: Response) => { ), ]); - const { tags } = (await responseSource.json()) as any; // TODO: types - const { results } = (await trendGifSource.json()) as any; //TODO: types; + const { tags } = (await responseSource.json()) as TENOR_CATEGORIES_RESULTS; + const { results } = (await trendGifSource.json()) as TENOR_TRENDING_RESULTS; res.json({ - categories: tags.map((x: any) => ({ + categories: tags.map((x) => ({ name: x.searchterm, src: x.image, })), |