// DB+S3 라운드트립 한 방 검증: `npm run files:check` // ensureFilesTable → saveFile → listFiles(포함 확인) → getObjectStream(바이트 일치) → 성공/실패. import { pool } from "../src/db.js"; import { ensureFilesTable, saveFile, listFiles, getObjectStream, } from "../src/files.js"; async function readStream(stream) { const chunks = []; for await (const c of stream) chunks.push(c); return Buffer.concat(chunks); } try { await ensureFilesTable(); const payload = Buffer.from(`poc check ${new Date().toISOString()}`); const row = await saveFile({ name: "poc-check.txt", contentType: "text/plain", body: payload, }); console.log("saveFile OK:", { id: row.id, key: row.key, size: row.size }); const files = await listFiles(); if (!files.some((f) => f.key === row.key)) { throw new Error("listFiles 에 방금 업로드한 key 가 없음"); } console.log("listFiles OK:", files.length, "rows"); const obj = await getObjectStream(row.key); const got = await readStream(obj.body); if (!got.equals(payload)) { throw new Error( `다운로드 바이트 불일치: expected ${payload.length}, got ${got.length}` ); } console.log("getObject OK: 바이트 일치", got.length, "bytes"); console.log("FILES CHECK OK ✅ (DB insert/select + MinIO put/get 라운드트립 성공)"); } catch (e) { console.error("FILES CHECK FAIL:", e.message); process.exitCode = 1; } finally { await pool.end(); }