diff --git a/apps/files/ajax/getstoragestats.php b/apps/files/ajax/getstoragestats.php deleted file mode 100644 index d1d8d57b46..0000000000 --- a/apps/files/ajax/getstoragestats.php +++ /dev/null @@ -1,40 +0,0 @@ - - * @author Lukas Reschke - * @author Robin Appelman - * @author Thomas Müller - * @author Vincent Petry - * - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see - * - */ -$dir = '/'; - -if (isset($_GET['dir'])) { - $dir = (string)$_GET['dir']; -} - -OCP\JSON::checkLoggedIn(); -\OC::$server->getSession()->close(); - -// send back json -try { - OCP\JSON::success(array('data' => \OCA\Files\Helper::buildFileStorageStatistics($dir))); -} catch (\OCP\Files\NotFoundException $e) { - OCP\JSON::error(['data' => ['message' => 'Folder not found']]); -} diff --git a/apps/files/appinfo/routes.php b/apps/files/appinfo/routes.php index 28bc60a31a..3912d72350 100644 --- a/apps/files/appinfo/routes.php +++ b/apps/files/appinfo/routes.php @@ -1,4 +1,5 @@ registerRoutes( $this, - array( - 'routes' => array( - array( + [ + 'routes' => [ + [ 'name' => 'API#getThumbnail', 'url' => '/api/v1/thumbnail/{x}/{y}/{file}', 'verb' => 'GET', - 'requirements' => array('file' => '.+') - ), - array( + 'requirements' => ['file' => '.+'] + ], + [ 'name' => 'API#updateFileTags', 'url' => '/api/v1/files/{path}', 'verb' => 'POST', - 'requirements' => array('path' => '.+'), - ), - array( + 'requirements' => ['path' => '.+'], + ], + [ 'name' => 'API#getRecentFiles', 'url' => '/api/v1/recent/', 'verb' => 'GET' - ), - array( + ], + [ 'name' => 'API#updateFileSorting', 'url' => '/api/v1/sorting', 'verb' => 'POST' - ), - array( + ], + [ 'name' => 'API#showHiddenFiles', 'url' => '/api/v1/showhidden', 'verb' => 'POST' - ), + ], [ 'name' => 'view#index', 'url' => '/', @@ -69,21 +70,24 @@ $application->registerRoutes( 'name' => 'settings#setMaxUploadSize', 'url' => '/settings/maxUpload', 'verb' => 'POST', - ] - ) - ) + ], + [ + 'name' => 'ajax#getStorageStats', + 'url' => '/ajax/getstoragestats.php', + 'verb' => 'GET', + ], + ] + ] ); /** @var $this \OC\Route\Router */ $this->create('files_ajax_download', 'ajax/download.php') ->actionInclude('files/ajax/download.php'); -$this->create('files_ajax_getstoragestats', 'ajax/getstoragestats.php') - ->actionInclude('files/ajax/getstoragestats.php'); $this->create('files_ajax_list', 'ajax/list.php') ->actionInclude('files/ajax/list.php'); $this->create('download', 'download{file}') - ->requirements(array('file' => '.*')) + ->requirements(['file' => '.*']) ->actionInclude('files/download.php'); diff --git a/apps/files/composer/composer/autoload_classmap.php b/apps/files/composer/composer/autoload_classmap.php index d184702cfa..3fe29a5dd5 100644 --- a/apps/files/composer/composer/autoload_classmap.php +++ b/apps/files/composer/composer/autoload_classmap.php @@ -27,6 +27,7 @@ return array( 'OCA\\Files\\Command\\Scan' => $baseDir . '/../lib/Command/Scan.php', 'OCA\\Files\\Command\\ScanAppData' => $baseDir . '/../lib/Command/ScanAppData.php', 'OCA\\Files\\Command\\TransferOwnership' => $baseDir . '/../lib/Command/TransferOwnership.php', + 'OCA\\Files\\Controller\\AjaxController' => $baseDir . '/../lib/Controller/AjaxController.php', 'OCA\\Files\\Controller\\ApiController' => $baseDir . '/../lib/Controller/ApiController.php', 'OCA\\Files\\Controller\\SettingsController' => $baseDir . '/../lib/Controller/SettingsController.php', 'OCA\\Files\\Controller\\ViewController' => $baseDir . '/../lib/Controller/ViewController.php', diff --git a/apps/files/composer/composer/autoload_static.php b/apps/files/composer/composer/autoload_static.php index 44094c6a34..7dd1508383 100644 --- a/apps/files/composer/composer/autoload_static.php +++ b/apps/files/composer/composer/autoload_static.php @@ -42,6 +42,7 @@ class ComposerStaticInitFiles 'OCA\\Files\\Command\\Scan' => __DIR__ . '/..' . '/../lib/Command/Scan.php', 'OCA\\Files\\Command\\ScanAppData' => __DIR__ . '/..' . '/../lib/Command/ScanAppData.php', 'OCA\\Files\\Command\\TransferOwnership' => __DIR__ . '/..' . '/../lib/Command/TransferOwnership.php', + 'OCA\\Files\\Controller\\AjaxController' => __DIR__ . '/..' . '/../lib/Controller/AjaxController.php', 'OCA\\Files\\Controller\\ApiController' => __DIR__ . '/..' . '/../lib/Controller/ApiController.php', 'OCA\\Files\\Controller\\SettingsController' => __DIR__ . '/..' . '/../lib/Controller/SettingsController.php', 'OCA\\Files\\Controller\\ViewController' => __DIR__ . '/..' . '/../lib/Controller/ViewController.php', diff --git a/apps/files/lib/Controller/AjaxController.php b/apps/files/lib/Controller/AjaxController.php new file mode 100644 index 0000000000..a7422d7c4c --- /dev/null +++ b/apps/files/lib/Controller/AjaxController.php @@ -0,0 +1,56 @@ + + * + * @author Roeland Jago Douma + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ + +namespace OCA\Files\Controller; + +use OCA\Files\Helper; +use OCP\AppFramework\Controller; +use OCP\AppFramework\Http\JSONResponse; +use OCP\Files\NotFoundException; +use OCP\IRequest; + +class AjaxController extends Controller { + + public function __construct(string $appName, IRequest $request) { + parent::__construct($appName, $request); + } + + /** + * @NoAdminRequired + */ + public function getStorageStats(string $dir = '/'): JSONResponse { + try { + return new JSONResponse([ + 'status' => 'success', + 'data' => Helper::buildFileStorageStatistics($dir), + ]); + } catch (NotFoundException $e) { + return new JSONResponse([ + 'status' => 'error', + 'data' => [ + 'message' => 'Folder not found' + ], + ]); + } + } +}