Skip to content

Commit

Permalink
feat: add nextcloud url helper info endpoint to get instance base_url (
Browse files Browse the repository at this point in the history
…#383)

Added miscellaneous OCS method to get current Nextcloud instance
base_url.

<img width="883" alt="image"
src="https://github.com/user-attachments/assets/42b98354-eabd-4fd4-b75b-fed6e49dd627">

---------

Signed-off-by: Andrey Borysenko <[email protected]>
  • Loading branch information
andrey18106 authored Sep 10, 2024
1 parent f0a44bf commit aae372b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [3.2.0 - 2024-09-09]
## [3.2.0 - 2024-09-10]

### Added

- ExAppProxy: added bruteforce protection option for ExApp routes. #368
- ExAppOCS: added miscellaneous method to get Nextcloud instance base URL. #383

### Changed

Expand Down
1 change: 1 addition & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
['name' => 'OCSApi#getEnabledState', 'url' => '/ex-app/state', 'verb' => 'GET'],

// ExApps
['name' => 'OCSExApp#getNextcloudUrl', 'url' => '/api/v1/info/nextcloud_url', 'verb' => 'GET'],
['name' => 'OCSExApp#getExAppsList', 'url' => '/api/v1/ex-app/{list}', 'verb' => 'GET'],
['name' => 'OCSExApp#getExApp', 'url' => '/api/v1/ex-app/info/{appId}', 'verb' => 'GET'],

Expand Down
18 changes: 18 additions & 0 deletions docs/tech_details/api/exapp.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,24 @@ Response data

Returns HTTP 200 on success, HTTP 404 - on error.

Get Nextcloud URL
^^^^^^^^^^^^^^^^^

It might be necessary for ExApp to know (or update) the Nextcloud URL.

OCS endpoint: ``GET /apps/app_api/api/v1/info/nextcloud_url``

Response data
*************

Returns the base URL of the Nextcloud instance:

.. code-block:: json
{
"base_url": "http(s)://nextcloud.example.com"
}
Make Requests to ExApps
^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
9 changes: 9 additions & 0 deletions lib/Controller/OCSExAppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use OCP\AppFramework\OCS\OCSBadRequestException;
use OCP\AppFramework\OCSController;
use OCP\IRequest;
use OCP\IURLGenerator;

class OCSExAppController extends OCSController {
protected $request;
Expand All @@ -22,6 +23,7 @@ public function __construct(
IRequest $request,
private readonly AppAPIService $service,
private readonly ExAppService $exAppService,
private readonly IURLGenerator $urlGenerator,
) {
parent::__construct(Application::APP_ID, $request);

Expand All @@ -45,6 +47,13 @@ public function getExApp(string $appId): DataResponse {
return new DataResponse($this->exAppService->formatExAppInfo($exApp), Http::STATUS_OK);
}

#[NoCSRFRequired]
public function getNextcloudUrl(): DataResponse {
return new DataResponse([
'base_url' => $this->urlGenerator->getBaseUrl(),
], Http::STATUS_OK);
}

/**
* @throws OCSBadRequestException
*/
Expand Down

0 comments on commit aae372b

Please sign in to comment.