mirror of
https://github.com/appwrite/appwrite.git
synced 2026-11-18 20:36:03 +00:00
Remove folder param from listFiles in favor of queries
This commit is contained in:
1 parent
ad7c6b9919
commit
796af6f7b5
2 files changed
+13
-26
No files matched your search
@@ -7,7 +7,6 @@ use Appwrite\SDK\AuthType;
|
||||
use Appwrite\SDK\Method;
|
||||
use Appwrite\SDK\Response as SDKResponse;
|
||||
use Appwrite\Utopia\Database\Documents\User;
|
||||
use Appwrite\Utopia\Database\Validator\Folder;
|
||||
use Appwrite\Utopia\Database\Validator\Queries\Files;
|
||||
use Appwrite\Utopia\Response;
|
||||
use Utopia\Database\Database;
|
||||
@@ -23,7 +22,6 @@ use Utopia\Database\Validator\UID;
|
||||
use Utopia\Platform\Action;
|
||||
use Utopia\Platform\Scope\HTTP;
|
||||
use Utopia\Validator\Boolean;
|
||||
use Utopia\Validator\Nullable;
|
||||
use Utopia\Validator\Text;
|
||||
|
||||
class XList extends Action
|
||||
@@ -62,7 +60,6 @@ class XList extends Action
|
||||
->param('queries', [], new Files(), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' queries are allowed, each ' . APP_LIMIT_ARRAY_ELEMENT_SIZE . ' characters long. You may filter on the following attributes: ' . implode(', ', Files::ALLOWED_ATTRIBUTES), true)
|
||||
->param('search', '', new Text(256), 'Search term to filter your list results. Max length: 256 chars.', true)
|
||||
->param('total', true, new Boolean(true), 'When set to false, the total count returned will be 0 and will not be calculated.', true)
|
||||
->param('folder', null, new Nullable(new Folder()), 'Filter results to files directly inside this virtual folder. Pass an empty string for the bucket root. Returns files from all folders when omitted.', true)
|
||||
->inject('response')
|
||||
->inject('dbForProject')
|
||||
->inject('mode')
|
||||
@@ -76,7 +73,6 @@ class XList extends Action
|
||||
array $queries,
|
||||
string $search,
|
||||
bool $includeTotal,
|
||||
?string $folder,
|
||||
Response $response,
|
||||
Database $dbForProject,
|
||||
string $mode,
|
||||
@@ -108,13 +104,6 @@ class XList extends Action
|
||||
$queries[] = Query::search('search', $search);
|
||||
}
|
||||
|
||||
if (!\is_null($folder)) {
|
||||
$folder = Folder::normalize($folder);
|
||||
$queries[] = $folder === ''
|
||||
? Query::or([Query::equal('folder', ['']), Query::isNull('folder')])
|
||||
: Query::equal('folder', [$folder]);
|
||||
}
|
||||
|
||||
$cursor = Query::getCursorQueries($queries, false);
|
||||
$cursor = \reset($cursor);
|
||||
|
||||
|
||||
@@ -491,7 +491,7 @@ trait StorageBase
|
||||
$this->assertNotEmpty($webpView['body']);
|
||||
}
|
||||
|
||||
public function testCreateBucketFileWithParent(): void
|
||||
public function testCreateBucketFileWithFolder(): void
|
||||
{
|
||||
$bucket = $this->client->call(Client::METHOD_POST, '/storage/buckets', [
|
||||
'content-type' => 'application/json',
|
||||
@@ -2036,7 +2036,7 @@ trait StorageBase
|
||||
$this->assertGreaterThanOrEqual(0, $bucket['body']['totalSize']);
|
||||
}
|
||||
|
||||
public function testListFilesByParent(): void
|
||||
public function testListFilesByFolder(): void
|
||||
{
|
||||
$bucket = $this->client->call(Client::METHOD_POST, '/storage/buckets', [
|
||||
'content-type' => 'application/json',
|
||||
@@ -2083,25 +2083,23 @@ trait StorageBase
|
||||
// no filter -- all files
|
||||
$this->assertEquals(3, $list([])['total']);
|
||||
|
||||
// exact match -- immediate children only
|
||||
$this->assertEquals(1, $list(['folder' => 'photos'])['total']);
|
||||
$this->assertEquals('photos/', $list(['folder' => 'photos'])['files'][0]['folder']);
|
||||
// exact match -- immediate children only, canonical form with trailing slash
|
||||
$exact = $list(['queries' => [Query::equal('folder', ['photos/'])->toString()]]);
|
||||
$this->assertEquals(1, $exact['total']);
|
||||
$this->assertEquals('photos/', $exact['files'][0]['folder']);
|
||||
|
||||
// equality is against the stored canonical form -- no normalization on query values
|
||||
$this->assertEquals(0, $list(['queries' => [Query::equal('folder', ['photos'])->toString()]])['total']);
|
||||
|
||||
// root only
|
||||
$this->assertEquals(1, $list(['folder' => ''])['total']);
|
||||
$this->assertEquals('', $list(['folder' => ''])['files'][0]['folder']);
|
||||
$root = $list(['queries' => [Query::equal('folder', [''])->toString()]]);
|
||||
$this->assertEquals(1, $root['total']);
|
||||
$this->assertEquals('', $root['files'][0]['folder']);
|
||||
|
||||
// recursive via queries
|
||||
// recursive via prefix
|
||||
$recursive = $list(['queries' => [Query::startsWith('folder', 'photos/')->toString()]]);
|
||||
$this->assertEquals(2, $recursive['total']);
|
||||
|
||||
// invalid parent
|
||||
$response = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), ['folder' => '/photos']);
|
||||
$this->assertEquals(400, $response['headers']['status-code']);
|
||||
|
||||
$response = $this->client->call(Client::METHOD_DELETE, '/storage/buckets/' . $bucketId, [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
|
||||
Reference in new issue
Block a user