From 333cb01229864af9e5107c48fbff2bc0e907409f Mon Sep 17 00:00:00 2001 From: TylerCG <117808427+TylerCG@users.noreply.github.com> Date: Sun, 22 Jun 2025 17:33:43 -0400 Subject: [PATCH] added html frontend --- .gitignore | 54 +++++++++++++++++ backend/main.py | 30 +++++++--- backend/static/index.html | 120 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 197 insertions(+), 7 deletions(-) create mode 100644 .gitignore create mode 100644 backend/static/index.html diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ae95cfb --- /dev/null +++ b/.gitignore @@ -0,0 +1,54 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# Virtual environments +.venv/ +env/ +venv/ + +# VSCode settings +.vscode/ + +# macOS and Linux system files +.DS_Store +Thumbs.db + +# Docker-related +*.log +*.pid +*.tar +*.sock + +# Ignore test output or temporary files +*.tmp +*.bak +*.swp + +# Python artifacts +*.egg-info/ +*.egg +dist/ +build/ + +# PyInstaller +*.spec + +# Coverage reports +htmlcov/ +.coverage +.cache +nosetests.xml +coverage.xml +*.cover + +# MyPy +.mypy_cache/ + +# Presets and data you don’t want in Git +presets/ +data/ + +# Frontend build output (optional if using React) +frontend/build/ diff --git a/backend/main.py b/backend/main.py index 8968dac..2cdcc43 100644 --- a/backend/main.py +++ b/backend/main.py @@ -1,6 +1,7 @@ from fastapi import FastAPI, UploadFile, File, Form, HTTPException from fastapi.responses import FileResponse from fastapi.middleware.cors import CORSMiddleware +from fastapi.staticfiles import StaticFiles import yaml import os import subprocess @@ -9,14 +10,21 @@ from utils import parse_yaml_config, get_presets_dir app = FastAPI() -# Allow CORS (frontend access) +# CORS setup for frontend use app.add_middleware( CORSMiddleware, - allow_origins=["*"], + allow_origins=["*"], # For dev; restrict for production allow_methods=["*"], allow_headers=["*"], ) +# Serve static files (e.g., HTML GUI) +app.mount("/static", StaticFiles(directory="static"), name="static") + +@app.get("/") +def read_root(): + return FileResponse("static/index.html") + @app.post("/upload-config/") async def upload_config(file: UploadFile = File(...)): config_data = yaml.safe_load(await file.read()) @@ -26,16 +34,24 @@ async def upload_config(file: UploadFile = File(...)): async def transcode(yaml_config: dict): try: ffmpeg_cmd = parse_yaml_config(yaml_config) - subprocess.run(ffmpeg_cmd, check=True) - return {"status": "success", "cmd": ffmpeg_cmd} - except Exception as e: - raise HTTPException(status_code=500, detail=str(e)) + process = subprocess.run(ffmpeg_cmd, check=True, capture_output=True, text=True) + return { + "status": "success", + "cmd": ffmpeg_cmd, + "output": process.stdout, + "error": process.stderr + } + except subprocess.CalledProcessError as e: + raise HTTPException(status_code=500, detail=e.stderr or str(e)) @app.get("/browse/") def browse(path: str = "/data"): if not os.path.exists(path): raise HTTPException(status_code=404, detail="Path not found") - entries = [{"name": f, "is_dir": os.path.isdir(os.path.join(path, f))} for f in os.listdir(path)] + entries = [{ + "name": f, + "is_dir": os.path.isdir(os.path.join(path, f)) + } for f in os.listdir(path)] return {"path": path, "entries": entries} @app.post("/save-preset/") diff --git a/backend/static/index.html b/backend/static/index.html new file mode 100644 index 0000000..6970a31 --- /dev/null +++ b/backend/static/index.html @@ -0,0 +1,120 @@ + + +
+ + +