mirror of
https://github.com/docmost/docmost.git
synced 2026-05-07 06:23:06 +08:00
57efb91bd3
* feat: ai chat * feat: ai chat * sync * cleanup * view space button
40 lines
1.3 KiB
TypeScript
40 lines
1.3 KiB
TypeScript
import { Module } from '@nestjs/common';
|
|
import { ThrottlerModule } from '@nestjs/throttler';
|
|
import { ThrottlerStorageRedisService } from '@nest-lab/throttler-storage-redis';
|
|
import { EnvironmentService } from '../environment/environment.service';
|
|
import { EnvironmentModule } from '../environment/environment.module';
|
|
import { parseRedisUrl } from '../../common/helpers';
|
|
import { AUTH_THROTTLER, AI_CHAT_THROTTLER } from './throttler-names';
|
|
import Redis from 'ioredis';
|
|
|
|
@Module({
|
|
imports: [
|
|
ThrottlerModule.forRootAsync({
|
|
imports: [EnvironmentModule],
|
|
useFactory: (environmentService: EnvironmentService) => {
|
|
const redisConfig = parseRedisUrl(environmentService.getRedisUrl());
|
|
|
|
return {
|
|
throttlers: [
|
|
{ name: AUTH_THROTTLER, ttl: 60_000, limit: 10 },
|
|
{ name: AI_CHAT_THROTTLER, ttl: 60_000, limit: 25 },
|
|
],
|
|
errorMessage: 'Too many requests',
|
|
storage: new ThrottlerStorageRedisService(
|
|
new Redis({
|
|
host: redisConfig.host,
|
|
port: redisConfig.port,
|
|
password: redisConfig.password,
|
|
db: redisConfig.db,
|
|
family: redisConfig.family,
|
|
keyPrefix: 'throttle:',
|
|
}),
|
|
),
|
|
};
|
|
},
|
|
inject: [EnvironmentService],
|
|
}),
|
|
],
|
|
})
|
|
export class ThrottleModule {}
|