calcom/packages/app-store/giphy/lib/giphyManager.ts
Omar López 2e6bc5e5b4 Fixes/app store keys in db (#2651)
* Adds available apps

* Adds App Model

* WIP

* Updates seeder script

* Seeder fixes

* lowercase categories

* Upgrades prisma

* WIP

* WIP

* Hopefully fixes circular deps

* Type fixes

* Fixes seeder

* Adds migration to connect Credentials to Apps

* Updates app store callbacks

* Updates google credentials

* Uses dirName from DB

* Type fixes

* Update reschedule.ts

* Seeder fixes

* Fixes categories listing

* Update index.ts

* Update schema.prisma

* Updates dependencies

* Renames giphy app

* Uses dynamic imports for app metadata

* Fixes credentials error

* Uses dynamic import for api handlers

* Dynamic import fixes

* Allows for simple folder names in app store

* Squashes app migrations

* seeder fixes

* Fixes dyamic imports

* Update apiHandlers.tsx
2022-05-02 16:21:11 -06:00

29 lines
1 KiB
TypeScript

import { HttpError } from "@calcom/lib/http-error";
import getAppKeysFromSlug from "../../_utils/getAppKeysFromSlug";
let api_key = "";
export const searchGiphy = async (locale: string, keyword: string, offset: number = 0) => {
const appKeys = await getAppKeysFromSlug("giphy");
if (typeof appKeys.api_key === "string") api_key = appKeys.api_key;
if (!api_key) throw new HttpError({ statusCode: 400, message: "Missing Giphy api_key" });
const queryParams = new URLSearchParams({
api_key,
q: keyword,
limit: "1",
offset: String(offset),
// Contains images that are broadly accepted as appropriate and commonly witnessed by people in a public environment.
rating: "g",
lang: locale,
});
const response = await fetch(`https://api.giphy.com/v1/gifs/search?${queryParams.toString()}`, {
method: "GET",
headers: {
Accept: "application/json",
},
});
const responseBody = await response.json();
const gifs = responseBody.data;
return gifs?.[0]?.images?.fixed_height_downsampled?.url || null;
};