From 78df8a376e82ea700b1af14987c35b8e0ce4f129 Mon Sep 17 00:00:00 2001 From: Maxime Naulleau Date: Fri, 6 Dec 2024 20:00:19 +0100 Subject: [PATCH] Logs to debug files upload --- apps/api/package.json | 4 ++-- .../adapters/primary/nestjs/files.controller.ts | 1 + .../business-logic/use-cases/file-upload/upload-file.ts | 2 ++ .../adapters/primary/nestjs/reports.controller.ts | 1 + .../use-cases/report-attach-file/attach-report-file.ts | 2 ++ apps/api/src/shared-kernel/adapters/primary/nestjs/env.ts | 6 +++--- 6 files changed, 11 insertions(+), 5 deletions(-) diff --git a/apps/api/package.json b/apps/api/package.json index 2a3140e..6cee918 100644 --- a/apps/api/package.json +++ b/apps/api/package.json @@ -10,7 +10,7 @@ "format": "prettier --write \"src/**/*.ts\"", "format:check": "prettier --check \"src/**/*.ts\"", "start": "nest start", - "dev": "nest start --watch", + "dev": "dotenvx run -- nest start --watch", "start:debug": "nest start --debug --watch", "start:prod": "node dist/src/main", "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix", @@ -32,7 +32,7 @@ "drizzle:migrate": "drizzle-kit migrate", "drizzle:migrate:prod": "pnpm drizzle-kit migrate --config dist/drizzle.config.js", "cli:seed": "ts-node -r tsconfig-paths/register cli/seed.ts", - "cli:upload-nomination-files:local": "ts-node -r tsconfig-paths/register cli/import-nominations-from-local-file/run-import-nominations-from-local-file-cli.ts", + "cli:upload-nomination-files:local": "dotenvx run -- ts-node -r tsconfig-paths/register cli/import-nominations-from-local-file/run-import-nominations-from-local-file-cli.ts", "scalingo:upload-nomination-files:staging": "dotenvx run -f .env.scalingo-upload.staging -f .env.scalingo-upload -- ./scripts/import-nominations-from-local-file-to-scalingo.sh", "scalingo:upload-nomination-files:production": "dotenvx run -f .env.scalingo-upload.production -f .env.scalingo-upload -- ./scripts/import-nominations-from-local-file-to-scalingo.sh" }, diff --git a/apps/api/src/files-context/adapters/primary/nestjs/files.controller.ts b/apps/api/src/files-context/adapters/primary/nestjs/files.controller.ts index e2b592f..892b67f 100644 --- a/apps/api/src/files-context/adapters/primary/nestjs/files.controller.ts +++ b/apps/api/src/files-context/adapters/primary/nestjs/files.controller.ts @@ -30,6 +30,7 @@ export class FilesController { @Query() query: FileUploadQueryDto, @UploadedFile() file: Express.Multer.File, ) { + console.log('query', query); const { bucket, path, fileId } = query; return this.uploadFileUseCase.execute( fileId, diff --git a/apps/api/src/files-context/business-logic/use-cases/file-upload/upload-file.ts b/apps/api/src/files-context/business-logic/use-cases/file-upload/upload-file.ts index afd935c..1d0f3f8 100644 --- a/apps/api/src/files-context/business-logic/use-cases/file-upload/upload-file.ts +++ b/apps/api/src/files-context/business-logic/use-cases/file-upload/upload-file.ts @@ -33,6 +33,7 @@ export class UploadFileUseCase { // Order matters, file isn't uploaded if saving in repository fails await this.fileRepository.save(fileDocument)(trx); + console.log('files context - saved file'); await this.s3StorageProvider.uploadFile( file, fileName, @@ -40,6 +41,7 @@ export class UploadFileUseCase { bucket, filePath, ); + console.log('files context - uploaded file'); }); } } diff --git a/apps/api/src/reports-context/adapters/primary/nestjs/reports.controller.ts b/apps/api/src/reports-context/adapters/primary/nestjs/reports.controller.ts index 0aec549..9f297ee 100644 --- a/apps/api/src/reports-context/adapters/primary/nestjs/reports.controller.ts +++ b/apps/api/src/reports-context/adapters/primary/nestjs/reports.controller.ts @@ -84,6 +84,7 @@ export class ReportsController implements IReportController { @Param() { id }: ReportsEndpoints['attachFile']['Params'], @UploadedFile() file: Express.Multer.File, ): Promise { + console.log('attach file', id, file); return this.attachReportFileUseCase.execute( id, file.originalname, diff --git a/apps/api/src/reports-context/business-logic/use-cases/report-attach-file/attach-report-file.ts b/apps/api/src/reports-context/business-logic/use-cases/report-attach-file/attach-report-file.ts index 2d2d29f..af04853 100644 --- a/apps/api/src/reports-context/business-logic/use-cases/report-attach-file/attach-report-file.ts +++ b/apps/api/src/reports-context/business-logic/use-cases/report-attach-file/attach-report-file.ts @@ -35,11 +35,13 @@ export class AttachReportFileUseCase { // Order matters, file isn't attached if saving in repository fails await this.reportAttachedFileRepository.save(attachedFile)(trx); + console.log('saved attached file'); await this.reportFileService.uploadFile( attachedFile, fileBuffer, filePath, ); + console.log('uploaded file'); }); } } diff --git a/apps/api/src/shared-kernel/adapters/primary/nestjs/env.ts b/apps/api/src/shared-kernel/adapters/primary/nestjs/env.ts index 349faab..d62f992 100644 --- a/apps/api/src/shared-kernel/adapters/primary/nestjs/env.ts +++ b/apps/api/src/shared-kernel/adapters/primary/nestjs/env.ts @@ -65,9 +65,9 @@ export const defaultApiConfig = { scaleway: { endpoint: { scheme: 'https', baseDomain: baseScalewayDomain }, region: 'fr-par', - encryptionKeyBase64: Buffer.from(crypto.randomBytes(32)).toString( - 'base64', - ), + encryptionKeyBase64: + process.env.SCW_ENCRYPTION_KEY ?? + Buffer.from(crypto.randomBytes(32)).toString('base64'), credentials: { accessKeyId: process.env.SCW_ACCESS_KEY!, secretAccessKey: process.env.SCW_SECRET_KEY!,