-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathOCSApiController.php
More file actions
120 lines (107 loc) · 3.38 KB
/
Copy pathOCSApiController.php
File metadata and controls
120 lines (107 loc) · 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\AppAPI\Controller;
use OCA\AppAPI\AppInfo\Application;
use OCA\AppAPI\Attribute\AppAPIAuth;
use OCA\AppAPI\Service\AppAPIService;
use OCA\AppAPI\Service\ExAppService;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
use OCP\AppFramework\Http\Attribute\PublicPage;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCS\OCSBadRequestException;
use OCP\AppFramework\OCSController;
use OCP\IConfig;
use OCP\IRequest;
use OCP\IURLGenerator;
use Psr\Log\InvalidArgumentException;
use Psr\Log\LoggerInterface;
class OCSApiController extends OCSController {
protected $request;
public function __construct(
IRequest $request,
private readonly LoggerInterface $logger,
private readonly AppAPIService $service,
private IConfig $config,
private readonly ExAppService $exAppService,
private readonly IURLGenerator $urlGenerator,
) {
parent::__construct(Application::APP_ID, $request);
$this->request = $request;
}
/**
* @throws OCSBadRequestException
*/
#[AppAPIAuth]
#[PublicPage]
#[NoAdminRequired]
#[NoCSRFRequired]
public function log(int $level, string $message): DataResponse {
try {
$this->logger->log($level, $message, [
'app' => $this->request->getHeader('EX-APP-ID'),
]);
return new DataResponse();
} catch (InvalidArgumentException) {
$this->logger->error('Invalid log level');
throw new OCSBadRequestException('Invalid log level');
}
}
#[AppAPIAuth]
#[PublicPage]
#[NoCSRFRequired]
public function getNCUsersList(): DataResponse {
return new DataResponse($this->exAppService->getNCUsersList(), Http::STATUS_OK);
}
#[AppAPIAuth]
#[PublicPage]
#[NoCSRFRequired]
public function setAppInitProgressDeprecated(string $appId, int $progress, string $error = ''): DataResponse {
$exApp = $this->exAppService->getExApp($appId);
if (!$exApp) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
$this->service->setAppInitProgress($exApp, $progress, $error);
return new DataResponse();
}
#[AppAPIAuth]
#[PublicPage]
#[NoCSRFRequired]
public function setAppInitProgress(int $progress, string $error = ''): DataResponse {
$exApp = $this->exAppService->getExApp($this->request->getHeader('EX-APP-ID'));
if (!$exApp) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
$this->service->setAppInitProgress($exApp, $progress, $error);
return new DataResponse();
}
/**
* Retrieves the enabled status of an ExApp (0 for disabled, 1 for enabled).
* Note: This endpoint is accessible even if the ExApp itself is disabled.
*
* @return DataResponse The enabled status of the ExApp.
*/
#[AppAPIAuth]
#[PublicPage]
#[NoCSRFRequired]
public function getEnabledState(): DataResponse {
$exApp = $this->exAppService->getExApp($this->request->getHeader('EX-APP-ID'));
if (!$exApp) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
return new DataResponse($exApp->getEnabled());
}
#[AppAPIAuth]
#[PublicPage]
#[NoCSRFRequired]
public function getNextcloudAbsoluteUrl(string $url): DataResponse {
return new DataResponse([
'absolute_url' => rtrim($this->config->getSystemValueString('overwrite.cli.url'), '/') . '/' . ltrim($url, '/'),
], Http::STATUS_OK);
}
}