From a648c023324f3d7590f43caf6639581d9b27538f Mon Sep 17 00:00:00 2001 From: Kathryn Beaty Date: Mon, 30 Sep 2024 11:41:01 -0400 Subject: [PATCH] move tenor api types into common; use for tenor fetch payload --- common/lib/types/tenor.ts | 44 +++++++++++++++++++ .../server/app/handlers/api/tenor/index.ts | 42 +----------------- .../src/core/server/services/tenor/tenor.ts | 6 ++- 3 files changed, 49 insertions(+), 43 deletions(-) create mode 100644 common/lib/types/tenor.ts diff --git a/common/lib/types/tenor.ts b/common/lib/types/tenor.ts new file mode 100644 index 0000000000..d36e73465d --- /dev/null +++ b/common/lib/types/tenor.ts @@ -0,0 +1,44 @@ +export interface MediaFormat { + url: string; + duration: number; + dims: number[]; + size: number; +} + +export interface SearchResult { + id: string; + title: string; + created: number; + content_description: string; + itemurl: string; + url: string; + tags: string[]; + flags: []; + hasaudio: boolean; + media_formats: { + webm: MediaFormat; + mp4: MediaFormat; + nanowebm: MediaFormat; + loopedmp4: MediaFormat; + gifpreview: MediaFormat; + tinygifpreview: MediaFormat; + nanomp4: MediaFormat; + nanogifpreview: MediaFormat; + tinymp4: MediaFormat; + gif: MediaFormat; + webp: MediaFormat; + mediumgif: MediaFormat; + tinygif: MediaFormat; + nanogif: MediaFormat; + tinywebm: MediaFormat; + }; +} + +export interface SearchPayload { + results: SearchResult[]; + next: string; +} + +export interface FetchPayload { + results: SearchResult[]; +} diff --git a/server/src/core/server/app/handlers/api/tenor/index.ts b/server/src/core/server/app/handlers/api/tenor/index.ts index 9b2ecdb7cd..6f63a7a755 100644 --- a/server/src/core/server/app/handlers/api/tenor/index.ts +++ b/server/src/core/server/app/handlers/api/tenor/index.ts @@ -1,6 +1,7 @@ import Joi from "joi"; import fetch from "node-fetch"; +import { SearchPayload } from "coral-common/common/lib/types/tenor"; import { AppOptions } from "coral-server/app/"; import { RequestHandler, TenantCoralRequest } from "coral-server/types/express"; @@ -17,47 +18,6 @@ interface BodyPayload { pos?: string; } -interface MediaFormat { - url: string; - duration: number; - dims: number[]; - size: number; -} - -interface SearchResult { - id: string; - title: string; - created: number; - content_description: string; - itemurl: string; - url: string; - tags: string[]; - flags: []; - hasaudio: boolean; - media_formats: { - webm: MediaFormat; - mp4: MediaFormat; - nanowebm: MediaFormat; - loopedmp4: MediaFormat; - gifpreview: MediaFormat; - tinygifpreview: MediaFormat; - nanomp4: MediaFormat; - nanogifpreview: MediaFormat; - tinymp4: MediaFormat; - gif: MediaFormat; - webp: MediaFormat; - mediumgif: MediaFormat; - tinygif: MediaFormat; - nanogif: MediaFormat; - tinywebm: MediaFormat; - }; -} - -interface SearchPayload { - results: SearchResult[]; - next: string; -} - export const convertGiphyContentRatingToTenorLevel = ( rating: string | null | undefined ): string => { diff --git a/server/src/core/server/services/tenor/tenor.ts b/server/src/core/server/services/tenor/tenor.ts index e5e17527e4..f7e4f3cea1 100644 --- a/server/src/core/server/services/tenor/tenor.ts +++ b/server/src/core/server/services/tenor/tenor.ts @@ -1,8 +1,10 @@ +import Joi from "joi"; + +import { FetchPayload } from "coral-common/common/lib/types/tenor"; import { InternalError } from "coral-server/errors"; import { validateSchema } from "coral-server/helpers"; import { supportsMediaType, Tenant } from "coral-server/models/tenant"; import { createFetch } from "coral-server/services/fetch"; -import Joi from "joi"; const TENOR_FETCH_URL = "https://tenor.googleapis.com/v2/posts"; const fetch = createFetch({ name: "tenor" }); @@ -25,7 +27,7 @@ const TenorRetrieveResponseSchema = Joi.object().keys({ export async function retrieveFromTenor( tenant: Tenant, id: string -): Promise { +): Promise { if (!supportsMediaType(tenant, "tenor") || !tenant.media.gifs.key) { throw new InternalError("Tenor was not enabled"); }