|
8 | 8 | namespace OCA\Files\Controller; |
9 | 9 |
|
10 | 10 | use OC\Files\FilenameValidator; |
| 11 | +use OC\Files\Search\SearchComparison; |
| 12 | +use OC\Files\Search\SearchQuery; |
11 | 13 | use OCA\Files\Activity\Helper; |
12 | 14 | use OCA\Files\AppInfo\Application; |
13 | 15 | use OCA\Files\Event\LoadAdditionalScriptsEvent; |
|
26 | 28 | use OCP\AppFramework\Services\IInitialState; |
27 | 29 | use OCP\Collaboration\Resources\LoadAdditionalScriptsEvent as ResourcesLoadAdditionalScriptsEvent; |
28 | 30 | use OCP\EventDispatcher\IEventDispatcher; |
| 31 | +use OCP\Files\Cache\ICacheEntry; |
29 | 32 | use OCP\Files\Folder; |
30 | 33 | use OCP\Files\IRootFolder; |
31 | 34 | use OCP\Files\NotFoundException; |
| 35 | +use OCP\Files\Search\ISearchComparison; |
32 | 36 | use OCP\Files\Template\ITemplateManager; |
33 | 37 | use OCP\IConfig; |
34 | 38 | use OCP\IL10N; |
@@ -160,6 +164,35 @@ public function index($dir = '', $view = '', $fileid = null, $fileNotFound = fal |
160 | 164 | $favElements = []; |
161 | 165 | } |
162 | 166 |
|
| 167 | + try { |
| 168 | + $userFolder = $this->rootFolder->getUserFolder($userId); |
| 169 | + $searchQuery = new SearchQuery( |
| 170 | + new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'mimetype', ICacheEntry::DIRECTORY_MIMETYPE), |
| 171 | + 0, |
| 172 | + 0, |
| 173 | + [], |
| 174 | + $this->userSession->getUser(), |
| 175 | + false, |
| 176 | + ); |
| 177 | + /** @var Folder[] $folders */ |
| 178 | + $folders = $userFolder->search($searchQuery); |
| 179 | + $folderTreeFolders = array_values(array_map(fn (Folder $folder) => [ |
| 180 | + 'fileid' => $folder->getId(), |
| 181 | + 'displayname' => $folder->getName(), |
| 182 | + 'owner' => $folder->getOwner()?->getUID(), |
| 183 | + 'path' => $userFolder->getRelativePath($folder->getPath()), |
| 184 | + 'parentid' => $folder->getParentId(), |
| 185 | + 'mountType' => $folder->getMountPoint()->getMountType(), |
| 186 | + 'mime' => $folder->getMimetype(), |
| 187 | + 'size' => $folder->getSize(), |
| 188 | + 'mtime' => $folder->getMTime(), |
| 189 | + 'crtime' => $folder->getCreationTime(), |
| 190 | + 'permissions' => $folder->getPermissions(), |
| 191 | + ], $folders)); |
| 192 | + } catch (\RuntimeException $e) { |
| 193 | + $folderTreeFolders = []; |
| 194 | + } |
| 195 | + |
163 | 196 | // If the file doesn't exists in the folder and |
164 | 197 | // exists in only one occurrence, redirect to that file |
165 | 198 | // in the correct folder |
@@ -190,6 +223,7 @@ public function index($dir = '', $view = '', $fileid = null, $fileNotFound = fal |
190 | 223 | $this->initialState->provideInitialState('config', $this->userConfig->getConfigs()); |
191 | 224 | $this->initialState->provideInitialState('viewConfigs', $this->viewConfig->getConfigs()); |
192 | 225 | $this->initialState->provideInitialState('favoriteFolders', $favElements); |
| 226 | + $this->initialState->provideInitialState('folderTreeFolders', $folderTreeFolders); |
193 | 227 |
|
194 | 228 | // File sorting user config |
195 | 229 | $filesSortingConfig = json_decode($this->config->getUserValue($userId, 'files', 'files_sorting_configs', '{}'), true); |
|
0 commit comments