1
0
Fork 0
mirror of synced 2024-07-05 22:51:24 +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 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);
}