From d82594cfcd570c014fe0badeb12f0df979d52afd Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Fri, 25 Jun 2021 16:41:39 +0545 Subject: [PATCH] update and delete backward compatibility --- app/controllers/api/storage.php | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/app/controllers/api/storage.php b/app/controllers/api/storage.php index 0abaf65573..b78b96a3e0 100644 --- a/app/controllers/api/storage.php +++ b/app/controllers/api/storage.php @@ -1180,17 +1180,23 @@ App::put('/v1/storage/files/:fileId') /** @var Utopia\Database\Database $dbForInternal */ /** @var Appwrite\Event\Event $audits */ + $bucketId = 'default'; + $bucket = $dbForInternal->getDocument('buckets', $bucketId); + + if($bucket->isEmpty()) { + throw new Exception('Bucket not found', 404); + } + $file = $dbForInternal->getDocument('files', $fileId); - if (empty($file->getId())) { + if ($file->isEmpty() || $file->getAttribute('bucketId') != $bucketId) { throw new Exception('File not found', 404); } - $file = $dbForInternal->updateDocument('files', $fileId, new Document(\array_merge($file->getArrayCopy(), [ - '$read' => $read, - '$write' => $write, - 'bucketId' => '', - ]))); + $file = $dbForInternal->updateDocument('files', $fileId, $file + ->setAttribute('$read', $read) + ->setAttribute('$write', $write) + ); $audits ->setParam('event', 'storage.files.update') @@ -1224,9 +1230,16 @@ App::delete('/v1/storage/files/:fileId') /** @var Appwrite\Event\Event $audits */ /** @var Appwrite\Event\Event $usage */ + $bucketId = 'default'; + $bucket = $dbForInternal->getDocument('buckets', $bucketId); + + if($bucket->isEmpty()) { + throw new Exception('Bucket not found', 404); + } + $file = $dbForInternal->getDocument('files', $fileId); - if (empty($file->getId())) { + if ($file->isEmpty() || $file->getAttribute('bucketId') != $bucketId) { throw new Exception('File not found', 404); }