Skip to content

Commit

Permalink
add subfolder
Browse files Browse the repository at this point in the history
  • Loading branch information
n1crack committed Jun 14, 2024
1 parent 97562dd commit 18cd07b
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/VueFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public function init($config): void

$route_array = [
'index' => 'get',
'subfolders' => 'get',
'download' => 'get',
'preview' => 'get',
'search' => 'get',
Expand Down Expand Up @@ -112,7 +113,7 @@ public function init($config): void
}

$adapter = $this->storageAdapters[$this->adapterKey];
$readonly_array = ['index', 'download', 'preview', 'search'];
$readonly_array = ['index', 'download', 'preview', 'search', 'subfolders'];

if ($adapter instanceof ReadOnlyFilesystemAdapter && !in_array($query, $readonly_array, true)) {
throw new Exception('This is a readonly storage.');
Expand Down Expand Up @@ -175,6 +176,23 @@ public function index()
return new JsonResponse(compact(['adapter', 'storages', 'dirname', 'files']));
}

public function subfolders()
{
$dirname = $this->request->get('path', $this->adapterKey . '://');

$folders = $this->manager
->listContents($dirname)
->filter(fn(StorageAttributes $attributes) => $attributes->isDir())
->map(fn(StorageAttributes $attributes) => [
'adapter' => $this->adapterKey,
'path' => $attributes->path(),
'basename' => basename($attributes->path()),
])
->toArray();;

return new JsonResponse(compact(['folders']));
}

/**
* @return JsonResponse
* @throws FilesystemException
Expand Down

0 comments on commit 18cd07b

Please sign in to comment.