Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ Setup background job workers as described here: https://docs.nextcloud.com/serve
<image>nextcloud/context_chat_backend</image>
<image-tag>4.3.0</image-tag>
</docker-install>
<routes>
<route>
<url>download-logs</url>
<verb>GET</verb>
<access_level>ADMIN</access_level>
<headers_to_exclude>[]</headers_to_exclude>
</route>
</routes>
<environment-variables>
<variable>
<name>EXTERNAL_DB</name>
Expand Down
17 changes: 17 additions & 0 deletions context_chat_backend/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
# SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
# SPDX-License-Identifier: AGPL-3.0-or-later
#
import zipfile

from starlette.responses import FileResponse
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah and this should be moved below too with the rest of the imports.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved and kept alphabetical order


# isort: off
from .chain.types import ContextException, LLMOutput, ScopeType, SearchResult
Expand All @@ -12,6 +15,7 @@
import logging
import multiprocessing as mp
import os
import tempfile
import threading
from collections.abc import Callable
from contextlib import asynccontextmanager
Expand Down Expand Up @@ -492,3 +496,16 @@ def _(query: Query) -> list[SearchResult]:
query.scopeType,
query.scopeList,
))


@app.get('/download-logs')
@enabled_guard(app)
def download_logs() -> FileResponse:
with tempfile.NamedTemporaryFile('wb', delete=False) as tmp:
with zipfile.ZipFile(tmp, mode='w', compression=zipfile.ZIP_DEFLATED) as zip_file:
files = os.listdir(os.path.join(persistent_storage(), 'logs'))
for file in files:
file_path = os.path.join(persistent_storage(), 'logs', file)
if os.path.isfile(file_path): # Might be a folder (just skip it then)
zip_file.write(file_path)
return FileResponse(tmp.name, media_type='application/zip', filename='docker_logs.zip')
Loading