Skip to content

Commit 94a373e

Browse files
committed
feat: replace ingest_id with digest_url for downloads
- Update `IngestResponse` schema to include `digest_url` instead of `ingest_id`. - Modify API and UI logic to handle `digest_url` for file downloads. - Disable local file download endpoint when S3 is enabled.
1 parent 416254c commit 94a373e

File tree

4 files changed

+31
-19
lines changed

4 files changed

+31
-19
lines changed

src/server/models.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ class IngestSuccessResponse(BaseModel):
7171
Short form of repository URL (user/repo).
7272
summary : str
7373
Summary of the ingestion process including token estimates.
74-
ingest_id : str
75-
Ingestion id used to download full context.
74+
digest_url : str
75+
URL to download the full digest content (either S3 URL or local download endpoint).
7676
tree : str
7777
File tree structure of the repository.
7878
content : str
@@ -89,7 +89,7 @@ class IngestSuccessResponse(BaseModel):
8989
repo_url: str = Field(..., description="Original repository URL")
9090
short_repo_url: str = Field(..., description="Short repository URL (user/repo)")
9191
summary: str = Field(..., description="Ingestion summary with token estimates")
92-
ingest_id: str = Field(..., description="Ingestion id used to download full context")
92+
digest_url: str = Field(..., description="URL to download the full digest content")
9393
tree: str = Field(..., description="File tree structure")
9494
content: str = Field(..., description="Processed file content")
9595
default_max_file_size: int = Field(..., description="File size slider position used")

src/server/query_processor.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,21 @@ async def process_query(
125125
summary=summary,
126126
)
127127

128+
# Generate digest_url based on S3 configuration
129+
if is_s3_enabled():
130+
digest_url = getattr(query, "s3_url", None)
131+
if not digest_url:
132+
# This should not happen if S3 upload was successful
133+
msg = "S3 is enabled but no S3 URL was generated"
134+
raise RuntimeError(msg)
135+
else:
136+
digest_url = f"/api/download/file/{query.id}"
137+
128138
return IngestSuccessResponse(
129139
repo_url=input_text,
130140
short_repo_url=short_repo_url,
131141
summary=summary,
132-
ingest_id=str(query.id),
142+
digest_url=digest_url,
133143
tree=tree,
134144
content=content,
135145
default_max_file_size=slider_position,

src/server/routers/ingest.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from gitingest.config import TMP_BASE_PATH
1111
from server.models import IngestRequest
1212
from server.routers_utils import COMMON_INGEST_RESPONSES, _perform_ingestion
13-
from server.s3_utils import get_s3_url_for_ingest_id, is_s3_enabled
13+
from server.s3_utils import is_s3_enabled
1414
from server.server_config import MAX_DISPLAY_SIZE
1515
from server.server_utils import limiter
1616

@@ -101,29 +101,31 @@ async def download_ingest(
101101
"""Download the first text file produced for an ingest ID.
102102
103103
**This endpoint retrieves the first ``*.txt`` file produced during the ingestion process**
104-
and returns it as a downloadable file. If S3 is enabled and the file is stored in S3,
105-
it redirects to the S3 URL. Otherwise, it serves the local file.
104+
and returns it as a downloadable file. When S3 is enabled, this endpoint is disabled
105+
and clients should use the S3 URL provided in the ingest response instead.
106106
107107
**Parameters**
108108
109109
- **ingest_id** (`UUID`): Identifier that the ingest step emitted
110110
111111
**Returns**
112112
113-
- **RedirectResponse**: Redirect to S3 URL if S3 is enabled and file exists in S3
114113
- **FileResponse**: Streamed response with media type ``text/plain`` for local files
115114
116115
**Raises**
117116
117+
- **HTTPException**: **503** - endpoint is disabled when S3 is enabled
118118
- **HTTPException**: **404** - digest directory is missing or contains no ``*.txt`` file
119119
- **HTTPException**: **403** - the process lacks permission to read the directory or file
120120
121121
"""
122-
# Check if S3 is enabled and file exists in S3
122+
# Disable download endpoint when S3 is enabled
123123
if is_s3_enabled():
124-
s3_url = get_s3_url_for_ingest_id(ingest_id)
125-
if s3_url:
126-
return RedirectResponse(url=s3_url, status_code=302)
124+
raise HTTPException(
125+
status_code=status.HTTP_503_SERVICE_UNAVAILABLE,
126+
detail="Download endpoint is disabled when S3 is enabled. "
127+
"Use the S3 URL provided in the ingest response instead.",
128+
)
127129

128130
# Fall back to local file serving
129131
# Normalize and validate the directory path

src/static/js/utils.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@ function handleSuccessfulResponse(data) {
172172
// Show results section
173173
showResults();
174174

175-
// Store the ingest_id for download functionality
176-
window.currentIngestId = data.ingest_id;
175+
// Store the digest_url for download functionality
176+
window.currentDigestUrl = data.digest_url;
177177

178178
// Set plain text content for summary, tree, and content
179179
document.getElementById('result-summary').value = data.summary || '';
@@ -271,9 +271,9 @@ function copyFullDigest() {
271271
}
272272

273273
function downloadFullDigest() {
274-
// Check if we have an ingest_id
275-
if (!window.currentIngestId) {
276-
console.error('No ingest_id available for download');
274+
// Check if we have a digest_url
275+
if (!window.currentDigestUrl) {
276+
console.error('No digest_url available for download');
277277

278278
return;
279279
}
@@ -289,10 +289,10 @@ function downloadFullDigest() {
289289
Downloading...
290290
`;
291291

292-
// Create a download link to the server endpoint
292+
// Create a download link using the digest_url
293293
const a = document.createElement('a');
294294

295-
a.href = `/api/download/file/${window.currentIngestId}`;
295+
a.href = window.currentDigestUrl;
296296
a.download = 'digest.txt';
297297
document.body.appendChild(a);
298298
a.click();

0 commit comments

Comments
 (0)