1+ import typing
2+
13from fastapi import APIRouter , Form , Request
24from fastapi .responses import HTMLResponse , Response
35from fastapi .templating import Jinja2Templates
810router = APIRouter ()
911templates = Jinja2Templates (directory = "templates" )
1012
13+
1114@router .get ("/extract/{full_path:path}" , response_model = None )
1215async def extract_content (
1316 request : Request ,
@@ -20,22 +23,24 @@ async def extract_content(
2023 pattern_type = query_params .get ("pattern_type" , "exclude" )
2124 pattern = query_params .get ("pattern" , "" )
2225
23- result_summary , tree , content = await process_query (
26+ processed_query = await process_query (
2427 request ,
2528 input_text = f"https://github.com/{ full_path } " ,
2629 slider_position = max_file_size ,
2730 pattern_type = pattern_type ,
2831 pattern = pattern ,
2932 is_index = False ,
30- raw_response = True
33+ raw_response = True ,
3134 )
32-
35+
36+ result_summary , tree , content = typing .cast (tuple [str , str , str ], processed_query )
37+
3338 response_parts = []
3439 if summary :
3540 response_parts .append (f"Summary:\n { result_summary } \n " )
3641 response_parts .append (f"Tree:\n { tree } \n " )
3742 response_parts .append (f"Content:\n { content } " )
38-
43+
3944 return Response (content = "\n " .join (response_parts ), media_type = "text/plain" )
4045 except Exception as e :
4146 return Response (
@@ -44,6 +49,7 @@ async def extract_content(
4449 status_code = 500 ,
4550 )
4651
52+
4753@router .get ("/{full_path:path}" )
4854async def catch_all (request : Request , full_path : str ) -> HTMLResponse :
4955 """
@@ -84,7 +90,7 @@ async def process_catch_all(
8490 max_file_size : int = Form (...),
8591 pattern_type : str = Form (...),
8692 pattern : str = Form (...),
87- ) -> HTMLResponse :
93+ ) -> HTMLResponse | tuple [ str , str , str ] :
8894 """
8995 Processes the form submission with user input for query parameters.
9096
0 commit comments