summaryrefslogtreecommitdiffstats
path: root/apps/files
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2018-03-13 12:09:46 +0100
committerRoeland Jago Douma <roeland@famdouma.nl>2018-03-13 12:44:48 +0100
commitf52ba44edb1c84be67e854125c3b9409e13a314a (patch)
tree6edd3bc274a490c9dfd657e872c4aa650e37e22f /apps/files
parent58599e0360c4a90b71f569214ac591092916622c (diff)
downloadnextcloud-server-f52ba44edb1c84be67e854125c3b9409e13a314a.tar.gz
nextcloud-server-f52ba44edb1c84be67e854125c3b9409e13a314a.zip
Move storagestats endpoint to proper controller
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'apps/files')
-rw-r--r--apps/files/ajax/getstoragestats.php40
-rw-r--r--apps/files/appinfo/routes.php44
-rw-r--r--apps/files/composer/composer/autoload_classmap.php1
-rw-r--r--apps/files/composer/composer/autoload_static.php1
-rw-r--r--apps/files/lib/Controller/AjaxController.php56
5 files changed, 82 insertions, 60 deletions
diff --git a/apps/files/ajax/getstoragestats.php b/apps/files/ajax/getstoragestats.php
deleted file mode 100644
index d1d8d57b468..00000000000
--- a/apps/files/ajax/getstoragestats.php
+++ /dev/null
@@ -1,40 +0,0 @@
-<?php
-/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Jörn Friedrich Dreyer <jfd@butonic.de>
- * @author Lukas Reschke <lukas@statuscode.ch>
- * @author Robin Appelman <robin@icewind.nl>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- * @author Vincent Petry <pvince81@owncloud.com>
- *
- * @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 <http://www.gnu.org/licenses/>
- *
- */
-$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 28bc60a31a3..3912d723508 100644
--- a/apps/files/appinfo/routes.php
+++ b/apps/files/appinfo/routes.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
@@ -31,35 +32,35 @@ namespace OCA\Files\AppInfo;
$application = new Application();
$application->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 d184702cfa2..3fe29a5dd59 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 44094c6a34c..7dd15083831 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 00000000000..a7422d7c4ca
--- /dev/null
+++ b/apps/files/lib/Controller/AjaxController.php
@@ -0,0 +1,56 @@
+<?php
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2018, Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @author Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @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 <http://www.gnu.org/licenses/>
+ *
+ */
+
+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'
+ ],
+ ]);
+ }
+ }
+}