mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-19 05:55:34 +09:00
fix: migrate gifs to klipy service (#1220)
This commit is contained in:
1 parent
99eedf6d1e
commit
4a741d8396
79 files changed
+3032
-1653
No files matched your search
@@ -17,6 +17,7 @@ import {RateLimitConfigs} from '../RateLimitConfig';
|
||||
import type {HonoApp, HonoEnv} from '../types/HonoEnv';
|
||||
import {Validator} from '../Validator';
|
||||
import {GifProviderHeaderMiddleware} from './GifProviderHeaderMiddleware';
|
||||
import {resolveGifRequestCountry} from './GifRequestCountry';
|
||||
|
||||
const TAGS = ['GIFs'];
|
||||
|
||||
@@ -34,8 +35,8 @@ const PREFIXES: ReadonlyArray<PrefixConfig> = [
|
||||
];
|
||||
const DEPRECATION_NOTICE = 'Use /gifs/* instead - these vendor-specific paths are deprecated and will be removed.';
|
||||
|
||||
function getCountry(ctx: Context<HonoEnv>): string {
|
||||
return ctx.req.header('CF-IPCountry') || 'US';
|
||||
async function getCountry(ctx: Context<HonoEnv>): Promise<string> {
|
||||
return resolveGifRequestCountry(ctx.req.raw);
|
||||
}
|
||||
|
||||
function deprecationMiddleware(deprecated: boolean): MiddlewareHandler<HonoEnv> {
|
||||
@@ -72,7 +73,8 @@ function registerRoutes(app: HonoApp, cfg: PrefixConfig) {
|
||||
async (ctx) => {
|
||||
const {q, locale} = ctx.req.valid('query');
|
||||
const provider = await ctx.get('gifService').getActive();
|
||||
return ctx.json(await provider.search({q, locale, country: getCountry(ctx)}));
|
||||
const country = await getCountry(ctx);
|
||||
return ctx.json(await provider.search({q, locale, country}));
|
||||
},
|
||||
);
|
||||
app.get(
|
||||
@@ -94,7 +96,8 @@ function registerRoutes(app: HonoApp, cfg: PrefixConfig) {
|
||||
Validator('query', GifLocaleQuery),
|
||||
async (ctx) => {
|
||||
const provider = await ctx.get('gifService').getActive();
|
||||
return ctx.json(await provider.getFeatured({locale: ctx.req.valid('query').locale, country: getCountry(ctx)}));
|
||||
const country = await getCountry(ctx);
|
||||
return ctx.json(await provider.getFeatured({locale: ctx.req.valid('query').locale, country}));
|
||||
},
|
||||
);
|
||||
const trendingPath = prefix === '/gifs' ? `${prefix}/trending` : `${prefix}/trending-gifs`;
|
||||
@@ -117,10 +120,11 @@ function registerRoutes(app: HonoApp, cfg: PrefixConfig) {
|
||||
Validator('query', GifLocaleQuery),
|
||||
async (ctx) => {
|
||||
const provider = await ctx.get('gifService').getActive();
|
||||
const country = await getCountry(ctx);
|
||||
return ctx.json(
|
||||
await provider.getTrendingGifs({
|
||||
locale: ctx.req.valid('query').locale,
|
||||
country: getCountry(ctx),
|
||||
country,
|
||||
}),
|
||||
);
|
||||
},
|
||||
@@ -145,7 +149,8 @@ function registerRoutes(app: HonoApp, cfg: PrefixConfig) {
|
||||
async (ctx) => {
|
||||
const {id, q, locale} = ctx.req.valid('json');
|
||||
const provider = await ctx.get('gifService').getActive();
|
||||
await provider.registerShare({id, q: q ?? '', locale, country: getCountry(ctx)});
|
||||
const country = await getCountry(ctx);
|
||||
await provider.registerShare({id, q: q ?? '', locale, country});
|
||||
return ctx.body(null, 204);
|
||||
},
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user