Skip to content

Commit d2ccfb8

Browse files
committed
idk
1 parent c4ee8b3 commit d2ccfb8

File tree

1 file changed

+16
-72
lines changed

1 file changed

+16
-72
lines changed

src/server/routers/ingest.py

Lines changed: 16 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -129,125 +129,69 @@ async def download_ingest(
129129
"""
130130
logger = logging.getLogger(__name__)
131131

132-
logger.info("Download request received", extra={
133-
"ingest_id": str(ingest_id),
134-
"s3_enabled": is_s3_enabled()
135-
})
132+
logger.info(f"Download request received - ingest_id: {ingest_id}, s3_enabled: {is_s3_enabled()}")
136133

137134
# Check if S3 is enabled and file exists in S3
138135
if is_s3_enabled():
139-
logger.info("S3 is enabled, attempting S3 URL lookup", extra={"ingest_id": str(ingest_id)})
136+
logger.info(f"S3 is enabled, attempting S3 URL lookup - ingest_id: {ingest_id}")
140137

141138
try:
142139
s3_url = get_s3_url_for_ingest_id(ingest_id)
143140
if s3_url:
144-
logger.info("File found in S3, redirecting", extra={
145-
"ingest_id": str(ingest_id),
146-
"s3_url": s3_url,
147-
"redirect_status": 302
148-
})
141+
logger.info(f"File found in S3, redirecting - ingest_id: {ingest_id}, s3_url: {s3_url}, redirect_status: 302")
149142
return RedirectResponse(url=s3_url, status_code=302)
150143
else:
151-
logger.info("File not found in S3, falling back to local file", extra={
152-
"ingest_id": str(ingest_id)
153-
})
144+
logger.info(f"File not found in S3, falling back to local file - ingest_id: {ingest_id}")
154145
except Exception as s3_err:
155-
logger.error("Error during S3 URL lookup, falling back to local file", extra={
156-
"ingest_id": str(ingest_id),
157-
"error_type": type(s3_err).__name__,
158-
"error_message": str(s3_err)
159-
})
146+
logger.error(f"Error during S3 URL lookup, falling back to local file - ingest_id: {ingest_id}, error_type: {type(s3_err).__name__}, error_message: {str(s3_err)}")
160147
else:
161-
logger.info("S3 is disabled, serving local file", extra={"ingest_id": str(ingest_id)})
148+
logger.info(f"S3 is disabled, serving local file - ingest_id: {ingest_id}")
162149

163150
# Fall back to local file serving
164-
logger.info("Attempting local file serving", extra={"ingest_id": str(ingest_id)})
151+
logger.info(f"Attempting local file serving - ingest_id: {ingest_id}")
165152

166153
# Normalize and validate the directory path
167154
directory = (TMP_BASE_PATH / str(ingest_id)).resolve()
168155

169-
logger.debug("Local directory path resolved", extra={
170-
"ingest_id": str(ingest_id),
171-
"directory_path": str(directory),
172-
"tmp_base_path": str(TMP_BASE_PATH.resolve())
173-
})
156+
logger.info(f"Local directory path resolved - ingest_id: {ingest_id}, directory_path: {str(directory)}, tmp_base_path: {str(TMP_BASE_PATH.resolve())}")
174157

175158
if not str(directory).startswith(str(TMP_BASE_PATH.resolve())):
176-
logger.error("Invalid ingest ID - path traversal attempt", extra={
177-
"ingest_id": str(ingest_id),
178-
"directory_path": str(directory),
179-
"tmp_base_path": str(TMP_BASE_PATH.resolve())
180-
})
159+
logger.error(f"Invalid ingest ID - path traversal attempt - ingest_id: {ingest_id}, directory_path: {str(directory)}, tmp_base_path: {str(TMP_BASE_PATH.resolve())}")
181160
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail=f"Invalid ingest ID: {ingest_id!r}")
182161

183162
if not directory.is_dir():
184-
logger.error("Digest directory not found", extra={
185-
"ingest_id": str(ingest_id),
186-
"directory_path": str(directory),
187-
"directory_exists": directory.exists(),
188-
"is_directory": directory.is_dir() if directory.exists() else False
189-
})
163+
logger.error(f"Digest directory not found - ingest_id: {ingest_id}, directory_path: {str(directory)}, directory_exists: {directory.exists()}, is_directory: {directory.is_dir() if directory.exists() else False}")
190164
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=f"Digest {ingest_id!r} not found")
191165

192166
try:
193167
# List all txt files for debugging
194168
txt_files = list(directory.glob("*.txt"))
195-
logger.debug("Found txt files in directory", extra={
196-
"ingest_id": str(ingest_id),
197-
"directory_path": str(directory),
198-
"txt_files_count": len(txt_files),
199-
"txt_files": [f.name for f in txt_files]
200-
})
169+
logger.info(f"Found txt files in directory - ingest_id: {ingest_id}, directory_path: {str(directory)}, txt_files_count: {len(txt_files)}, txt_files: {[f.name for f in txt_files]}")
201170

202171
first_txt_file = next(directory.glob("*.txt"))
203172

204-
logger.info("Selected txt file for download", extra={
205-
"ingest_id": str(ingest_id),
206-
"selected_file": first_txt_file.name,
207-
"file_path": str(first_txt_file),
208-
"file_size": first_txt_file.stat().st_size if first_txt_file.exists() else "unknown"
209-
})
173+
logger.info(f"Selected txt file for download - ingest_id: {ingest_id}, selected_file: {first_txt_file.name}, file_path: {str(first_txt_file)}, file_size: {first_txt_file.stat().st_size if first_txt_file.exists() else 'unknown'}")
210174

211175
except StopIteration as exc:
212176
# List all files in directory for debugging
213177
all_files = list(directory.glob("*"))
214-
logger.error("No txt file found in digest directory", extra={
215-
"ingest_id": str(ingest_id),
216-
"directory_path": str(directory),
217-
"all_files_count": len(all_files),
218-
"all_files": [f.name for f in all_files],
219-
"s3_enabled": is_s3_enabled()
220-
})
178+
logger.error(f"No txt file found in digest directory - ingest_id: {ingest_id}, directory_path: {str(directory)}, all_files_count: {len(all_files)}, all_files: {[f.name for f in all_files]}, s3_enabled: {is_s3_enabled()}")
221179
raise HTTPException(
222180
status_code=status.HTTP_404_NOT_FOUND,
223181
detail=f"No .txt file found for digest {ingest_id!r}, s3_enabled: {is_s3_enabled()}"
224182
) from exc
225183

226184
try:
227-
logger.info("Serving local file", extra={
228-
"ingest_id": str(ingest_id),
229-
"file_name": first_txt_file.name,
230-
"file_path": str(first_txt_file),
231-
"media_type": "text/plain"
232-
})
185+
logger.info(f"Serving local file - ingest_id: {ingest_id}, file_name: {first_txt_file.name}, file_path: {str(first_txt_file)}, media_type: text/plain")
233186
return FileResponse(path=first_txt_file, media_type="text/plain", filename=first_txt_file.name)
234187
except PermissionError as exc:
235-
logger.error("Permission denied accessing file", extra={
236-
"ingest_id": str(ingest_id),
237-
"file_path": str(first_txt_file),
238-
"error_message": str(exc)
239-
})
188+
logger.error(f"Permission denied accessing file - ingest_id: {ingest_id}, file_path: {str(first_txt_file)}, error_message: {str(exc)}")
240189
raise HTTPException(
241190
status_code=status.HTTP_403_FORBIDDEN,
242191
detail=f"Permission denied for {first_txt_file}",
243192
) from exc
244193
except Exception as exc:
245-
logger.error("Unexpected error serving local file", extra={
246-
"ingest_id": str(ingest_id),
247-
"file_path": str(first_txt_file),
248-
"error_type": type(exc).__name__,
249-
"error_message": str(exc)
250-
})
194+
logger.error(f"Unexpected error serving local file - ingest_id: {ingest_id}, file_path: {str(first_txt_file)}, error_type: {type(exc).__name__}, error_message: {str(exc)}")
251195
raise HTTPException(
252196
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
253197
detail=f"Error serving file for digest {ingest_id!r}",

0 commit comments

Comments
 (0)