-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathTaskProcessingController.php
More file actions
88 lines (74 loc) · 2.4 KB
/
Copy pathTaskProcessingController.php
File metadata and controls
88 lines (74 loc) · 2.4 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
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2024 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 OCA\AppAPI\Service\ProvidersAI\TaskProcessingService;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
use OCP\AppFramework\Http\Attribute\PublicPage;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Http\Response;
use OCP\AppFramework\OCSController;
use OCP\IRequest;
class TaskProcessingController extends OCSController {
protected $request;
public function __construct(
IRequest $request,
private readonly TaskProcessingService $taskProcessingService,
private readonly AppAPIService $appAPIService,
private readonly ExAppService $exAppService,
) {
parent::__construct(Application::APP_ID, $request);
$this->request = $request;
$this->taskProcessingService->setAppAPIService($this->appAPIService);
$this->taskProcessingService->setExAppService($this->exAppService);
}
#[NoCSRFRequired]
#[PublicPage]
#[AppAPIAuth]
public function registerProvider(
array $provider,
?array $customTaskType,
): DataResponse {
$providerObj = $this->taskProcessingService->registerTaskProcessingProvider(
$this->request->getHeader('EX-APP-ID'),
$provider,
$customTaskType,
);
if ($providerObj === null) {
return new DataResponse([], Http::STATUS_BAD_REQUEST);
}
return new DataResponse();
}
#[NoCSRFRequired]
#[PublicPage]
#[AppAPIAuth]
public function unregisterProvider(string $name): Response {
$unregistered = $this->taskProcessingService->unregisterTaskProcessingProvider(
$this->request->getHeader('EX-APP-ID'), $name
);
if ($unregistered === null) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
return new DataResponse();
}
#[NoCSRFRequired]
#[PublicPage]
#[AppAPIAuth]
public function getProvider(string $name): DataResponse {
$result = $this->taskProcessingService->getExAppTaskProcessingProvider(
$this->request->getHeader('EX-APP-ID'), $name
);
if (!$result) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
return new DataResponse($result, Http::STATUS_OK);
}
}