From 772d1ad759dc987212dba330af36b01fec381a7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Jos=C3=A9=20Cano=20Duque?= Date: Tue, 7 Apr 2026 19:56:10 -0500 Subject: [PATCH] refactor: centralize SUPPORTED_EXTENSIONS in indexer.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously defined in 4 places (indexer.py, watcher.py, and twice in main.py). Now defined once in indexer.py and imported everywhere else — adding a new format like .docx only requires one change. Co-Authored-By: Claude Sonnet 4.6 --- backend/main.py | 6 +++--- backend/watcher.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/backend/main.py b/backend/main.py index f041c52..d3e7f52 100644 --- a/backend/main.py +++ b/backend/main.py @@ -16,7 +16,7 @@ load_dotenv() from .database import init_db -from .indexer import CompassIndexer +from .indexer import CompassIndexer, SUPPORTED_EXTENSIONS from .watcher import start_watcher from .chat import process_chat @@ -79,7 +79,7 @@ async def lifespan(app: FastAPI): app.state.indexer = CompassIndexer(model=COMPASS_MODEL, workspace=str(WORKSPACE)) for f in DOCS_PATH.iterdir(): - if f.suffix.lower() in {".pdf", ".md", ".markdown", ".txt"}: + if f.suffix.lower() in SUPPORTED_EXTENSIONS: app.state.indexer.index_document(str(f)) app.state.watcher = start_watcher(str(DOCS_PATH), app.state.indexer) @@ -170,7 +170,7 @@ async def upload(file: UploadFile = File(...), request: Request = None): safe_name = Path(file.filename).name ext = Path(safe_name).suffix.lower() - if ext not in {".pdf", ".md", ".markdown", ".txt"}: + if ext not in SUPPORTED_EXTENSIONS: raise HTTPException(status_code=400, detail="Formatos soportados: PDF, Markdown, TXT") contents = await file.read() diff --git a/backend/watcher.py b/backend/watcher.py index 3a8abf4..dfabbd4 100644 --- a/backend/watcher.py +++ b/backend/watcher.py @@ -3,9 +3,9 @@ from watchdog.observers import Observer from watchdog.events import FileSystemEventHandler -logger = logging.getLogger(__name__) +from .indexer import SUPPORTED_EXTENSIONS -SUPPORTED_EXTENSIONS = {".pdf", ".md", ".markdown", ".txt"} +logger = logging.getLogger(__name__) class DocumentHandler(FileSystemEventHandler):