Create temp directory if it doesn't exist before saving images and cache
This commit is contained in:
parent
e7f142ecff
commit
570e1b4679
2 changed files with 19 additions and 1 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import { join } from "path";
|
import { join } from "path";
|
||||||
|
import { mkdirSync, existsSync } from "fs";
|
||||||
import { createCanvas, loadImage, GlobalFonts } from "@napi-rs/canvas";
|
import { createCanvas, loadImage, GlobalFonts } from "@napi-rs/canvas";
|
||||||
import { getMealInfo, getNutritionInfo, NameToEmoji, removeNutritionInfo } from "./meal"; // 이 함수의 내용은 제공되지 않았으므로 그대로 둡니다.
|
import { getMealInfo, getNutritionInfo, NameToEmoji, removeNutritionInfo } from "./meal"; // 이 함수의 내용은 제공되지 않았으므로 그대로 둡니다.
|
||||||
import { getAllSchedules } from "./schedule";
|
import { getAllSchedules } from "./schedule";
|
||||||
|
|
@ -58,6 +59,12 @@ export class CreateImage {
|
||||||
} // VTS 관련 코드 주석 처리
|
} // VTS 관련 코드 주석 처리
|
||||||
|
|
||||||
const outPath = path.join("./temp", `${MLSV_YMD}.png`); // 경로 수정: "./temp/" -> "./temp"
|
const outPath = path.join("./temp", `${MLSV_YMD}.png`); // 경로 수정: "./temp/" -> "./temp"
|
||||||
|
|
||||||
|
// temp 폴더가 없으면 생성
|
||||||
|
if (!existsSync("./temp")) {
|
||||||
|
mkdirSync("./temp", { recursive: true });
|
||||||
|
}
|
||||||
|
|
||||||
const buffer = canvas.toBuffer("image/png");
|
const buffer = canvas.toBuffer("image/png");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
@ -116,6 +123,12 @@ export class CreateImage {
|
||||||
|
|
||||||
// 파일 저장
|
// 파일 저장
|
||||||
const outputFilePath = join("./", `temp/schedule-${year}-${month}.png`);
|
const outputFilePath = join("./", `temp/schedule-${year}-${month}.png`);
|
||||||
|
|
||||||
|
// temp 폴더가 없으면 생성
|
||||||
|
if (!existsSync("./temp")) {
|
||||||
|
mkdirSync("./temp", { recursive: true });
|
||||||
|
}
|
||||||
|
|
||||||
const buffer = canvas.toBuffer("image/png");
|
const buffer = canvas.toBuffer("image/png");
|
||||||
require("fs").writeFileSync(outputFilePath, buffer);
|
require("fs").writeFileSync(outputFilePath, buffer);
|
||||||
console.log("📅 | School Event Image Saved");
|
console.log("📅 | School Event Image Saved");
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { writeFileSync, existsSync, readFileSync } from "fs";
|
import { writeFileSync, existsSync, readFileSync, mkdirSync } from "fs";
|
||||||
import * as cheerio from "cheerio";
|
import * as cheerio from "cheerio";
|
||||||
|
|
||||||
const CACHE_FILE = "./temp/scheduleCache.json";
|
const CACHE_FILE = "./temp/scheduleCache.json";
|
||||||
|
|
@ -99,6 +99,11 @@ export async function getAllSchedules(
|
||||||
|
|
||||||
const schedule = Object.assign({}, ...results);
|
const schedule = Object.assign({}, ...results);
|
||||||
|
|
||||||
|
// temp 폴더가 없으면 생성
|
||||||
|
if (!existsSync("./temp")) {
|
||||||
|
mkdirSync("./temp", { recursive: true });
|
||||||
|
}
|
||||||
|
|
||||||
writeFileSync(CACHE_FILE, JSON.stringify(schedule, null, 2), "utf-8");
|
writeFileSync(CACHE_FILE, JSON.stringify(schedule, null, 2), "utf-8");
|
||||||
console.log(`📦 캐시 저장됨 → ${CACHE_FILE}`);
|
console.log(`📦 캐시 저장됨 → ${CACHE_FILE}`);
|
||||||
return schedule;
|
return schedule;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue