Skip to content

Commit

Permalink
removed deprecated OCS endpoints for frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
bigcat88 committed Dec 5, 2023
1 parent 0d260cb commit 3707c8c
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 130 deletions.
2 changes: 0 additions & 2 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@
['name' => 'OCSUi#registerFileActionMenu', 'url' => '/api/v1/ui/files-actions-menu', 'verb' => 'POST'],
['name' => 'OCSUi#unregisterFileActionMenu', 'url' => '/api/v1/ui/files-actions-menu', 'verb' => 'DELETE'],
['name' => 'OCSUi#getFileActionMenu', 'url' => '/api/v1/ui/files-actions-menu', 'verb' => 'GET'],
['name' => 'OCSUi#handleFileAction', 'url' => '/api/v1/files/action', 'verb' => 'POST'],
['name' => 'OCSUi#loadFileActionIcon', 'url' => '/api/v1/files/action/icon', 'verb' => 'GET'],

// Top Menu
['name' => 'OCSUi#registerExAppMenuEntry', 'url' => '/api/v1/ui/top-menu', 'verb' => 'POST'],
Expand Down
92 changes: 0 additions & 92 deletions lib/Controller/OCSUiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,30 @@

use OCA\AppAPI\AppInfo\Application;
use OCA\AppAPI\Attribute\AppAPIAuth;
use OCA\AppAPI\Service\AppAPIService;
use OCA\AppAPI\Service\UI\FilesActionsMenuService;
use OCA\AppAPI\Service\UI\InitialStateService;
use OCA\AppAPI\Service\UI\ScriptsService;
use OCA\AppAPI\Service\UI\StylesService;
use OCA\AppAPI\Service\UI\TopMenuService;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
use OCP\AppFramework\Http\Attribute\PublicPage;
use OCP\AppFramework\Http\DataDisplayResponse;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCS\OCSBadRequestException;
use OCP\AppFramework\OCS\OCSNotFoundException;
use OCP\AppFramework\OCSController;
use OCP\Http\Client\IResponse;
use OCP\IConfig;
use OCP\IRequest;
use Psr\Log\LoggerInterface;

class OCSUiController extends OCSController {
protected $request;

public function __construct(
IRequest $request,
private readonly ?string $userId,
private readonly FilesActionsMenuService $filesActionsMenuService,
private readonly TopMenuService $menuEntryService,
private readonly InitialStateService $initialStateService,
private readonly ScriptsService $scriptsService,
private readonly StylesService $stylesService,
private readonly AppAPIService $appAPIService,
private readonly IConfig $config,
private readonly LoggerInterface $logger,
) {
parent::__construct(Application::APP_ID, $request);

Expand Down Expand Up @@ -317,86 +307,4 @@ public function getExAppStyle(string $type, string $name, string $path): DataRes
}
return new DataResponse($result, Http::STATUS_OK);
}

/**
* @NoCSRFRequired
* @NoAdminRequired
*
* @param string $appId
* @param string $actionName
* @param array $actionFile
* @param string $actionHandler
*
* @return DataResponse
*/
#[NoAdminRequired]
#[NoCSRFRequired]
public function handleFileAction(string $appId, string $actionName, array $actionFile, string $actionHandler): DataResponse {
$result = false;
$exFileAction = $this->filesActionsMenuService->getExAppFileAction($appId, $actionName);
if ($exFileAction !== null) {
$handler = $exFileAction->getActionHandler(); // route on ex app
$params = [
'actionName' => $actionName,
'actionHandler' => $actionHandler,
'actionFile' => [
'fileId' => $actionFile['fileId'],
'name' => $actionFile['name'],
'directory' => $actionFile['directory'],
'etag' => $actionFile['etag'],
'mime' => $actionFile['mime'],
'fileType' => $actionFile['fileType'],
'mtime' => $actionFile['mtime'] / 1000, // convert ms to s
'size' => intval($actionFile['size']),
'favorite' => $actionFile['favorite'] ?? "false",
'permissions' => $actionFile['permissions'],
'shareOwner' => $actionFile['shareOwner'] ?? null,
'shareOwnerId' => $actionFile['shareOwnerId'] ?? null,
'shareTypes' => $actionFile['shareTypes'] ?? null,
'shareAttributes' => $actionFile['shareAttributes'] ?? null,
'sharePermissions' => $actionFile['sharePermissions'] ?? null,
'userId' => $this->userId,
'instanceId' => $this->config->getSystemValue('instanceid', null),
],
];
$exApp = $this->appAPIService->getExApp($appId);
if ($exApp !== null) {
$result = $this->appAPIService->aeRequestToExApp($exApp, $handler, $this->userId, 'POST', $params, [], $this->request);
if ($result instanceof IResponse) {
$result = $result->getStatusCode() === 200;
} elseif (isset($result['error'])) {
$this->logger->error(sprintf('Failed to handle ExApp %s FileAction %s. Error: %s', $appId, $actionName, $result['error']));
}
}
}
return new DataResponse([
'success' => $result,
'handleFileActionSent' => $result,
], Http::STATUS_OK);
}

