1
0
Fork 0
mirror of synced 2024-07-09 00:16:13 +12:00

update and delete backward compatibility

This commit is contained in:
Damodar Lohani 2021-06-25 16:41:39 +05:45
parent ee580add1a
commit d82594cfcd

View file

@ -1180,17 +1180,23 @@ App::put('/v1/storage/files/:fileId')
/** @var Utopia\Database\Database $dbForInternal */ /** @var Utopia\Database\Database $dbForInternal */
/** @var Appwrite\Event\Event $audits */ /** @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); $file = $dbForInternal->getDocument('files', $fileId);
if (empty($file->getId())) { if ($file->isEmpty() || $file->getAttribute('bucketId') != $bucketId) {
throw new Exception('File not found', 404); throw new Exception('File not found', 404);
} }
$file = $dbForInternal->updateDocument('files', $fileId, new Document(\array_merge($file->getArrayCopy(), [ $file = $dbForInternal->updateDocument('files', $fileId, $file
'$read' => $read, ->setAttribute('$read', $read)
'$write' => $write, ->setAttribute('$write', $write)
'bucketId' => '', );
])));
$audits $audits
->setParam('event', 'storage.files.update') ->setParam('event', 'storage.files.update')
@ -1224,9 +1230,16 @@ App::delete('/v1/storage/files/:fileId')
/** @var Appwrite\Event\Event $audits */ /** @var Appwrite\Event\Event $audits */
/** @var Appwrite\Event\Event $usage */ /** @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); $file = $dbForInternal->getDocument('files', $fileId);
if (empty($file->getId())) { if ($file->isEmpty() || $file->getAttribute('bucketId') != $bucketId) {
throw new Exception('File not found', 404); throw new Exception('File not found', 404);
} }