Skip to content

Commit ce0df02

Browse files
committed
fix: move endpoint back to its own controller
1 parent 0888431 commit ce0df02

File tree

3 files changed

+80
-39
lines changed

3 files changed

+80
-39
lines changed

appinfo/routes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113
['name' => 'termsagreement_api#agree', 'url' => '/api/1.0/termsagreement/agree/{version}', 'verb' => 'POST'],
114114
['name' => 'termsagreement_api#isAgreed', 'url' => '/api/1.0/termsagreement/isagreed/{version}', 'verb' => 'GET'],
115115

116-
['name' => 'status_api#releases', 'url' => '/api/1.0/releases', 'verb' => 'GET'],
116+
['name' => 'releases_api#index', 'url' => '/api/1.0/releases', 'verb' => 'GET'],
117117

118118
[
119119
'name' => 'setting_groups_management#preflighted_cors',
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
3+
/**
4+
* @copyright Copyright (c) 2026 Sendent B.V.
5+
*
6+
* @author Sendent B.V. <info@sendent.com>
7+
*
8+
* @license GNU AGPL version 3 or any later version
9+
*
10+
* This program is free software: you can redistribute it and/or modify
11+
* it under the terms of the GNU Affero General Public License as
12+
* published by the Free Software Foundation, either version 3 of the
13+
* License, or (at your option) any later version.
14+
*
15+
* This program is distributed in the hope that it will be useful,
16+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
* GNU Affero General Public License for more details.
19+
*
20+
* You should have received a copy of the GNU Affero General Public License
21+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
22+
*/
23+
24+
namespace OCA\Sendent\Controller;
25+
26+
use OCP\AppFramework\ApiController;
27+
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
28+
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
29+
use OCP\AppFramework\Http\DataResponse;
30+
use OCP\Http\Client\IClientService;
31+
use OCP\IRequest;
32+
use Psr\Log\LoggerInterface;
33+
34+
class ReleasesApiController extends ApiController {
35+
private const BASE_URL = 'https://releasesapp.com/api/entries/latest/';
36+
37+
private const WORKSPACES = [
38+
'outlook-cross-platform' => 'dc9b6f11-139c-46ad-83a7-efca461ef0d0',
39+
'ms-teams' => '6880e895-ba93-4433-9729-371ea9dc0ac1',
40+
'outlook-windows' => '13f7862f-8df4-4106-a818-4d5a82f6fe50',
41+
];
42+
43+
private $httpClient;
44+
private $logger;
45+
46+
public function __construct(
47+
$appName,
48+
IRequest $request,
49+
IClientService $clientService,
50+
LoggerInterface $logger,
51+
) {
52+
parent::__construct($appName, $request);
53+
$this->httpClient = $clientService->newClient();
54+
$this->logger = $logger;
55+
}
56+
57+
/**
58+
* Fetches the latest release entry for all products.
59+
*
60+
* @return DataResponse
61+
*/
62+
#[NoAdminRequired]
63+
#[NoCSRFRequired]
64+
public function index(): DataResponse {
65+
$results = [];
66+
foreach (self::WORKSPACES as $slug => $uuid) {
67+
try {
68+
$response = $this->httpClient->get(self::BASE_URL . $uuid);
69+
$data = json_decode($response->getBody(), true);
70+
if ($data) {
71+
$results[$slug] = $data;
72+
}
73+
} catch (\Exception $e) {
74+
$this->logger->warning('Failed to fetch release for ' . $slug . ': ' . $e->getMessage());
75+
}
76+
}
77+
return new DataResponse($results);
78+
}
79+
}

lib/Controller/StatusApiController.php

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@
3232
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
3333
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
3434
use OCP\AppFramework\Http\DataResponse;
35-
use OCP\Http\Client\IClientService;
3635
use OCP\IRequest;
37-
use Psr\Log\LoggerInterface;
3836

3937
class StatusApiController extends ApiController {
4038
/** @var IAppManager */
@@ -44,15 +42,6 @@ class StatusApiController extends ApiController {
4442
private $licensemanager;
4543
private $appVersionClient;
4644
private $licenseservice;
47-
private $httpClient;
48-
private $logger;
49-
50-
private const RELEASES_BASE_URL = 'https://releasesapp.com/api/entries/latest/';
51-
private const RELEASE_WORKSPACES = [
52-
'outlook-cross-platform' => 'dc9b6f11-139c-46ad-83a7-efca461ef0d0',
53-
'ms-teams' => '6880e895-ba93-4433-9729-371ea9dc0ac1',
54-
'outlook-windows' => '13f7862f-8df4-4106-a818-4d5a82f6fe50',
55-
];
5645

5746
public function __construct(
5847
$appName,
@@ -62,17 +51,13 @@ public function __construct(
6251
LicenseManager $licensemanager,
6352
AppVersionHttpClient $appVersionClient,
6453
LicenseService $licenseservice,
65-
IClientService $clientService,
66-
LoggerInterface $logger,
6754
) {
6855
parent::__construct($appName, $request);
6956
$this->appManager = $appManager;
7057
$this->userId = $userId;
7158
$this->appVersionClient = $appVersionClient;
7259
$this->licensemanager = $licensemanager;
7360
$this->licenseservice = $licenseservice;
74-
$this->httpClient = $clientService->newClient();
75-
$this->logger = $logger;
7661
}
7762
/**
7863
* Get the status of the user's license
@@ -147,27 +132,4 @@ public function index(): DataResponse {
147132
// Returns license status
148133
return new DataResponse($statusobj);
149134
}
150-
151-
/**
152-
* Fetches the latest release entry for all products from releasesapp.com
153-
*
154-
* @return DataResponse
155-
*/
156-
#[NoAdminRequired]
157-
#[NoCSRFRequired]
158-
public function releases(): DataResponse {
159-
$results = [];
160-
foreach (self::RELEASE_WORKSPACES as $slug => $uuid) {
161-
try {
162-
$response = $this->httpClient->get(self::RELEASES_BASE_URL . $uuid);
163-
$data = json_decode($response->getBody(), true);
164-
if ($data) {
165-
$results[$slug] = $data;
166-
}
167-
} catch (\Exception $e) {
168-
$this->logger->warning('Failed to fetch release for ' . $slug . ': ' . $e->getMessage());
169-
}
170-
}
171-
return new DataResponse($results);
172-
}
173135
}

0 commit comments

Comments
 (0)