diff options
author | Ferdinand Thiessen <opensource@fthiessen.de> | 2025-05-14 17:02:44 +0200 |
---|---|---|
committer | Ferdinand Thiessen <opensource@fthiessen.de> | 2025-05-16 14:37:30 +0200 |
commit | 3d113ab6cccf994a44064492082117d81b203758 (patch) | |
tree | 80add56a3b4e687b72f1e1a302033a4ca785c3c4 | |
parent | 3ab905dbfa944273d7ec631150d867b7990afd46 (diff) | |
download | nextcloud-server-3d113ab6cccf994a44064492082117d81b203758.tar.gz nextcloud-server-3d113ab6cccf994a44064492082117d81b203758.zip |
refactor(dav): use Node API instead of private files view for filedrop plugin
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
-rw-r--r-- | apps/dav/appinfo/v1/publicwebdav.php | 4 | ||||
-rw-r--r-- | apps/dav/appinfo/v2/publicremote.php | 4 | ||||
-rw-r--r-- | apps/dav/lib/Files/Sharing/FilesDropPlugin.php | 32 |
3 files changed, 21 insertions, 19 deletions
diff --git a/apps/dav/appinfo/v1/publicwebdav.php b/apps/dav/appinfo/v1/publicwebdav.php index aa16d6c584a..af49ca5462c 100644 --- a/apps/dav/appinfo/v1/publicwebdav.php +++ b/apps/dav/appinfo/v1/publicwebdav.php @@ -104,11 +104,9 @@ $server = $serverFactory->createServer(false, $baseuri, $requestUri, $authPlugin if (!$isReadable) { $filesDropPlugin->enable(); } - - $view = new View($node->getPath()); - $filesDropPlugin->setView($view); $filesDropPlugin->setShare($share); + $view = new View($node->getPath()); return $view; }); diff --git a/apps/dav/appinfo/v2/publicremote.php b/apps/dav/appinfo/v2/publicremote.php index 62336a9b80f..fbb3ddd2cb3 100644 --- a/apps/dav/appinfo/v2/publicremote.php +++ b/apps/dav/appinfo/v2/publicremote.php @@ -131,11 +131,9 @@ $server = $serverFactory->createServer(true, $baseuri, $requestUri, $authPlugin, if (!$isReadable) { $filesDropPlugin->enable(); } - - $view = new View($node->getPath()); - $filesDropPlugin->setView($view); $filesDropPlugin->setShare($share); + $view = new View($node->getPath()); return $view; }); diff --git a/apps/dav/lib/Files/Sharing/FilesDropPlugin.php b/apps/dav/lib/Files/Sharing/FilesDropPlugin.php index ad7648795da..0bb3e3274b1 100644 --- a/apps/dav/lib/Files/Sharing/FilesDropPlugin.php +++ b/apps/dav/lib/Files/Sharing/FilesDropPlugin.php @@ -5,7 +5,7 @@ */ namespace OCA\DAV\Files\Sharing; -use OC\Files\View; +use OCP\Files\Folder; use OCP\Share\IShare; use Sabre\DAV\Exception\MethodNotAllowed; use Sabre\DAV\ServerPlugin; @@ -17,14 +17,9 @@ use Sabre\HTTP\ResponseInterface; */ class FilesDropPlugin extends ServerPlugin { - private ?View $view = null; private ?IShare $share = null; private bool $enabled = false; - public function setView(View $view): void { - $this->view = $view; - } - public function setShare(IShare $share): void { $this->share = $share; } @@ -33,7 +28,6 @@ class FilesDropPlugin extends ServerPlugin { $this->enabled = true; } - /** * This initializes the plugin. * It is ONLY initialized by the server on a file drop request. @@ -45,7 +39,12 @@ class FilesDropPlugin extends ServerPlugin { } public function onMkcol(RequestInterface $request, ResponseInterface $response) { - if (!$this->enabled || $this->share === null || $this->view === null) { + if (!$this->enabled || $this->share === null) { + return; + } + + $node = $this->share->getNode(); + if (!($node instanceof Folder)) { return; } @@ -57,7 +56,12 @@ class FilesDropPlugin extends ServerPlugin { } public function beforeMethod(RequestInterface $request, ResponseInterface $response) { - if (!$this->enabled || $this->share === null || $this->view === null) { + if (!$this->enabled || $this->share === null) { + return; + } + + $node = $this->share->getNode(); + if (!($node instanceof Folder)) { return; } @@ -132,14 +136,16 @@ class FilesDropPlugin extends ServerPlugin { if ($folder === '') { continue; } // skip empty parts - if (!$this->view->file_exists($folder)) { - $this->view->mkdir($folder); + if (!$node->nodeExists($folder)) { + $node->newFolder($folder); } } // Finally handle conflicts on the end files - $noConflictPath = \OC_Helper::buildNotExistingFileNameForView(dirname($relativePath), basename($relativePath), $this->view); - $path = '/files/' . $token . '/' . $noConflictPath; + /** @var Folder */ + $folder = $node->get(dirname($relativePath)); + $uniqueName = $folder->getNonExistingName(basename(($relativePath))); + $path = '/files/' . $token . '/' . dirname($relativePath) . '/' . $uniqueName; $url = $request->getBaseUrl() . str_replace('//', '/', $path); $request->setUrl($url); } |