Skip to content

Commit

Permalink
fix: order returned folders by path in v3
Browse files Browse the repository at this point in the history
  • Loading branch information
revam committed Dec 19, 2023
1 parent 6e82bb1 commit bf6cbc8
Showing 1 changed file with 70 additions and 64 deletions.
134 changes: 70 additions & 64 deletions Shoko.Server/API/v3/Controllers/FolderController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,65 +37,68 @@ public class FolderController : BaseController
"sysfs",
};

[HttpGet("MountPoints")]
[HttpGet("Drives")]
public ActionResult<IEnumerable<Drive>> GetDrives()
public ActionResult<IEnumerable<Drive>> 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]
Expand All @@ -107,22 +110,25 @@ public ActionResult<IEnumerable<Folder>> 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)
Expand Down

0 comments on commit bf6cbc8

Please sign in to comment.