Skip to content

Commit

Permalink
move tenor api types into common; use for tenor fetch payload
Browse files Browse the repository at this point in the history
  • Loading branch information
kabeaty committed Sep 30, 2024
1 parent 325fa3b commit a648c02
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 43 deletions.
44 changes: 44 additions & 0 deletions common/lib/types/tenor.ts
Original file line number Diff line number Diff line change
@@ -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[];
}
42 changes: 1 addition & 41 deletions server/src/core/server/app/handlers/api/tenor/index.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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 => {
Expand Down
6 changes: 4 additions & 2 deletions server/src/core/server/services/tenor/tenor.ts
Original file line number Diff line number Diff line change
@@ -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" });
Expand All @@ -25,7 +27,7 @@ const TenorRetrieveResponseSchema = Joi.object().keys({
export async function retrieveFromTenor(
tenant: Tenant,
id: string
): Promise<any> {
): Promise<FetchPayload> {
if (!supportsMediaType(tenant, "tenor") || !tenant.media.gifs.key) {
throw new InternalError("Tenor was not enabled");
}
Expand Down

0 comments on commit a648c02

Please sign in to comment.