diff --git a/appinfo/routes.php b/appinfo/routes.php index 9ec63df4..8c221373 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -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'], diff --git a/lib/Controller/OCSUiController.php b/lib/Controller/OCSUiController.php index b6374fe9..a2711c17 100644 --- a/lib/Controller/OCSUiController.php +++ b/lib/Controller/OCSUiController.php @@ -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); @@ -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); - } } diff --git a/lib/Service/UI/FilesActionsMenuService.php b/lib/Service/UI/FilesActionsMenuService.php index 9b23a0e3..e5965d36 100644 --- a/lib/Service/UI/FilesActionsMenuService.php +++ b/lib/Service/UI/FilesActionsMenuService.php @@ -9,10 +9,7 @@ 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; @@ -20,16 +17,13 @@ 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(); } /** @@ -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);