From 14eda1bf5bd7c4aaa42eef8b7493cf9301472b05 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Fri, 6 Sep 2024 15:52:23 +0200 Subject: [PATCH] fix: pdf download FONTS_DIR issue --- backend/open_webui/apps/webui/routers/utils.py | 7 ++----- backend/open_webui/env.py | 2 ++ 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/backend/open_webui/apps/webui/routers/utils.py b/backend/open_webui/apps/webui/routers/utils.py index 731f98784..bb556b318 100644 --- a/backend/open_webui/apps/webui/routers/utils.py +++ b/backend/open_webui/apps/webui/routers/utils.py @@ -4,6 +4,7 @@ from pathlib import Path import black import markdown from open_webui.config import DATA_DIR, ENABLE_ADMIN_EXPORT +from open_webui.env import FONTS_DIR from open_webui.constants import ERROR_MESSAGES from fastapi import APIRouter, Depends, HTTPException, Response, status from fpdf import FPDF @@ -57,14 +58,10 @@ class ChatForm(BaseModel): async def download_chat_as_pdf( form_data: ChatForm, ): + global FONTS_DIR pdf = FPDF() pdf.add_page() - # When running in docker, workdir is /app/backend, so fonts is in /app/backend/static/fonts - FONTS_DIR = Path("./static/fonts") - - # Non Docker Installation - # When running using `pip install` the static directory is in the site packages. if not FONTS_DIR.exists(): FONTS_DIR = Path(site.getsitepackages()[0]) / "static/fonts" diff --git a/backend/open_webui/env.py b/backend/open_webui/env.py index 865d61003..b716769c2 100644 --- a/backend/open_webui/env.py +++ b/backend/open_webui/env.py @@ -198,6 +198,8 @@ if FROM_INIT_PY: DATA_DIR = Path(os.getenv("DATA_DIR", OPEN_WEBUI_DIR / "data")) +FONTS_DIR = Path(os.getenv("FONTS_DIR", OPEN_WEBUI_DIR / "static" / "fonts")) + FRONTEND_BUILD_DIR = Path(os.getenv("FRONTEND_BUILD_DIR", BASE_DIR / "build")).resolve() if FROM_INIT_PY: