Completed
Push — master ( 7f194b...f212c6 )
by Morris
18:03 queued 13s
created

DirectHome::getName()   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 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
/**
4
 * @copyright 2018, Roeland Jago Douma <[email protected]>
5
 *
6
 * @author Roeland Jago Douma <[email protected]>
7
 *
8
 * @license GNU AGPL version 3 or any later version
9
 *
10
 * This program is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU Affero General Public License as
12
 * published by the Free Software Foundation, either version 3 of the
13
 * License, or (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 * GNU Affero General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU Affero General Public License
21
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
 *
23
 */
24
25
namespace OCA\DAV\Direct;
26
27
use OC\Security\Bruteforce\Throttler;
28
use OCA\DAV\Db\DirectMapper;
29
use OCP\AppFramework\Db\DoesNotExistException;
30
use OCP\AppFramework\Utility\ITimeFactory;
31
use OCP\Files\IRootFolder;
32
use OCP\IRequest;
33
use Sabre\DAV\Exception\Forbidden;
34
use Sabre\DAV\Exception\MethodNotAllowed;
35
use Sabre\DAV\Exception\NotFound;
36
use Sabre\DAV\ICollection;
37
38
class DirectHome implements ICollection {
39
40
	/** @var IRootFolder */
41
	private $rootFolder;
42
43
	/** @var DirectMapper */
44
	private $mapper;
45
46
	/** @var ITimeFactory */
47
	private $timeFactory;
48
49
	/** @var Throttler */
50
	private $throttler;
51
52
	/** @var IRequest */
53
	private $request;
54
55
	public function __construct(IRootFolder $rootFolder,
56
								DirectMapper $mapper,
57
								ITimeFactory $timeFactory,
58
								Throttler $throttler,
59
								IRequest $request) {
60
		$this->rootFolder = $rootFolder;
61
		$this->mapper = $mapper;
62
		$this->timeFactory = $timeFactory;
63
		$this->throttler = $throttler;
64
		$this->request = $request;
65
	}
66
67
	public function createFile($name, $data = null) {
68
		throw new Forbidden();
69
	}
70
71
	public function createDirectory($name) {
72
		throw new Forbidden();
73
	}
74
75
	public function getChild($name): DirectFile {
76
		try {
77
			$direct = $this->mapper->getByToken($name);
78
79
			// Expired
80
			if ($direct->getExpiration() < $this->timeFactory->getTime()) {
81
				throw new NotFound();
82
			}
83
84
			return new DirectFile($direct, $this->rootFolder);
85
		} catch (DoesNotExistException $e) {
86
			// Since the token space is so huge only throttle on non exsisting token
87
			$this->throttler->registerAttempt('directlink', $this->request->getRemoteAddress());
88
			$this->throttler->sleepDelay($this->request->getRemoteAddress(), 'directlink');
89
90
			throw new NotFound();
91
		}
92
	}
93
94
	public function getChildren() {
95
		throw new MethodNotAllowed('Listing members of this collection is disabled');
96
	}
97
98
	public function childExists($name): bool {
99
		return false;
100
	}
101
102
	public function delete() {
103
		throw new Forbidden();
104
	}
105
106
	public function getName(): string {
107
		return 'direct';
108
	}
109
110
	public function setName($name) {
111
		throw new Forbidden();
112
	}
113
114
	public function getLastModified(): int {
115
		return 0;
116
	}
117
118
}
119