Fix: Improve file serving content-disposition and filename
Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
@@ -1383,7 +1383,12 @@ async def api_files_full(path_b64: str, request: Request):
|
|||||||
if not _is_safe_path(UPLOAD_ROOT, file_path) or not os.path.isfile(file_path):
|
if not _is_safe_path(UPLOAD_ROOT, file_path) or not os.path.isfile(file_path):
|
||||||
return Response(status_code=404)
|
return Response(status_code=404)
|
||||||
|
|
||||||
return FileResponse(file_path)
|
mime_type, _ = mimetypes.guess_type(file_path)
|
||||||
|
disposition = "attachment"
|
||||||
|
if mime_type and (mime_type.startswith(('image/', 'video/', 'audio/', 'text/')) or mime_type == 'application/pdf'):
|
||||||
|
disposition = "inline"
|
||||||
|
|
||||||
|
return FileResponse(file_path, content_disposition_type=disposition, filename=os.path.basename(rel_path))
|
||||||
|
|
||||||
|
|
||||||
@app.get("/api/files/zip/{path_b64}")
|
@app.get("/api/files/zip/{path_b64}")
|
||||||
|
|||||||
Reference in New Issue
Block a user