2022-12-01 23:07:49 +01:00
|
|
|
import { HttpException, HttpStatus, Module } from "@nestjs/common";
|
2022-11-28 15:04:32 +01:00
|
|
|
|
2022-10-09 22:30:32 +02:00
|
|
|
import { ScheduleModule } from "@nestjs/schedule";
|
|
|
|
import { AuthModule } from "./auth/auth.module";
|
2022-10-16 00:25:32 +02:00
|
|
|
import { JobsService } from "./jobs/jobs.service";
|
2022-10-09 22:30:32 +02:00
|
|
|
|
2022-10-24 12:11:10 +02:00
|
|
|
import { APP_GUARD } from "@nestjs/core";
|
2022-12-01 23:07:49 +01:00
|
|
|
import { MulterModule } from "@nestjs/platform-express";
|
2022-10-24 12:11:10 +02:00
|
|
|
import { ThrottlerGuard, ThrottlerModule } from "@nestjs/throttler";
|
2022-12-01 23:07:49 +01:00
|
|
|
import { Request } from "express";
|
2022-11-28 15:04:32 +01:00
|
|
|
import { ConfigModule } from "./config/config.module";
|
|
|
|
import { ConfigService } from "./config/config.service";
|
|
|
|
import { EmailModule } from "./email/email.module";
|
2022-10-09 22:30:32 +02:00
|
|
|
import { FileController } from "./file/file.controller";
|
|
|
|
import { FileModule } from "./file/file.module";
|
|
|
|
import { PrismaModule } from "./prisma/prisma.module";
|
|
|
|
import { PrismaService } from "./prisma/prisma.service";
|
|
|
|
import { ShareController } from "./share/share.controller";
|
|
|
|
import { ShareModule } from "./share/share.module";
|
|
|
|
import { UserController } from "./user/user.controller";
|
|
|
|
|
|
|
|
@Module({
|
|
|
|
imports: [
|
|
|
|
AuthModule,
|
|
|
|
ShareModule,
|
|
|
|
FileModule,
|
2022-11-11 15:12:16 +01:00
|
|
|
EmailModule,
|
2022-10-09 22:30:32 +02:00
|
|
|
PrismaModule,
|
2022-11-28 15:04:32 +01:00
|
|
|
ConfigModule,
|
2022-12-01 23:07:49 +01:00
|
|
|
MulterModule.registerAsync({
|
|
|
|
useFactory: (config: ConfigService) => ({
|
|
|
|
fileFilter: (req: Request, file, cb) => {
|
|
|
|
const maxFileSize = config.get("maxFileSize");
|
|
|
|
const requestFileSize = parseInt(req.headers["content-length"]);
|
|
|
|
const isValidFileSize = requestFileSize <= maxFileSize;
|
|
|
|
cb(
|
|
|
|
!isValidFileSize &&
|
|
|
|
new HttpException(
|
|
|
|
`File must be smaller than ${maxFileSize} bytes`,
|
|
|
|
HttpStatus.PAYLOAD_TOO_LARGE
|
|
|
|
),
|
|
|
|
isValidFileSize
|
|
|
|
);
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
inject: [ConfigService],
|
|
|
|
}),
|
2022-10-24 12:11:10 +02:00
|
|
|
ThrottlerModule.forRoot({
|
|
|
|
ttl: 60,
|
|
|
|
limit: 100,
|
|
|
|
}),
|
2022-10-09 22:30:32 +02:00
|
|
|
ScheduleModule.forRoot(),
|
|
|
|
],
|
2022-10-24 12:11:10 +02:00
|
|
|
providers: [
|
2022-11-28 15:04:32 +01:00
|
|
|
ConfigService,
|
2022-10-24 12:11:10 +02:00
|
|
|
PrismaService,
|
|
|
|
JobsService,
|
2022-11-28 15:04:32 +01:00
|
|
|
{
|
|
|
|
provide: "CONFIG_VARIABLES",
|
|
|
|
useFactory: async (prisma: PrismaService) => {
|
|
|
|
return await prisma.config.findMany();
|
|
|
|
},
|
|
|
|
inject: [PrismaService],
|
|
|
|
},
|
2022-10-24 12:11:10 +02:00
|
|
|
{
|
|
|
|
provide: APP_GUARD,
|
|
|
|
useClass: ThrottlerGuard,
|
|
|
|
},
|
|
|
|
],
|
2022-10-09 22:30:32 +02:00
|
|
|
controllers: [UserController, ShareController, FileController],
|
|
|
|
})
|
|
|
|
export class AppModule {}
|