mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-19 05:55:34 +09:00
19 lines
623 B
TypeScript
19 lines
623 B
TypeScript
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
import {IpBannedError} from '@fluxer/errors/src/domains/moderation/IpBannedError';
|
|
import {createMiddleware} from 'hono/factory';
|
|
import type {HonoEnv} from '../types/HonoEnv';
|
|
import {getRequestClientIp} from '../utils/RequestClientIp';
|
|
import {torExitListCache} from './TorExitListCache';
|
|
|
|
export const TorExitMiddleware = createMiddleware<HonoEnv>(async (ctx, next) => {
|
|
const clientIp = getRequestClientIp(ctx);
|
|
if (clientIp && torExitListCache.isTorExit(clientIp)) {
|
|
throw new IpBannedError({
|
|
ipAddress: clientIp,
|
|
kind: 'permanent',
|
|
});
|
|
}
|
|
await next();
|
|
});
|