forked from cyclotruc/gitingest
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
56 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,55 @@ | ||
from ingest import ingest_from_query | ||
from utils.clone import clone_repo | ||
from utils.parse_url import parse_url | ||
from utils.log_convert import logSliderToSize | ||
from fastapi.templating import Jinja2Templates | ||
from fastapi import Request | ||
from config import MAX_DISPLAY_SIZE, EXAMPLE_REPOS | ||
|
||
async def process_query(query: dict) -> str: | ||
|
||
await clone_repo(query) | ||
|
||
result = ingest_from_query(query) | ||
txt_dump = result[1] + "\n" + result[2] | ||
with open(f"{query['local_path']}.txt", "w") as f: | ||
f.write(txt_dump) | ||
|
||
templates = Jinja2Templates(directory="templates") | ||
|
||
async def process_query(request: Request, input_text: str, max_file_size: int, is_index: bool) -> str: | ||
|
||
|
||
template = "index.jinja.html" if is_index else "github.jinja.html" | ||
slider_position = max_file_size | ||
size_in_kb = logSliderToSize(max_file_size) | ||
|
||
try: | ||
query = parse_url(input_text) | ||
query["max_file_size"] = int(size_in_kb) * 1024 | ||
await clone_repo(query) | ||
summary, tree, content = ingest_from_query(query) | ||
with open(f"{query['local_path']}.txt", "w") as f: | ||
f.write(tree + "\n" + content) | ||
except Exception as e: | ||
return templates.TemplateResponse( | ||
template, | ||
{ | ||
"request": request, | ||
"github_url": input_text, | ||
"error_message": f"Error: {e}", | ||
"examples": EXAMPLE_REPOS if is_index else [], | ||
"default_file_size": slider_position, | ||
} | ||
) | ||
|
||
if len(content) > MAX_DISPLAY_SIZE: | ||
content = f"(Files content cropped to {int(MAX_DISPLAY_SIZE/1000)}k characters, download full ingest to see more)\n" + content[:MAX_DISPLAY_SIZE] | ||
|
||
return result | ||
return templates.TemplateResponse( | ||
"index.jinja.html", | ||
{ | ||
"request": request, | ||
"github_url": input_text, | ||
"result": True, | ||
"summary": summary, | ||
"tree": tree, | ||
"content": content, | ||
"examples": EXAMPLE_REPOS if is_index else [], | ||
"ingest_id": query['id'], | ||
"default_file_size": slider_position, | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters