Skip to content

Commit 7b3f39b

Browse files
committed
feat: allow for downloading logs
Signed-off-by: Lukas Schaefer <lukas@lschaefer.xyz>
1 parent 3d82650 commit 7b3f39b

File tree

5 files changed

+65
-4
lines changed

5 files changed

+65
-4
lines changed

appinfo/routes.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@
1313
['name' => 'provider#getProviders', 'url' => '/providers', 'verb' => 'GET'],
1414
['name' => 'provider#getDefaultProviderKey', 'url' => '/default-provider-key', 'verb' => 'GET'],
1515
['name' => 'provider#getMetadataFor', 'url' => '/sources-metadata', 'verb' => 'POST'],
16+
['name' => 'log#getNextcloudLogs', 'url' => '/download-logs-nextcloud', 'verb' => 'GET'],
1617
],
1718
];

lib/Controller/LogController.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
/**
4+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
5+
* SPDX-License-Identifier: AGPL-3.0-or-later
6+
*/
7+
8+
namespace OCA\ContextChat\Controller;
9+
10+
use OCA\ContextChat\Logger;
11+
use OCP\AppFramework\Controller;
12+
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
13+
14+
use OCP\AppFramework\Http\ZipResponse;
15+
use OCP\IRequest;
16+
17+
class LogController extends Controller {
18+
public function __construct(
19+
string $appName,
20+
IRequest $request,
21+
private Logger $logger,
22+
) {
23+
parent::__construct($appName, $request);
24+
}
25+
/**
26+
* Downloads log file
27+
*
28+
* @return ZipResponse
29+
*/
30+
#[NoCSRFRequired]
31+
public function getNextcloudLogs(): ZipResponse {
32+
$logFilepath = $this->logger->getLogFilepath();
33+
$response = new ZipResponse($this->request, 'nextcloud-logs');
34+
$filePath = $logFilepath;
35+
$counter = 1;
36+
while ($remoteFile = fopen($filePath, 'r')) {
37+
$size = filesize($filePath);
38+
$time = filemtime($filePath); // Needed otherwise tar complains that time is in the future
39+
$response->addResource($remoteFile, basename($filePath), $size, $time);
40+
$filePath = $logFilepath . '.' . $counter++;
41+
}
42+
return $response;
43+
}
44+
}

package-lock.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
},
3838
"dependencies": {
3939
"@nextcloud/initial-state": "^2.2.0",
40+
"@nextcloud/router": "^3.0.1",
4041
"@nextcloud/vue": "8.x",
4142
"humanize-duration": "^3.32.1",
4243
"vue": "^2.7.12"

src/components/ViewAdmin.vue

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,28 +43,42 @@ SPDX-License-Identifier: AGPL-3.0-or-later
4343
</td>
4444
</tr>
4545
</table>
46+
<h2>{{ t('context_chat', 'Context Chat Logs') }}</h2>
47+
<NcButton :href="downloadURLNextcloudLogs">
48+
{{ t('context_chat', 'Download Nextcloud logs') }}
49+
</NcButton>
50+
<NcButton :href="downloadURLDockerLogs">
51+
{{ t('context_chat', 'Download Backend logs') }}
52+
</NcButton>
4653
<p>&nbsp;</p>
4754
<p>{{ t('context_chat', 'Eligible files for indexing: {count}', {count: stats.eligible_files_count}) }}</p>
4855
<p>{{ t('context_chat', 'Queued content update actions: {count}', {count: stats.queued_actions_count}) }}</p>
49-
<p><a href="https://docs.nextcloud.com/server/latest/admin_manual/ai/app_context_chat.html">{{ t('context_chat', 'Official documentation') }}</a></p>
56+
<p>
57+
<a href="https://docs.nextcloud.com/server/latest/admin_manual/ai/app_context_chat.html">{{
58+
t('context_chat', 'Official documentation')
59+
}}</a>
60+
</p>
5061
</NcSettingsSection>
5162
</div>
5263
</template>
5364

5465
<script>
55-
import { NcNoteCard, NcSettingsSection } from '@nextcloud/vue'
66+
import { NcNoteCard, NcSettingsSection, NcButton } from '@nextcloud/vue'
5667
import { loadState } from '@nextcloud/initial-state'
5768
import humanizeDuration from 'humanize-duration'
69+
import { generateUrl } from '@nextcloud/router'
5870
5971
const MAX_RELATIVE_DATE = 1000 * 60 * 60 * 24 * 7 // one week
6072
6173
export default {
6274
name: 'ViewAdmin',
63-
components: { NcSettingsSection, NcNoteCard },
75+
components: { NcSettingsSection, NcNoteCard, NcButton },
6476
6577
data() {
6678
return {
67-
stats: {},
79+
stats: {},
80+
downloadURLNextcloudLogs: generateUrl('/apps/context_chat/download-logs-nextcloud'),
81+
downloadURLDockerLogs: generateUrl('/apps/app_api/proxy/context_chat_backend/download-logs'),
6882
}
6983
},
7084

0 commit comments

Comments
 (0)