Quellcode durchsuchen

refactor: simplify importExcelTags method in VideoMediaController to use Fastify multipart handling

Dave vor 3 Wochen
Ursprung
Commit
9053ac046c

+ 0 - 2
apps/box-mgnt-api/src/main.ts

@@ -10,8 +10,6 @@ import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
 import { Logger } from 'nestjs-pino';
 import multipart from '@fastify/multipart';
 import { AppModule } from './app.module';
-import fastifyStatic from '@fastify/static';
-import * as path from 'path';
 
 // @ts-expect-error: allow JSON.stringify(BigInt)
 BigInt.prototype.toJSON = function () {

+ 9 - 10
apps/box-mgnt-api/src/mgnt-backend/feature/video-media/video-media.controller.ts

@@ -282,22 +282,21 @@ export class VideoMediaController {
     schema: {
       type: 'object',
       properties: {
-        file: {
-          type: 'string',
-          format: 'binary',
-        },
+        file: { type: 'string', format: 'binary' },
       },
       required: ['file'],
     },
   })
   @Post('import/excel-tags')
-  @UseInterceptors(FileInterceptor('file', { storage: multer.memoryStorage() }))
-  async importExcelTags(@UploadedFile() file: Express.Multer.File) {
-    if (!file) {
-      throw new BadRequestException('No file uploaded');
-    }
+  async importExcelTags(@Req() req: FastifyRequest) {
+    // fastify multipart
+    const part = await (req as any).file();
+    if (!part) throw new BadRequestException('No file uploaded');
+
+    const buf = await part.toBuffer();
+    if (!buf?.length) throw new BadRequestException('Empty file');
 
-    return this.videoMediaService.importExcelTags(file);
+    return this.videoMediaService.importExcelTags(buf);
   }
 
   /**