diff --git a/src/api/Server.ts b/src/api/Server.ts
index 2bf14350..74718dad 100644
--- a/src/api/Server.ts
+++ b/src/api/Server.ts
@@ -29,6 +29,7 @@ import { BcryptWorkerPool } from "../util/util/workers/bcrypt/BcryptWorkerPool";
import { Authentication, CORS, ImageProxy, BodyParser, ErrorHandler, initRateLimits, initTranslation } from "./middlewares";
import { initInstance } from "./util/handlers/Instance";
import { route, addPendingPoll } from "./util";
+import { GifProviderManager } from "@spacebar/util/util/integrations/gifProviders/GifProviderManager";
const ASSETS_FOLDER = path.join(__dirname, "..", "..", "assets");
const PUBLIC_ASSETS_FOLDER = path.join(ASSETS_FOLDER, "public");
@@ -64,6 +65,7 @@ export class SpacebarServer extends Server {
await initInstance();
WebAuthn.init();
// await BcryptWorkerPool.Init(8); // TODO: make configurable
+ await GifProviderManager.init();
const logRequests = process.env["LOG_REQUESTS"] != undefined;
if (logRequests) {
diff --git a/src/api/routes/gifs/search.ts b/src/api/routes/gifs/search.ts
index 13c24659..20f77889 100644
--- a/src/api/routes/gifs/search.ts
+++ b/src/api/routes/gifs/search.ts
@@ -1,6 +1,6 @@
/*
Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
- Copyright (C) 2023 Spacebar and Spacebar Contributors
+ Copyright (C) 2026 Spacebar and Spacebar Contributors
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
@@ -17,9 +17,9 @@
*/
import { route } from "@spacebar/api/util/handlers/route";
-import { getGifApiKey, parseGifResult } from "@spacebar/util";
import { Request, Response, Router } from "express";
-import { TenorGif, TenorMediaTypes } from "@spacebar/schemas";
+import { GifMediaTypes } from "@spacebar/schemas";
+import { GifProviderManager } from "@spacebar/util/util/integrations/gifProviders/GifProviderManager";
const router = Router({ mergeParams: true });
@@ -35,33 +35,30 @@ router.get(
media_format: {
type: "string",
description: "Media format",
- values: Object.keys(TenorMediaTypes).filter((key) => isNaN(Number(key))),
+ values: Object.keys(GifMediaTypes).filter((key) => isNaN(Number(key))),
},
locale: {
type: "string",
description: "Locale",
},
+ provider: {
+ type: "string",
+ description: "Provider to use",
+ },
},
responses: {
200: {
- body: "TenorGifsResponse",
+ body: "GifsResponse",
},
},
}),
async (req: Request, res: Response) => {
- // TODO: Custom providers
- const { q, media_format, locale } = req.query;
-
- const apiKey = getGifApiKey();
-
- const response = await fetch(`https://g.tenor.com/v1/search?q=${q}&media_format=${media_format}&locale=${locale}&key=${apiKey}`, {
- method: "get",
- headers: { "Content-Type": "application/json" },
- });
+ const { provider } = req.query;
- const { results } = (await response.json()) as { results: TenorGif[] };
+ const impl = GifProviderManager.getProvider(provider as string);
+ const result = await impl.search(req.query as typeof impl.search.arguments);
- res.json(results.map(parseGifResult)).status(200);
+ res.json(result).status(200);
},
);
diff --git a/src/api/routes/gifs/trending-gifs.ts b/src/api/routes/gifs/trending-gifs.ts
index 14d3d4dc..a79dfc54 100644
--- a/src/api/routes/gifs/trending-gifs.ts
+++ b/src/api/routes/gifs/trending-gifs.ts
@@ -19,7 +19,7 @@
import { route } from "@spacebar/api/util/handlers/route";
import { getGifApiKey, parseGifResult } from "@spacebar/util";
import { Request, Response, Router } from "express";
-import { TenorGif, TenorMediaTypes } from "@spacebar/schemas";
+import { TenorGif, GifMediaTypes } from "@spacebar/schemas";
const router = Router({ mergeParams: true });
@@ -30,7 +30,7 @@ router.get(
media_format: {
type: "string",
description: "Media format",
- values: Object.keys(TenorMediaTypes).filter((key) => isNaN(Number(key))),
+ values: Object.keys(GifMediaTypes).filter((key) => isNaN(Number(key))),
},
locale: {
type: "string",
|