service change

This commit is contained in:
Aron Petau 2025-11-20 12:53:12 +01:00
parent d6edf761ac
commit 5b0a0292e1
4 changed files with 134 additions and 5 deletions

View file

@ -14,8 +14,13 @@ from app.models import Task
from dotenv import load_dotenv
from PIL import Image, ImageDraw, ImageFont
# Load environment variables
load_dotenv()
app = FastAPI()
app.add_middleware(SessionMiddleware, secret_key="CHANGE_THIS_SECRET")
# Use environment variable for session secret, fallback to random for dev
SESSION_SECRET = os.getenv("SESSION_SECRET", "CHANGE_THIS_SECRET")
app.add_middleware(SessionMiddleware, secret_key=SESSION_SECRET)
templates = Jinja2Templates(directory="app/templates")
app.mount("/static", StaticFiles(directory="app/static"), name="static")
app.mount("/out", StaticFiles(directory="out"), name="out")
@ -240,7 +245,6 @@ def print_task(request: Request, task_id: str):
# Print to physical printer if enabled
if ENABLE_PHYSICAL_PRINTER:
print(f"[DEBUG] Attempting to print to {PRINTER_DEVICE} at {PRINTER_BAUDRATE} baud...")
try:
printer = escpos.printer.Serial(devfile=PRINTER_DEVICE, baudrate=PRINTER_BAUDRATE, timeout=1)
@ -249,13 +253,10 @@ def print_task(request: Request, task_id: str):
printer.text("\n\n") # Add some spacing after image
printer.cut()
print(f"[DEBUG] Print command sent successfully")
except Exception as print_err:
print(f"[ERROR] Printer failed: {print_err}")
import traceback
traceback.print_exc()
else:
print(f"[DEBUG] Physical printer disabled, skipping print")
task.status = "printed"
msg = "success"