mirror of
https://github.com/kuhyx/testsAndMisc-archive.git
synced 2026-11-11 12:47:34 +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
29 lines
824 B
TypeScript
29 lines
824 B
TypeScript
const BACKEND_URL = "http://localhost:3000/files/upload";
|
|
|
|
export interface UploadResult {
|
|
filename: string;
|
|
originalname: string;
|
|
size: number;
|
|
savedAt: string;
|
|
}
|
|
|
|
/** Upload a single file to the backend. */
|
|
async function uploadOne(file: File): Promise<UploadResult> {
|
|
const form = new FormData();
|
|
form.append("file", file);
|
|
const res = await fetch(BACKEND_URL, { method: "POST", body: form });
|
|
if (!res.ok) {
|
|
throw new Error(`Upload failed for ${file.name}: ${res.statusText}`);
|
|
}
|
|
return res.json() as Promise<UploadResult>;
|
|
}
|
|
|
|
/** Upload all caught files sequentially to the backend. */
|
|
export async function uploadFiles(files: File[]): Promise<UploadResult[]> {
|
|
const results: UploadResult[] = [];
|
|
for (const file of files) {
|
|
results.push(await uploadOne(file));
|
|
}
|
|
return results;
|
|
}
|