mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-11-10 20:27:02 +01:00
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
39 lines
1.1 KiB
TypeScript
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);
|
|
}
|
|
}
|