From 145eabbd84dbb798791f523ce012797882c62e83 Mon Sep 17 00:00:00 2001 From: krvspacetime Date: Wed, 2 Apr 2025 05:58:18 +0800 Subject: [PATCH 1/3] feat/direct-max-file-size-input: add input field to directly input the max file size Introduce a text input field for file size in the git form to allow manual entry alongside the slider. Update the slider logic to handle input changes and ensure synchronization between the slider and the input field. This improves user experience by providing more flexibility in setting file size limits. --- .../templates/components/git_form.jinja | 10 +- src/static/js/utils.js | 370 ++++++++++-------- 2 files changed, 225 insertions(+), 155 deletions(-) diff --git a/src/server/templates/components/git_form.jinja b/src/server/templates/components/git_form.jinja index 764fff70..54dbb01b 100644 --- a/src/server/templates/components/git_form.jinja +++ b/src/server/templates/components/git_form.jinja @@ -84,8 +84,14 @@
-
= 1024) { - return Math.round(sizeInKB / 1024) + "mb"; + const mbValue = sizeInKB / 1024; + // If it's a whole number, display as integer + if (mbValue === Math.floor(mbValue)) { + return mbValue + "mb"; + } + // Otherwise limit to 2 decimal places for display + // Convert to fixed 2 decimal places + let formattedValue = mbValue.toFixed(2); + // Remove trailing zeros (e.g., 1.50 -> 1.5, 2.00 -> 2) + formattedValue = formattedValue.replace(/\.?0+$/, ""); + return formattedValue + "mb"; + } + + // For KB values, also limit to 2 decimal places if needed + if (sizeInKB === Math.floor(sizeInKB)) { + return sizeInKB + "kb"; + } else { + let formattedValue = parseFloat(sizeInKB).toFixed(2); + formattedValue = formattedValue.replace(/\.?0+$/, ""); + return formattedValue + "kb"; } - return Math.round(sizeInKB) + "kb"; } // Initialize slider on page load From 4921809131257302204048f0daa5963170cfca3a Mon Sep 17 00:00:00 2001 From: krvspacetime Date: Sun, 6 Apr 2025 21:38:50 +0800 Subject: [PATCH 3/3] fix: Make max file size support decimal values MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Modify slider_position and xact_file_size to handle float values in query processing - Adjust slider step to ny in the template to allow decimal increments - Refactor logSliderToSize and related functions in utils.js to support decimal precision --- src/server/query_processor.py | 17 +- src/server/routers/index.py | 2 +- .../templates/components/git_form.jinja | 7 +- src/static/js/utils.js | 185 ++++++++---------- 4 files changed, 96 insertions(+), 115 deletions(-) diff --git a/src/server/query_processor.py b/src/server/query_processor.py index 89eb84b1..1d5f08a7 100644 --- a/src/server/query_processor.py +++ b/src/server/query_processor.py @@ -1,6 +1,7 @@ """Process a query by parsing input, cloning a repository, and generating a summary.""" from functools import partial +from typing import Optional from fastapi import Request from starlette.templating import _TemplateResponse @@ -15,11 +16,11 @@ async def process_query( request: Request, input_text: str, - slider_position: int, + slider_position: float, pattern_type: str = "exclude", pattern: str = "", is_index: bool = False, - exact_file_size: str = None, + exact_file_size: Optional[str] = None, ) -> _TemplateResponse: """ Process a query by parsing input, cloning a repository, and generating a summary. @@ -33,7 +34,7 @@ async def process_query( The HTTP request object. input_text : str Input text provided by the user, typically a Git repository URL or slug. - slider_position : int + slider_position : float Position of the slider, representing the maximum file size in the query. pattern_type : str Type of pattern to use, either "include" or "exclude" (default is "exclude"). @@ -72,9 +73,9 @@ async def process_query( max_file_size = float(exact_file_size) * 1024 except ValueError: # If conversion fails, fall back to slider position - max_file_size = log_slider_to_size(slider_position) + max_file_size = log_slider_to_size(int(slider_position)) else: - max_file_size = log_slider_to_size(slider_position) + max_file_size = log_slider_to_size(int(slider_position)) context = { "request": request, @@ -137,7 +138,9 @@ async def process_query( "tree": tree, "content": content, "ingest_id": query.id, - "exact_file_size": exact_file_size, # Pass the exact file size back to the template + "exact_file_size": ( + exact_file_size if max_file_size < 1024 else max_file_size / 1024 + ), # Pass the exact file size back to the template } ) @@ -161,7 +164,7 @@ def _print_query(url: str, max_file_size: float, pattern_type: str, pattern: str The actual pattern string to include or exclude in the query. """ print(f"{Colors.WHITE}{url:<20}{Colors.END}", end="") - if int(max_file_size / 1024) != 50: + if max_file_size / 1024 != 50.00: # Format with up to 2 decimal places for KB values kb_value = max_file_size / 1024 # If it's a whole number, display as integer diff --git a/src/server/routers/index.py b/src/server/routers/index.py index 80ada539..fbfbd6df 100644 --- a/src/server/routers/index.py +++ b/src/server/routers/index.py @@ -34,7 +34,7 @@ async def home(request: Request) -> HTMLResponse: { "request": request, "examples": EXAMPLE_REPOS, - "default_file_size": 243, + "default_file_size": 243.14, }, ) diff --git a/src/server/templates/components/git_form.jinja b/src/server/templates/components/git_form.jinja index 42bf3f13..c05c0d6d 100644 --- a/src/server/templates/components/git_form.jinja +++ b/src/server/templates/components/git_form.jinja @@ -89,14 +89,15 @@
+ class="w-24 font-bold bg-transparent border-b-2 border-gray-900 focus:outline-none text-center" + value="{{ exact_file_size ~ 'kb' }}" + data-exact-value="{{ exact_file_size }}">
= 1024) { - const mbValue = sizeInKB / 1024; - // If it's a whole number, display as integer - if (mbValue === Math.floor(mbValue)) { - return mbValue + "mb"; - } - // Otherwise limit to 2 decimal places for display - // Convert to fixed 2 decimal places - let formattedValue = mbValue.toFixed(2); - // Remove trailing zeros (e.g., 1.50 -> 1.5, 2.00 -> 2) - formattedValue = formattedValue.replace(/\.?0+$/, ""); - return formattedValue + "mb"; + if (value >= 1024) { + const mbValue = value / 1024; + // Return with exactly 2 decimal places + return mbValue.toFixed(2).replace(/\.?0+$/, "") + "mb"; } - // For KB values, also limit to 2 decimal places if needed - if (sizeInKB === Math.floor(sizeInKB)) { - return sizeInKB + "kb"; - } else { - let formattedValue = parseFloat(sizeInKB).toFixed(2); - formattedValue = formattedValue.replace(/\.?0+$/, ""); - return formattedValue + "kb"; - } + // For KB values + return value.toFixed(2).replace(/\.?0+$/, "") + "kb"; } // Initialize slider on page load