testsAndMisc/bucket_catch/packages/backend/src/files/files.controller.ts
Krzysztof kuhy Rudnicki 5a9296d8aa Add bucket_catch: osu!catch browser game with 100% frontend test coverage
Frontend (React 19 + Vite 6 + TypeScript strict):
- DropZone, ModeSelect, GameCanvas, PuzzleCanvas, ScoreScreen, PuzzleResult
- File-drop game with AABB collision; download (JSZip) and upload (NestJS) modes
- Puzzle mode: NxN image slice via OffscreenCanvas; Union-Find spatial clustering
  guarantees 100% catch rate is always achievable regardless of piece speeds
- ESLint typescript-eslint strict-type-checked (zero errors)
- 145 Vitest tests; 100% coverage on statements/branches/functions/lines

Backend (NestJS 11):
- POST /files/upload (multer disk storage) and GET /health

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YZ8QTmreFcaqrsvVb38Grd
2026-06-27 12:21:35 +02:00

39 lines
1.1 KiB
TypeScript

import {
Controller,
Post,
UploadedFile,
UseInterceptors,
BadRequestException,
} from "@nestjs/common";
import { FileInterceptor } from "@nestjs/platform-express";
import { diskStorage } from "multer";
import { extname } from "path";
import { FilesService, UploadResult } from "./files.service";
@Controller("files")
export class FilesController {
constructor(private readonly filesService: FilesService) {}
@Post("upload")
@UseInterceptors(
FileInterceptor("file", {
storage: diskStorage({
destination: "./uploads",
filename: (_req, file, cb) => {
const uniqueSuffix = `${Date.now().toString()}-${Math.round(Math.random() * 1e9).toString()}`;
cb(null, uniqueSuffix + extname(file.originalname));
},
}),
limits: { fileSize: 100 * 1024 * 1024 }, // 100 MB
}),
)
uploadFile(
@UploadedFile() file: Express.Multer.File | undefined,
): UploadResult {
if (!file) {
throw new BadRequestException("No file provided");
}
return this.filesService.processUpload(file);
}
}