fix: 로그 삭제 시 RustFS(S3)에서도 파일 삭제
- deleteFromS3 함수 import 추가 - s3_key 또는 s3_url에서 키 추출하여 S3에서 삭제 - S3 삭제 실패해도 DB 레코드는 삭제되도록 처리
This commit is contained in:
parent
3c22f62c65
commit
a5e54e1ac6
1 changed files with 14 additions and 3 deletions
|
|
@ -7,6 +7,7 @@
|
||||||
import express from "express";
|
import express from "express";
|
||||||
import jwt from "jsonwebtoken";
|
import jwt from "jsonwebtoken";
|
||||||
import { pool, loadTranslations } from "../lib/db.js";
|
import { pool, loadTranslations } from "../lib/db.js";
|
||||||
|
import { deleteFromS3, s3Config } from "../lib/s3.js";
|
||||||
|
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
|
||||||
|
|
@ -316,11 +317,21 @@ router.delete("/logfile", async (req, res) => {
|
||||||
|
|
||||||
const file = rows[0];
|
const file = rows[0];
|
||||||
|
|
||||||
// S3에서 파일 삭제 (선택적 - 실패해도 DB 레코드는 삭제)
|
// S3에서 파일 삭제
|
||||||
try {
|
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) {
|
} catch (s3Error) {
|
||||||
console.error("[Admin] S3 삭제 실패:", s3Error);
|
console.error("[Admin] S3 삭제 실패:", s3Error.message);
|
||||||
|
// S3 삭제 실패해도 DB 레코드는 삭제 진행
|
||||||
}
|
}
|
||||||
|
|
||||||
// DB에서 레코드 삭제
|
// DB에서 레코드 삭제
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue