From 18cd07b3200cf198bab4075a073d1830078b0f7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yusuf=20=C3=96zdemir?= Date: Fri, 14 Jun 2024 09:33:13 +0300 Subject: [PATCH] add subfolder --- src/VueFinder.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/VueFinder.php b/src/VueFinder.php index f0ab74d..9eca2db 100755 --- a/src/VueFinder.php +++ b/src/VueFinder.php @@ -83,6 +83,7 @@ public function init($config): void $route_array = [ 'index' => 'get', + 'subfolders' => 'get', 'download' => 'get', 'preview' => 'get', 'search' => 'get', @@ -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.'); @@ -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