Move storagestats endpoint to proper controller

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
Roeland Jago Douma 2018-03-13 12:09:46 +01:00
parent 58599e0360
commit f52ba44edb
No known key found for this signature in database
GPG Key ID: F941078878347C0C
5 changed files with 82 additions and 60 deletions

View File

@ -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']]);
}

View File

@ -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');

View File

@ -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',

View File

@ -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',

View File

@ -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'
],
]);
}
}
}