import { ConfigurationModule } from '@ghostfolio/api/services/configuration/configuration.module'; import { PrismaModule } from '@ghostfolio/api/services/prisma/prisma.module'; import { Module } from '@nestjs/common'; import { MulterModule } from '@nestjs/platform-express'; import { diskStorage } from 'multer'; import { existsSync, mkdirSync } from 'node:fs'; import { join } from 'node:path'; import { v4 as uuidv4 } from 'uuid'; import { CellMappingModule } from '../cell-mapping/cell-mapping.module'; import { UploadModule } from '../upload/upload.module'; import { K1ImportController } from './k1-import.controller'; import { K1ImportService } from './k1-import.service'; import { K1AggregationService } from './k1-aggregation.service'; import { K1AllocationService } from './k1-allocation.service'; import { K1ConfidenceService } from './k1-confidence.service'; import { K1FieldMapperService } from './k1-field-mapper.service'; import { AzureExtractor } from './extractors/azure-extractor'; import { PdfParseExtractor } from './extractors/pdf-parse-extractor'; import { TesseractExtractor } from './extractors/tesseract-extractor'; const uploadDir = process.env.UPLOAD_DIR || join(process.cwd(), 'uploads'); @Module({ controllers: [K1ImportController], exports: [K1ImportService], imports: [ CellMappingModule, ConfigurationModule, MulterModule.register({ limits: { fileSize: 25 * 1024 * 1024 // 25 MB }, storage: diskStorage({ destination: (_req, _file, cb) => { const now = new Date(); const yearDir = now.getFullYear().toString(); const monthDir = (now.getMonth() + 1).toString().padStart(2, '0'); const subDir = join(uploadDir, yearDir, monthDir); if (!existsSync(subDir)) { mkdirSync(subDir, { recursive: true }); } cb(null, subDir); }, filename: (_req, file, cb) => { const ext = file.originalname.split('.').pop(); cb(null, `${uuidv4()}.${ext}`); } }) }), PrismaModule, UploadModule ], providers: [ AzureExtractor, K1AggregationService, K1AllocationService, K1ConfidenceService, K1FieldMapperService, K1ImportService, PdfParseExtractor, TesseractExtractor ] }) export class K1ImportModule {}