From bf6cbc8a35e1da4a36c1ddc57225f50b1bada387 Mon Sep 17 00:00:00 2001 From: Mikal Stordal Date: Tue, 19 Dec 2023 14:52:47 +0100 Subject: [PATCH] fix: order returned folders by path in v3 --- .../API/v3/Controllers/FolderController.cs | 134 +++++++++--------- 1 file changed, 70 insertions(+), 64 deletions(-) diff --git a/Shoko.Server/API/v3/Controllers/FolderController.cs b/Shoko.Server/API/v3/Controllers/FolderController.cs index ab22d929e..57e28e3bb 100644 --- a/Shoko.Server/API/v3/Controllers/FolderController.cs +++ b/Shoko.Server/API/v3/Controllers/FolderController.cs @@ -37,65 +37,68 @@ public class FolderController : BaseController "sysfs", }; + [HttpGet("MountPoints")] [HttpGet("Drives")] - public ActionResult> GetDrives() + public ActionResult> GetMountPoints() { - return DriveInfo.GetDrives().Select(d => - { - if (d.DriveType == DriveType.Unknown) - return null; - - string fullName; - try + return DriveInfo.GetDrives() + .Select(d => { - fullName = d.RootDirectory.FullName; - } - catch - { - return null; - } + if (d.DriveType == DriveType.Unknown) + return null; - string driveFormat; - try - { - driveFormat = d.DriveFormat; - } - catch - { - return null; - } + string fullName; + try + { + fullName = d.RootDirectory.FullName; + } + catch + { + return null; + } - foreach (var format in ExcludedFormats) - { - if (driveFormat == format) + string driveFormat; + try + { + driveFormat = d.DriveFormat; + } + catch + { return null; - } + } - ChildItems childItems = null; - try - { - childItems = d.IsReady - ? new ChildItems() - { - Files = d.RootDirectory.GetFiles()?.Length ?? 0, - Folders = d.RootDirectory.GetDirectories()?.Length ?? 0, - } - : null; - } - catch (UnauthorizedAccessException) - { - } + foreach (var format in ExcludedFormats) + { + if (driveFormat == format) + return null; + } - return new Drive() - { - Path = fullName, - IsAccessible = childItems != null, - Sizes = childItems, - Type = d.DriveType, - }; - }) - .Where(mountPoint => mountPoint != null) - .ToList(); + ChildItems childItems = null; + try + { + childItems = d.IsReady + ? new ChildItems() + { + Files = d.RootDirectory.GetFiles()?.Length ?? 0, + Folders = d.RootDirectory.GetDirectories()?.Length ?? 0, + } + : null; + } + catch (UnauthorizedAccessException) + { + } + + return new Drive() + { + Path = fullName, + IsAccessible = childItems != null, + Sizes = childItems, + Type = d.DriveType, + }; + }) + .Where(mountPoint => mountPoint != null) + .OrderBy(mountPoint => mountPoint.Path) + .ToList(); } [HttpGet] @@ -107,22 +110,25 @@ public ActionResult> GetFolder([FromQuery] string path) } var root = new DirectoryInfo(path); - return root.GetDirectories().Select(dir => - { - ChildItems childItems = null; - try + return root.GetDirectories() + .Select(dir => { - childItems = new ChildItems() + ChildItems childItems = null; + try { - Files = dir.GetFiles()?.Length ?? 0, Folders = dir.GetDirectories()?.Length ?? 0 - }; - } - catch (UnauthorizedAccessException) - { - } + childItems = new ChildItems() + { + Files = dir.GetFiles()?.Length ?? 0, Folders = dir.GetDirectories()?.Length ?? 0 + }; + } + catch (UnauthorizedAccessException) + { + } - return new Folder() { Path = dir.FullName, IsAccessible = childItems != null, Sizes = childItems }; - }).ToList(); + return new Folder() { Path = dir.FullName, IsAccessible = childItems != null, Sizes = childItems }; + }) + .OrderBy(folder => folder.Path) + .ToList(); } public FolderController(ISettingsProvider settingsProvider) : base(settingsProvider)