From e6d46056886419dd163df53b9e9c317d89dee4bd Mon Sep 17 00:00:00 2001 From: Alexander Piskun <13381981+bigcat88@users.noreply.github.com> Date: Tue, 30 Jul 2024 20:14:43 +0300 Subject: [PATCH] fixed `ocs` function for `Group Folders` app routes (#279) Fixes #277 . Changes proposed in this pull request: * we use `request.headers["Accept"] = "application/json"` in addition of appending `format=json` to the query url(look below why). * changed ocs_regexp to `r"/ocs/v[12]\.php/|/apps/groupfolders/"` until groupfolder app will fix it. Signed-off-by: Alexander Piskun --- CHANGELOG.md | 3 ++- nc_py_api/_session.py | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c113bef0..3ed61988 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,8 @@ All notable changes to this project will be documented in this file. ### Fixed -- NextcloudApp: `get_computation_device` function now correctly returns result in upper_case. +- Corrected behaviour of `ocs` function for `Group Folders` app routes(they are not fully OCS API). #279 +- NextcloudApp: `get_computation_device` function now correctly returns result in upper_case. #278 ## [0.15.0 - 2024-07-19] diff --git a/nc_py_api/_session.py b/nc_py_api/_session.py index bf3353c7..27bd93e6 100644 --- a/nc_py_api/_session.py +++ b/nc_py_api/_session.py @@ -150,7 +150,7 @@ def __init__(self, **kwargs): self.init_adapter() self.init_adapter_dav() self.response_headers = Headers() - self._ocs_regexp = re.compile(r"/ocs/v[12]\.php/") + self._ocs_regexp = re.compile(r"/ocs/v[12]\.php/|/apps/groupfolders/") def init_adapter(self, restart=False) -> None: if getattr(self, "adapter", None) is None or restart: @@ -289,6 +289,7 @@ def _request_event_ocs(self, request: Request) -> None: str_url = str(request.url) if re.search(self._ocs_regexp, str_url) is not None: # this is OCS call request.url = request.url.copy_merge_params({"format": "json"}) + request.headers["Accept"] = "application/json" def _response_event(self, response: Response) -> None: str_url = str(response.request.url) @@ -412,6 +413,7 @@ async def _request_event_ocs(self, request: Request) -> None: str_url = str(request.url) if re.search(self._ocs_regexp, str_url) is not None: # this is OCS call request.url = request.url.copy_merge_params({"format": "json"}) + request.headers["Accept"] = "application/json" async def _response_event(self, response: Response) -> None: str_url = str(response.request.url)