File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -37,6 +37,14 @@ Setup background job workers as described here: https://docs.nextcloud.com/serve
3737 <image >nextcloud/context_chat_backend</image >
3838 <image-tag >4.3.0</image-tag >
3939 </docker-install >
40+ <routes >
41+ <route >
42+ <url >download-logs</url >
43+ <verb >GET</verb >
44+ <access_level >ADMIN</access_level >
45+ <headers_to_exclude >[]</headers_to_exclude >
46+ </route >
47+ </routes >
4048 <environment-variables >
4149 <variable >
4250 <name >EXTERNAL_DB</name >
Original file line number Diff line number Diff line change 22# SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
33# SPDX-License-Identifier: AGPL-3.0-or-later
44#
5+ import zipfile
6+
7+ from starlette .responses import FileResponse
58
69# isort: off
710from .chain .types import ContextException , LLMOutput , ScopeType , SearchResult
1215import logging
1316import multiprocessing as mp
1417import os
18+ import tempfile
1519import threading
1620from collections .abc import Callable
1721from contextlib import asynccontextmanager
@@ -492,3 +496,16 @@ def _(query: Query) -> list[SearchResult]:
492496 query .scopeType ,
493497 query .scopeList ,
494498 ))
499+
500+
501+ @app .get ('/download-logs' )
502+ @enabled_guard (app )
503+ def download_logs () -> FileResponse :
504+ with tempfile .NamedTemporaryFile ('wb' , delete = False ) as tmp :
505+ with zipfile .ZipFile (tmp , mode = 'w' , compression = zipfile .ZIP_DEFLATED ) as zip_file :
506+ files = os .listdir (os .path .join (persistent_storage (), 'logs' ))
507+ for file in files :
508+ file_path = os .path .join (persistent_storage (), 'logs' , file )
509+ if os .path .isfile (file_path ): # Might be a folder (just skip it then)
510+ zip_file .write (file_path )
511+ return FileResponse (tmp .name , media_type = 'application/zip' , filename = 'docker_logs.zip' )
You can’t perform that action at this time.
0 commit comments