diff --git a/app/lib/image.ts b/app/lib/image.ts index dee576a..11f7c70 100644 --- a/app/lib/image.ts +++ b/app/lib/image.ts @@ -1,5 +1,6 @@ import path from "path"; import { join } from "path"; +import { mkdirSync, existsSync } from "fs"; import { createCanvas, loadImage, GlobalFonts } from "@napi-rs/canvas"; import { getMealInfo, getNutritionInfo, NameToEmoji, removeNutritionInfo } from "./meal"; // 이 함수의 내용은 제공되지 않았으므로 그대로 둡니다. import { getAllSchedules } from "./schedule"; @@ -58,6 +59,12 @@ export class CreateImage { } // VTS 관련 코드 주석 처리 const outPath = path.join("./temp", `${MLSV_YMD}.png`); // 경로 수정: "./temp/" -> "./temp" + + // temp 폴더가 없으면 생성 + if (!existsSync("./temp")) { + mkdirSync("./temp", { recursive: true }); + } + const buffer = canvas.toBuffer("image/png"); try { @@ -116,6 +123,12 @@ export class CreateImage { // 파일 저장 const outputFilePath = join("./", `temp/schedule-${year}-${month}.png`); + + // temp 폴더가 없으면 생성 + if (!existsSync("./temp")) { + mkdirSync("./temp", { recursive: true }); + } + const buffer = canvas.toBuffer("image/png"); require("fs").writeFileSync(outputFilePath, buffer); console.log("📅 | School Event Image Saved"); diff --git a/app/lib/schedule.ts b/app/lib/schedule.ts index 2fcbf76..f9bd3ab 100644 --- a/app/lib/schedule.ts +++ b/app/lib/schedule.ts @@ -1,4 +1,4 @@ -import { writeFileSync, existsSync, readFileSync } from "fs"; +import { writeFileSync, existsSync, readFileSync, mkdirSync } from "fs"; import * as cheerio from "cheerio"; const CACHE_FILE = "./temp/scheduleCache.json"; @@ -99,6 +99,11 @@ export async function getAllSchedules( const schedule = Object.assign({}, ...results); + // temp 폴더가 없으면 생성 + if (!existsSync("./temp")) { + mkdirSync("./temp", { recursive: true }); + } + writeFileSync(CACHE_FILE, JSON.stringify(schedule, null, 2), "utf-8"); console.log(`📦 캐시 저장됨 → ${CACHE_FILE}`); return schedule;