/**
* @NoAdminRequired
* @NoCSRFRequired
*
* @param string $appId
* @param string $exFileActionName
*
* @return DataDisplayResponse
*/
#[NoAdminRequired]
#[NoCSRFRequired]
public function loadFileActionIcon(string $appId, string $exFileActionName): DataDisplayResponse {
$icon = $this->filesActionsMenuService->loadFileActionIcon($appId, $exFileActionName);
if ($icon !== null && isset($icon['body'], $icon['headers'])) {
$response = new DataDisplayResponse(
$icon['body'],
Http::STATUS_OK,
['Content-Type' => $icon['headers']['Content-Type'][0] ?? 'image/svg+xml']
);
$response->cacheFor(FilesActionsMenuService::ICON_CACHE_TTL, false, true);
return $response;
}
return new DataDisplayResponse('', 400);
}
}
36 changes: 0 additions & 36 deletions lib/Service/UI/FilesActionsMenuService.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,21 @@
use OCA\AppAPI\Db\UI\FilesActionsMenuMapper;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
use OCP\AppFramework\Http;
use OCP\DB\Exception;
use OCP\Http\Client\IClient;
use OCP\Http\Client\IClientService;
use OCP\ICache;
use OCP\ICacheFactory;
use Psr\Log\LoggerInterface;

class FilesActionsMenuService {
public const ICON_CACHE_TTL = 60 * 60 * 24; // 1 day
private ICache $cache;
private IClient $client;

public function __construct(
ICacheFactory $cacheFactory,
private readonly FilesActionsMenuMapper $mapper,
private readonly LoggerInterface $logger,
IClientService $clientService,
) {
$this->cache = $cacheFactory->createDistributed(Application::APP_ID . '/ex_files_actions_menu');
$this->client = $clientService->newClient();
}

/**
Expand Down Expand Up @@ -133,36 +127,6 @@ public function getExAppFileAction(string $appId, string $fileActionName): ?File
return $fileAction;
}

/**
* @param string $appId
* @param string $exFileActionName
*
* @return array|null
*/
public function loadFileActionIcon(string $appId, string $exFileActionName): ?array {
$exFileAction = $this->getExAppFileAction($appId, $exFileActionName);
if ($exFileAction === null) {
return null;
}
$iconUrl = $exFileAction->getIcon();
if (!isset($iconUrl) || $iconUrl === '') {
return null;
}
try {
$thumbnailResponse = $this->client->get($iconUrl);
if ($thumbnailResponse->getStatusCode() === Http::STATUS_OK) {
return [
'body' => $thumbnailResponse->getBody(),
'headers' => $thumbnailResponse->getHeaders(),
];
}
} catch (\Exception $e) {
$this->logger->error(sprintf('Failed to load ExApp %s FileAction icon %s. Error: %s', $appId, $exFileActionName, $e->getMessage()), ['exception' => $e]);
return null;
}
return null;
}

public function unregisterExAppFileActions(string $appId): int {
try {
$result = $this->mapper->removeAllByAppId($appId);
Expand Down

0 comments on commit 3707c8c

Please sign in to comment.