@@ -39,33 +39,33 @@ |
||
39 | 39 | use OCP\L10N\IFactory; |
40 | 40 | |
41 | 41 | class ServerFactory { |
42 | - /** @var IConfig */ |
|
43 | - private $config; |
|
44 | - /** @var IL10N */ |
|
45 | - private $l10n; |
|
46 | - private $eventDispatcher; |
|
42 | + /** @var IConfig */ |
|
43 | + private $config; |
|
44 | + /** @var IL10N */ |
|
45 | + private $l10n; |
|
46 | + private $eventDispatcher; |
|
47 | 47 | |
48 | - public function __construct(IConfig $config, IFactory $l10nFactory, IEventDispatcher $eventDispatcher) { |
|
49 | - $this->config = $config; |
|
50 | - $this->l10n = $l10nFactory->get('dav'); |
|
51 | - $this->eventDispatcher = $eventDispatcher; |
|
52 | - } |
|
48 | + public function __construct(IConfig $config, IFactory $l10nFactory, IEventDispatcher $eventDispatcher) { |
|
49 | + $this->config = $config; |
|
50 | + $this->l10n = $l10nFactory->get('dav'); |
|
51 | + $this->eventDispatcher = $eventDispatcher; |
|
52 | + } |
|
53 | 53 | |
54 | - public function createServer(string $baseURI, |
|
55 | - string $requestURI, |
|
56 | - IRootFolder $rootFolder, |
|
57 | - DirectMapper $mapper, |
|
58 | - ITimeFactory $timeFactory, |
|
59 | - Throttler $throttler, |
|
60 | - IRequest $request): Server { |
|
61 | - $home = new DirectHome($rootFolder, $mapper, $timeFactory, $throttler, $request, $this->eventDispatcher); |
|
62 | - $server = new Server($home); |
|
54 | + public function createServer(string $baseURI, |
|
55 | + string $requestURI, |
|
56 | + IRootFolder $rootFolder, |
|
57 | + DirectMapper $mapper, |
|
58 | + ITimeFactory $timeFactory, |
|
59 | + Throttler $throttler, |
|
60 | + IRequest $request): Server { |
|
61 | + $home = new DirectHome($rootFolder, $mapper, $timeFactory, $throttler, $request, $this->eventDispatcher); |
|
62 | + $server = new Server($home); |
|
63 | 63 | |
64 | - $server->httpRequest->setUrl($requestURI); |
|
65 | - $server->setBaseUri($baseURI); |
|
64 | + $server->httpRequest->setUrl($requestURI); |
|
65 | + $server->setBaseUri($baseURI); |
|
66 | 66 | |
67 | - $server->addPlugin(new MaintenancePlugin($this->config, $this->l10n)); |
|
67 | + $server->addPlugin(new MaintenancePlugin($this->config, $this->l10n)); |
|
68 | 68 | |
69 | - return $server; |
|
70 | - } |
|
69 | + return $server; |
|
70 | + } |
|
71 | 71 | } |
@@ -40,86 +40,86 @@ |
||
40 | 40 | |
41 | 41 | class DirectHome implements ICollection { |
42 | 42 | |
43 | - /** @var IRootFolder */ |
|
44 | - private $rootFolder; |
|
45 | - |
|
46 | - /** @var DirectMapper */ |
|
47 | - private $mapper; |
|
48 | - |
|
49 | - /** @var ITimeFactory */ |
|
50 | - private $timeFactory; |
|
51 | - |
|
52 | - /** @var Throttler */ |
|
53 | - private $throttler; |
|
54 | - |
|
55 | - /** @var IRequest */ |
|
56 | - private $request; |
|
57 | - private $eventDispatcher; |
|
58 | - |
|
59 | - public function __construct( |
|
60 | - IRootFolder $rootFolder, |
|
61 | - DirectMapper $mapper, |
|
62 | - ITimeFactory $timeFactory, |
|
63 | - Throttler $throttler, |
|
64 | - IRequest $request, |
|
65 | - IEventDispatcher $eventDispatcher |
|
66 | - ) { |
|
67 | - $this->rootFolder = $rootFolder; |
|
68 | - $this->mapper = $mapper; |
|
69 | - $this->timeFactory = $timeFactory; |
|
70 | - $this->throttler = $throttler; |
|
71 | - $this->request = $request; |
|
72 | - $this->eventDispatcher = $eventDispatcher; |
|
73 | - } |
|
74 | - |
|
75 | - public function createFile($name, $data = null) { |
|
76 | - throw new Forbidden(); |
|
77 | - } |
|
78 | - |
|
79 | - public function createDirectory($name) { |
|
80 | - throw new Forbidden(); |
|
81 | - } |
|
82 | - |
|
83 | - public function getChild($name): DirectFile { |
|
84 | - try { |
|
85 | - $direct = $this->mapper->getByToken($name); |
|
86 | - |
|
87 | - // Expired |
|
88 | - if ($direct->getExpiration() < $this->timeFactory->getTime()) { |
|
89 | - throw new NotFound(); |
|
90 | - } |
|
91 | - |
|
92 | - return new DirectFile($direct, $this->rootFolder, $this->eventDispatcher); |
|
93 | - } catch (DoesNotExistException $e) { |
|
94 | - // Since the token space is so huge only throttle on non exsisting token |
|
95 | - $this->throttler->registerAttempt('directlink', $this->request->getRemoteAddress()); |
|
96 | - $this->throttler->sleepDelay($this->request->getRemoteAddress(), 'directlink'); |
|
97 | - |
|
98 | - throw new NotFound(); |
|
99 | - } |
|
100 | - } |
|
101 | - |
|
102 | - public function getChildren() { |
|
103 | - throw new MethodNotAllowed('Listing members of this collection is disabled'); |
|
104 | - } |
|
105 | - |
|
106 | - public function childExists($name): bool { |
|
107 | - return false; |
|
108 | - } |
|
109 | - |
|
110 | - public function delete() { |
|
111 | - throw new Forbidden(); |
|
112 | - } |
|
113 | - |
|
114 | - public function getName(): string { |
|
115 | - return 'direct'; |
|
116 | - } |
|
117 | - |
|
118 | - public function setName($name) { |
|
119 | - throw new Forbidden(); |
|
120 | - } |
|
121 | - |
|
122 | - public function getLastModified(): int { |
|
123 | - return 0; |
|
124 | - } |
|
43 | + /** @var IRootFolder */ |
|
44 | + private $rootFolder; |
|
45 | + |
|
46 | + /** @var DirectMapper */ |
|
47 | + private $mapper; |
|
48 | + |
|
49 | + /** @var ITimeFactory */ |
|
50 | + private $timeFactory; |
|
51 | + |
|
52 | + /** @var Throttler */ |
|
53 | + private $throttler; |
|
54 | + |
|
55 | + /** @var IRequest */ |
|
56 | + private $request; |
|
57 | + private $eventDispatcher; |
|
58 | + |
|
59 | + public function __construct( |
|
60 | + IRootFolder $rootFolder, |
|
61 | + DirectMapper $mapper, |
|
62 | + ITimeFactory $timeFactory, |
|
63 | + Throttler $throttler, |
|
64 | + IRequest $request, |
|
65 | + IEventDispatcher $eventDispatcher |
|
66 | + ) { |
|
67 | + $this->rootFolder = $rootFolder; |
|
68 | + $this->mapper = $mapper; |
|
69 | + $this->timeFactory = $timeFactory; |
|
70 | + $this->throttler = $throttler; |
|
71 | + $this->request = $request; |
|
72 | + $this->eventDispatcher = $eventDispatcher; |
|
73 | + } |
|
74 | + |
|
75 | + public function createFile($name, $data = null) { |
|
76 | + throw new Forbidden(); |
|
77 | + } |
|
78 | + |
|
79 | + public function createDirectory($name) { |
|
80 | + throw new Forbidden(); |
|
81 | + } |
|
82 | + |
|
83 | + public function getChild($name): DirectFile { |
|
84 | + try { |
|
85 | + $direct = $this->mapper->getByToken($name); |
|
86 | + |
|
87 | + // Expired |
|
88 | + if ($direct->getExpiration() < $this->timeFactory->getTime()) { |
|
89 | + throw new NotFound(); |
|
90 | + } |
|
91 | + |
|
92 | + return new DirectFile($direct, $this->rootFolder, $this->eventDispatcher); |
|
93 | + } catch (DoesNotExistException $e) { |
|
94 | + // Since the token space is so huge only throttle on non exsisting token |
|
95 | + $this->throttler->registerAttempt('directlink', $this->request->getRemoteAddress()); |
|
96 | + $this->throttler->sleepDelay($this->request->getRemoteAddress(), 'directlink'); |
|
97 | + |
|
98 | + throw new NotFound(); |
|
99 | + } |
|
100 | + } |
|
101 | + |
|
102 | + public function getChildren() { |
|
103 | + throw new MethodNotAllowed('Listing members of this collection is disabled'); |
|
104 | + } |
|
105 | + |
|
106 | + public function childExists($name): bool { |
|
107 | + return false; |
|
108 | + } |
|
109 | + |
|
110 | + public function delete() { |
|
111 | + throw new Forbidden(); |
|
112 | + } |
|
113 | + |
|
114 | + public function getName(): string { |
|
115 | + return 'direct'; |
|
116 | + } |
|
117 | + |
|
118 | + public function setName($name) { |
|
119 | + throw new Forbidden(); |
|
120 | + } |
|
121 | + |
|
122 | + public function getLastModified(): int { |
|
123 | + return 0; |
|
124 | + } |
|
125 | 125 | } |
@@ -36,83 +36,83 @@ |
||
36 | 36 | use Sabre\DAV\IFile; |
37 | 37 | |
38 | 38 | class DirectFile implements IFile { |
39 | - /** @var Direct */ |
|
40 | - private $direct; |
|
39 | + /** @var Direct */ |
|
40 | + private $direct; |
|
41 | 41 | |
42 | - /** @var IRootFolder */ |
|
43 | - private $rootFolder; |
|
42 | + /** @var IRootFolder */ |
|
43 | + private $rootFolder; |
|
44 | 44 | |
45 | - /** @var File */ |
|
46 | - private $file; |
|
45 | + /** @var File */ |
|
46 | + private $file; |
|
47 | 47 | |
48 | - private $eventDispatcher; |
|
48 | + private $eventDispatcher; |
|
49 | 49 | |
50 | - public function __construct(Direct $direct, IRootFolder $rootFolder, IEventDispatcher $eventDispatcher) { |
|
51 | - $this->direct = $direct; |
|
52 | - $this->rootFolder = $rootFolder; |
|
53 | - $this->eventDispatcher = $eventDispatcher; |
|
54 | - } |
|
50 | + public function __construct(Direct $direct, IRootFolder $rootFolder, IEventDispatcher $eventDispatcher) { |
|
51 | + $this->direct = $direct; |
|
52 | + $this->rootFolder = $rootFolder; |
|
53 | + $this->eventDispatcher = $eventDispatcher; |
|
54 | + } |
|
55 | 55 | |
56 | - public function put($data) { |
|
57 | - throw new Forbidden(); |
|
58 | - } |
|
56 | + public function put($data) { |
|
57 | + throw new Forbidden(); |
|
58 | + } |
|
59 | 59 | |
60 | - public function get() { |
|
61 | - $this->getFile(); |
|
60 | + public function get() { |
|
61 | + $this->getFile(); |
|
62 | 62 | |
63 | - $this->eventDispatcher->dispatchTyped(new BeforeFileDirectDownloadedEvent($this->file)); |
|
63 | + $this->eventDispatcher->dispatchTyped(new BeforeFileDirectDownloadedEvent($this->file)); |
|
64 | 64 | |
65 | - return $this->file->fopen('rb'); |
|
66 | - } |
|
65 | + return $this->file->fopen('rb'); |
|
66 | + } |
|
67 | 67 | |
68 | - public function getContentType() { |
|
69 | - $this->getFile(); |
|
68 | + public function getContentType() { |
|
69 | + $this->getFile(); |
|
70 | 70 | |
71 | - return $this->file->getMimeType(); |
|
72 | - } |
|
71 | + return $this->file->getMimeType(); |
|
72 | + } |
|
73 | 73 | |
74 | - public function getETag() { |
|
75 | - $this->getFile(); |
|
74 | + public function getETag() { |
|
75 | + $this->getFile(); |
|
76 | 76 | |
77 | - return $this->file->getEtag(); |
|
78 | - } |
|
77 | + return $this->file->getEtag(); |
|
78 | + } |
|
79 | 79 | |
80 | - public function getSize() { |
|
81 | - $this->getFile(); |
|
80 | + public function getSize() { |
|
81 | + $this->getFile(); |
|
82 | 82 | |
83 | - return $this->file->getSize(); |
|
84 | - } |
|
83 | + return $this->file->getSize(); |
|
84 | + } |
|
85 | 85 | |
86 | - public function delete() { |
|
87 | - throw new Forbidden(); |
|
88 | - } |
|
86 | + public function delete() { |
|
87 | + throw new Forbidden(); |
|
88 | + } |
|
89 | 89 | |
90 | - public function getName() { |
|
91 | - return $this->direct->getToken(); |
|
92 | - } |
|
90 | + public function getName() { |
|
91 | + return $this->direct->getToken(); |
|
92 | + } |
|
93 | 93 | |
94 | - public function setName($name) { |
|
95 | - throw new Forbidden(); |
|
96 | - } |
|
94 | + public function setName($name) { |
|
95 | + throw new Forbidden(); |
|
96 | + } |
|
97 | 97 | |
98 | - public function getLastModified() { |
|
99 | - $this->getFile(); |
|
98 | + public function getLastModified() { |
|
99 | + $this->getFile(); |
|
100 | 100 | |
101 | - return $this->file->getMTime(); |
|
102 | - } |
|
101 | + return $this->file->getMTime(); |
|
102 | + } |
|
103 | 103 | |
104 | - private function getFile() { |
|
105 | - if ($this->file === null) { |
|
106 | - $userFolder = $this->rootFolder->getUserFolder($this->direct->getUserId()); |
|
107 | - $files = $userFolder->getById($this->direct->getFileId()); |
|
104 | + private function getFile() { |
|
105 | + if ($this->file === null) { |
|
106 | + $userFolder = $this->rootFolder->getUserFolder($this->direct->getUserId()); |
|
107 | + $files = $userFolder->getById($this->direct->getFileId()); |
|
108 | 108 | |
109 | - if ($files === []) { |
|
110 | - throw new NotFound(); |
|
111 | - } |
|
109 | + if ($files === []) { |
|
110 | + throw new NotFound(); |
|
111 | + } |
|
112 | 112 | |
113 | - $this->file = array_shift($files); |
|
114 | - } |
|
113 | + $this->file = array_shift($files); |
|
114 | + } |
|
115 | 115 | |
116 | - return $this->file; |
|
117 | - } |
|
116 | + return $this->file; |
|
117 | + } |
|
118 | 118 | } |
@@ -30,18 +30,18 @@ |
||
30 | 30 | * @since 22.0.0 |
31 | 31 | */ |
32 | 32 | class BeforeFileDirectDownloadedEvent extends Event { |
33 | - private $file; |
|
33 | + private $file; |
|
34 | 34 | |
35 | - public function __construct(File $file) { |
|
36 | - parent::__construct(); |
|
37 | - $this->file = $file; |
|
38 | - } |
|
35 | + public function __construct(File $file) { |
|
36 | + parent::__construct(); |
|
37 | + $this->file = $file; |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * @return File |
|
42 | - * @since 22.0.0 |
|
43 | - */ |
|
44 | - public function getFile(): File { |
|
45 | - return $this->file; |
|
46 | - } |
|
40 | + /** |
|
41 | + * @return File |
|
42 | + * @since 22.0.0 |
|
43 | + */ |
|
44 | + public function getFile(): File { |
|
45 | + return $this->file; |
|
46 | + } |
|
47 | 47 | } |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | |
30 | 30 | // no php execution timeout for webdav |
31 | 31 | if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) { |
32 | - @set_time_limit(0); |
|
32 | + @set_time_limit(0); |
|
33 | 33 | } |
34 | 34 | ignore_user_abort(true); |
35 | 35 | |
@@ -41,13 +41,13 @@ discard block |
||
41 | 41 | /** @var ServerFactory $serverFactory */ |
42 | 42 | $serverFactory = \OC::$server->query(ServerFactory::class); |
43 | 43 | $server = $serverFactory->createServer( |
44 | - $baseuri, |
|
45 | - $requestUri, |
|
46 | - \OC::$server->getRootFolder(), |
|
47 | - \OC::$server->query(\OCA\DAV\Db\DirectMapper::class), |
|
48 | - \OC::$server->query(\OCP\AppFramework\Utility\ITimeFactory::class), |
|
49 | - \OC::$server->getBruteForceThrottler(), |
|
50 | - \OC::$server->getRequest() |
|
44 | + $baseuri, |
|
45 | + $requestUri, |
|
46 | + \OC::$server->getRootFolder(), |
|
47 | + \OC::$server->query(\OCA\DAV\Db\DirectMapper::class), |
|
48 | + \OC::$server->query(\OCP\AppFramework\Utility\ITimeFactory::class), |
|
49 | + \OC::$server->getBruteForceThrottler(), |
|
50 | + \OC::$server->getRequest() |
|
51 | 51 | ); |
52 | 52 | |
53 | 53 | $server->exec(); |