Export wiki content as Markdown or JSON. Args: request: The export request containing wiki pages and format Returns: A downloadable file in the requested format
(request: WikiExportRequest)
| 226 | |
| 227 | @app.post("/export/wiki") |
| 228 | async def export_wiki(request: WikiExportRequest): |
| 229 | """ |
| 230 | Export wiki content as Markdown or JSON. |
| 231 | |
| 232 | Args: |
| 233 | request: The export request containing wiki pages and format |
| 234 | |
| 235 | Returns: |
| 236 | A downloadable file in the requested format |
| 237 | """ |
| 238 | try: |
| 239 | logger.info(f"Exporting wiki for {request.repo_url} in {request.format} format") |
| 240 | |
| 241 | # Extract repository name from URL for the filename |
| 242 | repo_parts = request.repo_url.rstrip('/').split('/') |
| 243 | repo_name = repo_parts[-1] if len(repo_parts) > 0 else "wiki" |
| 244 | |
| 245 | # Get current timestamp for the filename |
| 246 | timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") |
| 247 | |
| 248 | if request.format == "markdown": |
| 249 | # Generate Markdown content |
| 250 | content = generate_markdown_export(request.repo_url, request.pages) |
| 251 | filename = f"{repo_name}_wiki_{timestamp}.md" |
| 252 | media_type = "text/markdown" |
| 253 | else: # JSON format |
| 254 | # Generate JSON content |
| 255 | content = generate_json_export(request.repo_url, request.pages) |
| 256 | filename = f"{repo_name}_wiki_{timestamp}.json" |
| 257 | media_type = "application/json" |
| 258 | |
| 259 | # Create response with appropriate headers for file download |
| 260 | response = Response( |
| 261 | content=content, |
| 262 | media_type=media_type, |
| 263 | headers={ |
| 264 | "Content-Disposition": f"attachment; filename={filename}" |
| 265 | } |
| 266 | ) |
| 267 | |
| 268 | return response |
| 269 | |
| 270 | except Exception as e: |
| 271 | error_msg = f"Error exporting wiki: {str(e)}" |
| 272 | logger.error(error_msg) |
| 273 | raise HTTPException(status_code=500, detail=error_msg) |
| 274 | |
| 275 | @app.get("/local_repo/structure") |
| 276 | async def get_local_repo_structure(path: str = Query(None, description="Path to local repository")): |
nothing calls this directly
no test coverage detected