Enhance loadProcessedItems function to handle directory case by removing it before processing

This commit is contained in:
암냥 2025-12-11 01:34:28 +09:00
commit 4d32202961
No known key found for this signature in database

View file

@ -1,9 +1,16 @@
import { readFileSync, writeFileSync, existsSync } from "fs"; import { readFileSync, writeFileSync, existsSync, statSync, rmSync } from "fs";
import { PROCESSED_FILE } from "./config"; import { PROCESSED_FILE } from "./config";
export function loadProcessedItems(): Record<string, string[]> { export function loadProcessedItems(): Record<string, string[]> {
if (existsSync(PROCESSED_FILE)) { if (existsSync(PROCESSED_FILE)) {
try { try {
// 디렉토리인 경우 삭제
const stat = statSync(PROCESSED_FILE);
if (stat.isDirectory()) {
console.warn(`${PROCESSED_FILE}이(가) 디렉토리입니다. 삭제 후 새로 생성합니다.`);
rmSync(PROCESSED_FILE, { recursive: true });
return {};
}
return JSON.parse(readFileSync(PROCESSED_FILE, "utf-8")); return JSON.parse(readFileSync(PROCESSED_FILE, "utf-8"));
} catch (error) { } catch (error) {
console.error("처리된 항목 파일 읽기 실패:", error); console.error("처리된 항목 파일 읽기 실패:", error);