From d35f9af22ed474aa36bd5bcacabcbd04985fc41e Mon Sep 17 00:00:00 2001 From: Christopher Ng Date: Wed, 24 Jul 2024 19:06:31 -0700 Subject: [PATCH] feat(files): Provide folder tree folders state Signed-off-by: Christopher Ng --- apps/files/lib/Controller/ViewController.php | 33 ++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/apps/files/lib/Controller/ViewController.php b/apps/files/lib/Controller/ViewController.php index 3be7e61d01081..9619a8ce00f62 100644 --- a/apps/files/lib/Controller/ViewController.php +++ b/apps/files/lib/Controller/ViewController.php @@ -8,6 +8,8 @@ namespace OCA\Files\Controller; use OC\Files\FilenameValidator; +use OC\Files\Search\SearchComparison; +use OC\Files\Search\SearchQuery; use OCA\Files\Activity\Helper; use OCA\Files\AppInfo\Application; use OCA\Files\Event\LoadAdditionalScriptsEvent; @@ -26,9 +28,11 @@ use OCP\AppFramework\Services\IInitialState; use OCP\Collaboration\Resources\LoadAdditionalScriptsEvent as ResourcesLoadAdditionalScriptsEvent; use OCP\EventDispatcher\IEventDispatcher; +use OCP\Files\Cache\ICacheEntry; use OCP\Files\Folder; use OCP\Files\IRootFolder; use OCP\Files\NotFoundException; +use OCP\Files\Search\ISearchComparison; use OCP\Files\Template\ITemplateManager; use OCP\IConfig; use OCP\IL10N; @@ -160,6 +164,34 @@ public function index($dir = '', $view = '', $fileid = null, $fileNotFound = fal $favElements = []; } + try { + $userFolder = $this->rootFolder->getUserFolder($userId); + $searchQuery = new SearchQuery( + new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'mimetype', ICacheEntry::DIRECTORY_MIMETYPE), + 0, + 0, + [], + $this->userSession->getUser(), + false, + ); + /** @var Folder[] $folders */ + $folders = $userFolder->search($searchQuery); + $folderTreeFolders = array_map(fn (Folder $folder) => [ + 'fileid' => $folder->getId(), + 'displayname' => $folder->getName(), + 'owner' => $folder->getOwner()?->getUID(), + 'path' => $userFolder->getRelativePath($folder->getPath()), + 'mountType' => $folder->getMountPoint()->getMountType(), + 'mime' => $folder->getMimetype(), + 'size' => $folder->getSize(), + 'mtime' => $folder->getMTime(), + 'crtime' => $folder->getCreationTime(), + 'permissions' => $folder->getPermissions(), + ], $folders); + } catch (\RuntimeException $e) { + $folderTreeFolders = []; + } + // If the file doesn't exists in the folder and // exists in only one occurrence, redirect to that file // in the correct folder @@ -190,6 +222,7 @@ public function index($dir = '', $view = '', $fileid = null, $fileNotFound = fal $this->initialState->provideInitialState('config', $this->userConfig->getConfigs()); $this->initialState->provideInitialState('viewConfigs', $this->viewConfig->getConfigs()); $this->initialState->provideInitialState('favoriteFolders', $favElements); + $this->initialState->provideInitialState('folderTreeFolders', $folderTreeFolders); // File sorting user config $filesSortingConfig = json_decode($this->config->getUserValue($userId, 'files', 'files_sorting_configs', '{}'), true);