aboutsummaryrefslogtreecommitdiffstats
path: root/apps/dav/lib/BulkUpload/BulkUploadPlugin.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/dav/lib/BulkUpload/BulkUploadPlugin.php')
-rw-r--r--apps/dav/lib/BulkUpload/BulkUploadPlugin.php61
1 files changed, 22 insertions, 39 deletions
diff --git a/apps/dav/lib/BulkUpload/BulkUploadPlugin.php b/apps/dav/lib/BulkUpload/BulkUploadPlugin.php
index bb6baf48b56..d4faf3764e1 100644
--- a/apps/dav/lib/BulkUpload/BulkUploadPlugin.php
+++ b/apps/dav/lib/BulkUpload/BulkUploadPlugin.php
@@ -1,47 +1,27 @@
<?php
+
/**
- * @copyright Copyright (c) 2021, Louis Chemineau <louis@chmn.me>
- *
- * @author Louis Chemineau <louis@chmn.me>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCA\DAV\BulkUpload;
+use OCA\DAV\Connector\Sabre\MtimeSanitizer;
+use OCP\AppFramework\Http;
+use OCP\Files\DavUtil;
+use OCP\Files\Folder;
use Psr\Log\LoggerInterface;
use Sabre\DAV\Server;
use Sabre\DAV\ServerPlugin;
use Sabre\HTTP\RequestInterface;
use Sabre\HTTP\ResponseInterface;
-use OCP\Files\Folder;
-use OCP\AppFramework\Http;
-use OCA\DAV\Connector\Sabre\MtimeSanitizer;
class BulkUploadPlugin extends ServerPlugin {
-
- /** @var Folder */
- private $userFolder;
-
- /** @var LoggerInterface */
- private $logger;
-
- public function __construct(Folder $userFolder, LoggerInterface $logger) {
- $this->userFolder = $userFolder;
- $this->logger = $logger;
+ public function __construct(
+ private Folder $userFolder,
+ private LoggerInterface $logger,
+ ) {
}
/**
@@ -60,11 +40,11 @@ class BulkUploadPlugin extends ServerPlugin {
*/
public function httpPost(RequestInterface $request, ResponseInterface $response): bool {
// Limit bulk upload to the /dav/bulk endpoint
- if ($request->getPath() !== "bulk") {
+ if ($request->getPath() !== 'bulk') {
return true;
}
- $multiPartParser = new MultipartRequestParser($request);
+ $multiPartParser = new MultipartRequestParser($request, $this->logger);
$writtenFiles = [];
while (!$multiPartParser->isAtLastBoundary()) {
@@ -74,7 +54,7 @@ class BulkUploadPlugin extends ServerPlugin {
// Return early if an error occurs during parsing.
$this->logger->error($e->getMessage());
$response->setStatus(Http::STATUS_BAD_REQUEST);
- $response->setBody(json_encode($writtenFiles));
+ $response->setBody(json_encode($writtenFiles, JSON_THROW_ON_ERROR));
return false;
}
@@ -90,22 +70,25 @@ class BulkUploadPlugin extends ServerPlugin {
$node = $this->userFolder->newFile($headers['x-file-path'], $content);
$node->touch($mtime);
+ $node = $this->userFolder->getFirstNodeById($node->getId());
$writtenFiles[$headers['x-file-path']] = [
- "error" => false,
- "etag" => $node->getETag(),
+ 'error' => false,
+ 'etag' => $node->getETag(),
+ 'fileid' => DavUtil::getDavFileId($node->getId()),
+ 'permissions' => DavUtil::getDavPermissions($node),
];
} catch (\Exception $e) {
$this->logger->error($e->getMessage(), ['path' => $headers['x-file-path']]);
$writtenFiles[$headers['x-file-path']] = [
- "error" => true,
- "message" => $e->getMessage(),
+ 'error' => true,
+ 'message' => $e->getMessage(),
];
}
}
$response->setStatus(Http::STATUS_OK);
- $response->setBody(json_encode($writtenFiles));
+ $response->setBody(json_encode($writtenFiles, JSON_THROW_ON_ERROR));
return false;
}