Create temp directory if it doesn't exist before saving images and cache

This commit is contained in:
암냥 2025-09-21 23:49:27 +09:00
commit 570e1b4679
2 changed files with 19 additions and 1 deletions

View file

@ -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");

View file

@ -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;