|
12 | 12 | import logging |
13 | 13 | import multiprocessing as mp |
14 | 14 | import os |
| 15 | +import tempfile |
15 | 16 | import threading |
| 17 | +import zipfile |
16 | 18 | from collections.abc import Callable |
17 | 19 | from contextlib import asynccontextmanager |
18 | 20 | from functools import wraps |
|
25 | 27 | from nc_py_api import AsyncNextcloudApp, NextcloudApp |
26 | 28 | from nc_py_api.ex_app import persistent_storage, set_handlers |
27 | 29 | from pydantic import BaseModel, ValidationInfo, field_validator |
| 30 | +from starlette.responses import FileResponse |
28 | 31 |
|
29 | 32 | from .chain.context import do_doc_search |
30 | 33 | from .chain.ingest.injest import embed_sources |
@@ -492,3 +495,15 @@ def _(query: Query) -> list[SearchResult]: |
492 | 495 | query.scopeType, |
493 | 496 | query.scopeList, |
494 | 497 | )) |
| 498 | + |
| 499 | + |
| 500 | +@app.get('/downloadLogs') |
| 501 | +def download_logs() -> FileResponse: |
| 502 | + with tempfile.NamedTemporaryFile('wb', delete=False) as tmp: |
| 503 | + with zipfile.ZipFile(tmp, mode='w', compression=zipfile.ZIP_DEFLATED) as zip_file: |
| 504 | + files = os.listdir(os.path.join(persistent_storage(), 'logs')) |
| 505 | + for file in files: |
| 506 | + file_path = os.path.join(persistent_storage(), 'logs', file) |
| 507 | + if os.path.isfile(file_path): # Might be a folder (just skip it then) |
| 508 | + zip_file.write(file_path) |
| 509 | + return FileResponse(tmp.name, media_type='application/zip', filename='docker_logs.zip') |
0 commit comments