|
1 | 1 | """Nextcloud API for declaring TextProcessing provider.""" |
2 | 2 |
|
| 3 | +import contextlib |
3 | 4 | import dataclasses |
4 | 5 |
|
5 | | -from ..._exceptions import NextcloudExceptionNotFound |
| 6 | +from ..._exceptions import NextcloudException, NextcloudExceptionNotFound |
6 | 7 | from ..._misc import require_capabilities |
7 | 8 | from ..._session import AsyncNcSessionApp, NcSessionApp |
8 | 9 |
|
@@ -76,6 +77,16 @@ def get_entry(self, name: str) -> TextProcessingProvider | None: |
76 | 77 | except NextcloudExceptionNotFound: |
77 | 78 | return None |
78 | 79 |
|
| 80 | + def report_result(self, task_id: int, result: str = "", error: str = "") -> None: |
| 81 | + """Report results of the text processing to Nextcloud.""" |
| 82 | + require_capabilities("app_api", self._session.capabilities) |
| 83 | + with contextlib.suppress(NextcloudException): |
| 84 | + self._session.ocs( |
| 85 | + "PUT", |
| 86 | + f"{self._session.ae_url}/{self._ep_suffix}", |
| 87 | + params={"taskId": task_id, "result": result, "error": error}, |
| 88 | + ) |
| 89 | + |
79 | 90 |
|
80 | 91 | class _AsyncTextProcessingProviderAPI: |
81 | 92 | """API for registering TextProcessing providers.""" |
@@ -114,3 +125,13 @@ async def get_entry(self, name: str) -> TextProcessingProvider | None: |
114 | 125 | ) |
115 | 126 | except NextcloudExceptionNotFound: |
116 | 127 | return None |
| 128 | + |
| 129 | + async def report_result(self, task_id: int, result: str = "", error: str = "") -> None: |
| 130 | + """Report results of the text processing to Nextcloud.""" |
| 131 | + require_capabilities("app_api", await self._session.capabilities) |
| 132 | + with contextlib.suppress(NextcloudException): |
| 133 | + await self._session.ocs( |
| 134 | + "PUT", |
| 135 | + f"{self._session.ae_url}/{self._ep_suffix}", |
| 136 | + params={"taskId": task_id, "result": result, "error": error}, |
| 137 | + ) |
0 commit comments