Skip to content

Commit a90dc77

Browse files
authored
added report_result method to TextProcessing providers API (#201)
Ref: nextcloud/app_api#208 Signed-off-by: Alexander Piskun <bigcat88@icloud.com>
1 parent 6552a63 commit a90dc77

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

nc_py_api/ex_app/providers/text_processing.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
"""Nextcloud API for declaring TextProcessing provider."""
22

3+
import contextlib
34
import dataclasses
45

5-
from ..._exceptions import NextcloudExceptionNotFound
6+
from ..._exceptions import NextcloudException, NextcloudExceptionNotFound
67
from ..._misc import require_capabilities
78
from ..._session import AsyncNcSessionApp, NcSessionApp
89

@@ -76,6 +77,16 @@ def get_entry(self, name: str) -> TextProcessingProvider | None:
7677
except NextcloudExceptionNotFound:
7778
return None
7879

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+
7990

8091
class _AsyncTextProcessingProviderAPI:
8192
"""API for registering TextProcessing providers."""
@@ -114,3 +125,13 @@ async def get_entry(self, name: str) -> TextProcessingProvider | None:
114125
)
115126
except NextcloudExceptionNotFound:
116127
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+
)

tests/actual_tests/text_processing_provider_test.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,14 @@ async def test_text_processing_provider_async(anc_app):
5656
await anc_app.providers.text_processing.unregister(result2.name, not_fail=False)
5757
assert await anc_app.providers.text_processing.get_entry(result2.name) is None
5858
assert str(result).find("type=free_prompt") != -1
59+
60+
61+
@pytest.mark.require_nc(major=29)
62+
def test_text_processing_provider_fail_report(nc_app):
63+
nc_app.providers.text_processing.report_result(999999)
64+
65+
66+
@pytest.mark.asyncio(scope="session")
67+
@pytest.mark.require_nc(major=29)
68+
async def test_text_processing_provider_fail_report_async(anc_app):
69+
await anc_app.providers.text_processing.report_result(999999)

0 commit comments

Comments
 (0)