Skip to content

Commit

Permalink
Merge pull request #4682 from coralproject/develop
Browse files Browse the repository at this point in the history
v9.4.1
  • Loading branch information
tessalt authored Oct 7, 2024
2 parents 1396828 + 8fc3e53 commit 1d2fe8e
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 30 deletions.
2 changes: 1 addition & 1 deletion client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@coralproject/talk",
"version": "9.4.0",
"version": "9.4.1",
"author": "The Coral Project",
"homepage": "https://coralproject.net/",
"sideEffects": [
Expand Down
2 changes: 1 addition & 1 deletion common/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "common",
"version": "9.4.0",
"version": "9.4.1",
"description": "",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion config/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "common",
"version": "9.4.0",
"version": "9.4.1",
"description": "",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@coralproject/talk",
"version": "9.4.0",
"version": "9.4.1",
"author": "The Coral Project",
"homepage": "https://coralproject.net/",
"sideEffects": [
Expand Down
61 changes: 35 additions & 26 deletions server/src/core/server/app/handlers/api/tenor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import fetch from "node-fetch";

import { SearchPayload } from "coral-common/common/lib/types/tenor";
import { AppOptions } from "coral-server/app/";
import { WrappedInternalError } from "coral-server/errors";
import { RequestHandler, TenantCoralRequest } from "coral-server/types/express";

const SEARCH_LIMIT = 32;
Expand Down Expand Up @@ -58,7 +59,7 @@ export const tenorSearchHandler =

const result = schema.validate(req.query);
if (result.error || result.errors) {
res.status(400).send(result.errors);
res.status(400).send(result.error ?? result.errors);
return;
}

Expand Down Expand Up @@ -99,33 +100,41 @@ export const tenorSearchHandler =
url.searchParams.set("pos", params.pos);
}

const response = await fetch(url.toString(), {
method: "GET",
});

if (!response.ok) {
res.status(500).send({
results: [],
try {
const response = await fetch(url.toString(), {
method: "GET",
});
return;
}

const json = (await response.json()) as SearchPayload;
if (!json) {
res.status(500).send({
results: [],
if (!response.ok) {
res.status(500).send({
results: [],
});
return;
}
const json = (await response.json()) as SearchPayload;
if (!json) {
res.status(500).send({
results: [],
});
return;
}

res.status(200).send({
results: json.results.map((r) => {
return {
id: r.id,
title: r.title,
url: r.media_formats.gif.url,
preview: r.media_formats.nanogif.url,
};
}),
next: json.next,
});
} catch (e) {
// Ensure that the API key doesn't get leaked to the logs by accident.
if (e.message) {
e.message = e.message.replace(tenant.media?.gifs.key, "[Sensitive]");
}
throw new WrappedInternalError(e as Error, "tenor search error");
}

res.status(200).send({
results: json.results.map((r) => {
return {
id: r.id,
title: r.title,
url: r.media_formats.gif.url,
preview: r.media_formats.nanogif.url,
};
}),
next: json.next,
});
};

0 comments on commit 1d2fe8e

Please sign in to comment.