Completed
Push — master ( 58599e...274106 )
by Morris
46s
created

AjaxController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
/**
4
 * @copyright Copyright (c) 2018, Roeland Jago Douma <[email protected]>
5
 *
6
 * @author Roeland Jago Douma <[email protected]>
7
 *
8
 * @license AGPL-3.0
9
 *
10
 * This code is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU Affero General Public License, version 3,
12
 * as published by the Free Software Foundation.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
 * GNU Affero General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU Affero General Public License, version 3,
20
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
21
 *
22
 */
23
24
namespace OCA\Files\Controller;
25
26
use OCA\Files\Helper;
27
use OCP\AppFramework\Controller;
28
use OCP\AppFramework\Http\JSONResponse;
29
use OCP\Files\NotFoundException;
30
use OCP\IRequest;
31
32
class AjaxController extends Controller {
33
34
	public function __construct(string $appName, IRequest $request) {
35
		parent::__construct($appName, $request);
36
	}
37
38
	/**
39
	 * @NoAdminRequired
40
	 */
41
	public function getStorageStats(string $dir = '/'): JSONResponse {
42
		try {
43
			return new JSONResponse([
44
				'status' => 'success',
45
				'data' => Helper::buildFileStorageStatistics($dir),
46
			]);
47
		} catch (NotFoundException $e) {
48
			return new JSONResponse([
49
				'status' => 'error',
50
				'data' => [
51
					'message' => 'Folder not found'
52
				],
53
			]);
54
		}
55
	}
56
}
57