From b137021b1f2de27a4abecccd4839dfb0ad9d9b49 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Thu, 13 Nov 2025 01:32:25 +0800 Subject: [PATCH] :sparkles: File index controller returns folders --- .../Index/FileIndexController.cs | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/DysonNetwork.Drive/Index/FileIndexController.cs b/DysonNetwork.Drive/Index/FileIndexController.cs index c66bce9..74febab 100644 --- a/DysonNetwork.Drive/Index/FileIndexController.cs +++ b/DysonNetwork.Drive/Index/FileIndexController.cs @@ -36,10 +36,17 @@ public class FileIndexController( { var fileIndexes = await fileIndexService.GetByPathAsync(accountId, path); + // Get all file indexes for this account to extract child folders + var allFileIndexes = await fileIndexService.GetByAccountIdAsync(accountId); + + // Extract unique child folder paths + var childFolders = ExtractChildFolders(allFileIndexes, path); + return Ok(new { Path = path, Files = fileIndexes, + Folders = childFolders, TotalCount = fileIndexes.Count }); } @@ -55,6 +62,41 @@ public class FileIndexController( } } + /// + /// Extracts unique child folder paths from all file indexes for a given parent path + /// + /// All file indexes for the account + /// The parent path to find children for + /// List of unique child folder names + private List ExtractChildFolders(List allFileIndexes, string parentPath) + { + var normalizedParentPath = FileIndexService.NormalizePath(parentPath); + var childFolders = new HashSet(); + + foreach (var index in allFileIndexes) + { + var normalizedIndexPath = FileIndexService.NormalizePath(index.Path); + + // Check if this path is a direct child of the parent path + if (normalizedIndexPath.StartsWith(normalizedParentPath) && + normalizedIndexPath != normalizedParentPath) + { + // Remove the parent path prefix to get the relative path + var relativePath = normalizedIndexPath.Substring(normalizedParentPath.Length); + + // Extract the first folder name (direct child) + var firstSlashIndex = relativePath.IndexOf('/'); + if (firstSlashIndex > 0) + { + var folderName = relativePath.Substring(0, firstSlashIndex); + childFolders.Add(folderName); + } + } + } + + return childFolders.OrderBy(f => f).ToList(); + } + /// /// Gets all files for the current user (across all paths) ///