diff --git a/backend/routes/admin.js b/backend/routes/admin.js index 73201b7..75973de 100644 --- a/backend/routes/admin.js +++ b/backend/routes/admin.js @@ -7,6 +7,7 @@ import express from "express"; import jwt from "jsonwebtoken"; import { pool, loadTranslations } from "../lib/db.js"; +import { deleteFromS3, s3Config } from "../lib/s3.js"; const router = express.Router(); @@ -316,11 +317,21 @@ router.delete("/logfile", async (req, res) => { const file = rows[0]; - // S3에서 파일 삭제 (선택적 - 실패해도 DB 레코드는 삭제) + // S3에서 파일 삭제 try { - // S3 삭제는 복잡하므로 일단 DB만 삭제 + // s3_key가 있으면 해당 키로, 없으면 URL에서 추출 + const s3Key = + file.s3_key || + (file.s3_url + ? file.s3_url.replace(`${s3Config.publicUrl}/${s3Config.bucket}/`, "") + : null); + if (s3Key) { + await deleteFromS3(s3Config.bucket, decodeURIComponent(s3Key)); + console.log(`[Admin] S3에서 로그 파일 삭제 완료: ${s3Key}`); + } } catch (s3Error) { - console.error("[Admin] S3 삭제 실패:", s3Error); + console.error("[Admin] S3 삭제 실패:", s3Error.message); + // S3 삭제 실패해도 DB 레코드는 삭제 진행 } // DB에서 레코드 삭제