fix: pdf download FONTS_DIR issue

This commit is contained in:
Timothy J. Baek 2024-09-06 15:52:23 +02:00
parent 2d4cdc5be9
commit 14eda1bf5b
2 changed files with 4 additions and 5 deletions

View File

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

View File

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