Skip to content

Commit 1cae92f

Browse files
authored
refactor: webdav plugin (#138)
* refactor: webdav plugin * chore: fix code style --------- Co-authored-by: mahiarirani <[email protected]>
1 parent 8064e9f commit 1cae92f

File tree

1 file changed

+20
-46
lines changed

1 file changed

+20
-46
lines changed

lib/Sabre/WebDavPlugin.php

Lines changed: 20 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
namespace OCA\Files_External_Ethswarm\Sabre;
2727

28+
use Exception;
2829
use OCA\DAV\Connector\Sabre\Directory;
2930
use OCA\DAV\Connector\Sabre\File;
3031
use OCA\Files_External_Ethswarm\Service\EthswarmService;
@@ -101,61 +102,35 @@ public function httpPost(RequestInterface $request, ResponseInterface $response)
101102
}
102103

103104
try {
104-
switch ($action) {
105-
case 'hide':
106-
$path = $request->getPath();
107-
$node = $this->server->tree->getNodeForPath($path);
108-
if ($node instanceof File) {
109-
$storageid = $node->getFileInfo()->getStorage()->getCache()->getNumericStorageId();
110-
$filename = $node->getFileInfo()->getinternalPath();
111-
}
112-
if ($node instanceof Directory) {
113-
$storageid = $node->getFileInfo()->getStorage()->getCache()->getNumericStorageId();
114-
$filename = $node->getFileInfo()->getinternalPath();
115-
}
116-
117-
$this->EthswarmService->setVisibility($filename, $storageid, 0);
105+
$path = $request->getPath();
106+
$node = $this->server->tree->getNodeForPath($path);
118107

119-
break;
108+
if (!$node instanceof File && !$node instanceof Directory) {
109+
return true;
110+
}
120111

112+
$fileInfo = $node->getFileInfo();
113+
$filename = $fileInfo->getinternalPath();
114+
$storage = $fileInfo->getMountPoint()->getStorage();
115+
$storageid = $fileInfo->getStorage()->getCache()->getNumericStorageId();
116+
117+
switch ($action) {
118+
case 'hide':
121119
case 'unhide':
122-
$path = $request->getPath();
123-
$node = $this->server->tree->getNodeForPath($path);
124-
if ($node instanceof File) {
125-
$storageid = $node->getFileInfo()->getStorage()->getCache()->getNumericStorageId();
126-
$filename = $node->getFileInfo()->getinternalPath();
127-
}
128-
if ($node instanceof Directory) {
129-
$storageid = $node->getFileInfo()->getStorage()->getCache()->getNumericStorageId();
130-
$filename = $node->getFileInfo()->getinternalPath();
131-
}
132-
133-
$this->EthswarmService->setVisibility($filename, $storageid, 1);
120+
$hide = 'hide' === $action ? 0 : 1;
121+
$this->EthswarmService->setVisibility($filename, $storageid, $hide);
134122

135123
break;
136124

137125
case 'archive':
138-
$path = $request->getPath();
139-
$node = $this->server->tree->getNodeForPath($path);
140-
if ($node instanceof File || $node instanceof Directory) {
141-
$fileInfo = $node->getFileInfo();
142-
$filename = $fileInfo->getInternalPath();
143-
$storage = $fileInfo->getMountPoint()->getStorage();
144-
$this->EthswarmService->archiveNode($filename, $storage);
145-
}
126+
$this->EthswarmService->archiveNode($filename, $storage);
146127

147128
break;
148129

149-
case 'unarchive' || 'move':
150-
$path = $request->getPath();
130+
case 'unarchive':
131+
case 'move':
151132
$destination = $request->getHeader('Destination');
152-
$node = $this->server->tree->getNodeForPath($path);
153-
if ($node instanceof File || $node instanceof Directory) {
154-
$fileInfo = $node->getFileInfo();
155-
$filename = $fileInfo->getInternalPath();
156-
$storage = $fileInfo->getMountPoint()->getStorage();
157-
$this->EthswarmService->moveNode($filename, $storage, $destination);
158-
}
133+
$this->EthswarmService->moveNode($filename, $storage, $destination);
159134

160135
break;
161136

@@ -167,7 +142,7 @@ public function httpPost(RequestInterface $request, ResponseInterface $response)
167142
'status' => true,
168143
'message' => 'success',
169144
]));
170-
} catch (\Exception $ex) {
145+
} catch (Exception $ex) {
171146
$response->setBody(json_encode([
172147
'status' => false,
173148
'message' => $ex->getMessage(),
@@ -203,7 +178,6 @@ public function httpMove(RequestInterface $request, ResponseInterface $response)
203178
} catch (Exception $ex) {
204179
$response->setStatus(500);
205180
}
206-
$response->setHeader('Content-Length', '0');
207181

208182
return false;
209183
}

0 commit comments

Comments
 (0)