summary refs log tree commit diff
path: root/src/api
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2026-07-06 00:32:23 +0200
committerRory& <root@rory.gay>2026-07-08 01:20:38 +0200
commitee57b28c324e7851168ae104a94d4bfd9252dae0 (patch)
tree46a24596ae66e01b5b2cd6f9387f6499281c613f /src/api
parentRemove a log that bothered me (diff)
downloadserver-ts-ee57b28c324e7851168ae104a94d4bfd9252dae0.tar.xz
Basic gif integration manager, port tenor search to that
Diffstat (limited to 'src/api')
-rw-r--r--src/api/Server.ts2
-rw-r--r--src/api/routes/gifs/search.ts29
-rw-r--r--src/api/routes/gifs/trending-gifs.ts4
3 files changed, 17 insertions, 18 deletions
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",