Skip to content

Commit 10ef67d

Browse files
committed
fix: go back to IngestRequest schema
1 parent f94bbf9 commit 10ef67d

File tree

1 file changed

+11
-36
lines changed

1 file changed

+11
-36
lines changed

src/server/routers/ingest.py

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
"""Ingest endpoint for the API."""
22

3-
from __future__ import annotations
3+
from typing import Annotated, Union
44

5-
from typing import Any
6-
7-
from fastapi import APIRouter, HTTPException, Request, status
5+
from fastapi import APIRouter, Body, HTTPException, Request, status
86
from fastapi.responses import FileResponse, JSONResponse, RedirectResponse
97
from prometheus_client import Counter
108

119
from gitingest.config import TMP_BASE_PATH
1210
from gitingest.utils.s3_utils import get_s3_url_for_ingest_id, is_s3_enabled
13-
from server.models import IngestErrorResponse
11+
from server.models import IngestRequest
1412
from server.routers_utils import COMMON_INGEST_RESPONSES, _perform_ingestion
1513
from server.server_config import MAX_DISPLAY_SIZE
1614
from server.server_utils import limiter
@@ -24,7 +22,7 @@
2422
@limiter.limit("10/minute")
2523
async def api_ingest(
2624
request: Request, # noqa: ARG001 (unused-function-argument) # pylint: disable=unused-argument
27-
ingest_data: dict[str, Any],
25+
ingest_request: Annotated[IngestRequest, Body(...)],
2826
) -> JSONResponse:
2927
"""Ingest a Git repository and return processed content.
3028
@@ -41,38 +39,15 @@ async def api_ingest(
4139
- **JSONResponse**: Success response with ingestion results or error response with appropriate HTTP status code
4240
4341
"""
44-
45-
# Extract and validate data from dictionary
46-
def _validate_input_text(text: str) -> None:
47-
if not text:
48-
msg = "input_text cannot be empty"
49-
raise ValueError(msg)
50-
51-
try:
52-
input_text = ingest_data.get("input_text", "").strip()
53-
_validate_input_text(input_text)
54-
55-
max_file_size = ingest_data.get("max_file_size", 243)
56-
if isinstance(max_file_size, str):
57-
max_file_size = int(max_file_size)
58-
59-
pattern_type = ingest_data.get("pattern_type", "exclude")
60-
pattern = ingest_data.get("pattern", "").strip()
61-
token = ingest_data.get("token") or None
62-
63-
except (ValueError, TypeError) as e:
64-
error_response = IngestErrorResponse(error=f"Invalid request data: {e}")
65-
return JSONResponse(status_code=status.HTTP_400_BAD_REQUEST, content=error_response.model_dump())
66-
6742
response = await _perform_ingestion(
68-
input_text=input_text,
69-
max_file_size=max_file_size,
70-
pattern_type=pattern_type,
71-
pattern=pattern,
72-
token=token,
43+
input_text=ingest_request.input_text,
44+
max_file_size=ingest_request.max_file_size,
45+
pattern_type=ingest_request.pattern_type.value,
46+
pattern=ingest_request.pattern,
47+
token=ingest_request.token,
7348
)
7449
# limit URL to 255 characters
75-
ingest_counter.labels(status=response.status_code, url=input_text[:255]).inc()
50+
ingest_counter.labels(status=response.status_code, url=ingest_request.input_text[:255]).inc()
7651
return response
7752

7853

@@ -119,7 +94,7 @@ async def api_ingest_get(
11994

12095

12196
@router.get("/api/download/file/{ingest_id}", response_model=None)
122-
async def download_ingest(ingest_id: str) -> RedirectResponse | FileResponse:
97+
async def download_ingest(ingest_id: str) -> Union[RedirectResponse, FileResponse]: # noqa: FA100
12398
"""Download the first text file produced for an ingest ID.
12499
125100
**This endpoint retrieves the first ``*.txt`` file produced during the ingestion process**

0 commit comments

Comments
 (0)