This commit is contained in:
imnyang 2025-05-31 01:07:25 +09:00
commit 6c4f5f799e
No known key found for this signature in database
GPG key ID: 356406A02D4AFA55
5 changed files with 416 additions and 11 deletions

View file

@ -1,7 +1,7 @@
import path from "path";
import { join } from "path";
import { createCanvas, loadImage, GlobalFonts } from "@napi-rs/canvas";
import { getMealInfo, NameToEmoji } from "./meal"; // 이 함수의 내용은 제공되지 않았으므로 그대로 둡니다.
import { getMealInfo, getNutritionInfo, NameToEmoji, removeNutritionInfo } from "./meal"; // 이 함수의 내용은 제공되지 않았으므로 그대로 둡니다.
import { getAllSchedules } from "./schedule";
import { isVTS } from "./vts";
@ -9,7 +9,7 @@ GlobalFonts.registerFromPath('./template/Pretendard-Bold.ttf', 'Pretendard Bold'
GlobalFonts.registerFromPath('./template/NotoColorEmoji-Regular.ttf', 'NotoColorEmoji Regular')
export class CreateImage {
static async PostMeal(MLSV_YMD: string): Promise<void> {
static async PostMeal(MLSV_YMD: string): Promise<{ [key: string]: any } | undefined> {
const mealInfo = await getMealInfo(MLSV_YMD);
const img = await loadImage(path.join("./template/skeleton.png"));
const canvas = createCanvas(img.width, img.height);
@ -20,7 +20,7 @@ export class CreateImage {
ctx.fillStyle = "white";
ctx.textAlign = "left";
const lines = mealInfo.meal.split("\n").reverse();
const lines = removeNutritionInfo(mealInfo.meal).split("\n").reverse();
let emojis = (await NameToEmoji(lines.toString())).split(",");
if (lines.length !== emojis.length) {
@ -65,6 +65,16 @@ export class CreateImage {
console.log("🍲 | Meal Info Image Saved");
} catch (error) {
console.error("Error saving meal info image:", error);
} finally {
const meals = removeNutritionInfo(mealInfo.meal).split("\n");
const nutritionInfo = getNutritionInfo(mealInfo.meal);
const retrunValue: { [key: string]: any } = {};
for (let i = 0; i < meals.length; i++) {
const meal = (meals[i] ?? "").trim();
retrunValue[meal] = nutritionInfo[i] || [];
}
return retrunValue;
}
}