mirror of
https://github.com/SoPat712/allstarr.git
synced 2026-10-07 22:03:14 -04:00
fix(admin): ignore missing managed audio files
This commit is contained in:
2 files changed
+64
-4
No files matched your search
@@ -0,0 +1,40 @@
|
||||
using allstarr.Controllers;
|
||||
|
||||
namespace allstarr.Tests;
|
||||
|
||||
public sealed class AdminUiStorageCountTests
|
||||
{
|
||||
[Fact]
|
||||
public void ExistingStorageMappings_ExcludeMissingAndOutsideFiles()
|
||||
{
|
||||
var testRoot = Path.Combine(Path.GetTempPath(), $"allstarr-home-storage-{Guid.NewGuid():N}");
|
||||
var downloadRoot = Path.Combine(testRoot, "downloads");
|
||||
var paths = new[]
|
||||
{
|
||||
Path.Combine(downloadRoot, "cache", "cached.mp3"),
|
||||
Path.Combine(downloadRoot, "transcoded", "transcoded.m4a"),
|
||||
Path.Combine(downloadRoot, "permanent", "permanent.flac"),
|
||||
Path.Combine(downloadRoot, "kept", "legacy.ogg"),
|
||||
Path.Combine(downloadRoot, "cache", "missing.mp3"),
|
||||
Path.Combine(testRoot, "outside.mp3")
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
foreach (var path in paths.Where(path => !path.EndsWith("missing.mp3", StringComparison.Ordinal)))
|
||||
{
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(path)!);
|
||||
File.WriteAllText(path, "fixture");
|
||||
}
|
||||
|
||||
var counts = AdminUiController.CountExistingStorageMappings(paths, downloadRoot);
|
||||
|
||||
Assert.Equal(2, counts.CacheTracks);
|
||||
Assert.Equal(2, counts.KeptTracks);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (Directory.Exists(testRoot)) Directory.Delete(testRoot, recursive: true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -275,10 +275,7 @@ public class AdminUiController : ControllerBase
|
||||
var paths = await context.DownloadedSongMappings.AsNoTracking()
|
||||
.Select(item => item.LocalPath)
|
||||
.ToArrayAsync(cancellationToken);
|
||||
cacheTracks = paths.Count(path => IsStoredUnder(path, Path.Combine(downloadRoot, "cache")) ||
|
||||
IsStoredUnder(path, Path.Combine(downloadRoot, "transcoded")));
|
||||
keptTracks = paths.Count(path => IsStoredUnder(path, Path.Combine(downloadRoot, "permanent")) ||
|
||||
IsStoredUnder(path, Path.Combine(downloadRoot, "kept")));
|
||||
(cacheTracks, keptTracks) = CountExistingStorageMappings(paths, downloadRoot);
|
||||
}
|
||||
var storage = services.GetService<DurableStorageState>()?.GetSnapshot();
|
||||
var providerHealth = session.IsAdministrator
|
||||
@@ -336,6 +333,29 @@ public class AdminUiController : ControllerBase
|
||||
}
|
||||
}
|
||||
|
||||
internal static (int CacheTracks, int KeptTracks) CountExistingStorageMappings(
|
||||
IEnumerable<string> paths,
|
||||
string downloadRoot)
|
||||
{
|
||||
var cacheTracks = 0;
|
||||
var keptTracks = 0;
|
||||
foreach (var path in paths)
|
||||
{
|
||||
if (!System.IO.File.Exists(path)) continue;
|
||||
if (IsStoredUnder(path, Path.Combine(downloadRoot, "cache")) ||
|
||||
IsStoredUnder(path, Path.Combine(downloadRoot, "transcoded")))
|
||||
{
|
||||
cacheTracks++;
|
||||
}
|
||||
else if (IsStoredUnder(path, Path.Combine(downloadRoot, "permanent")) ||
|
||||
IsStoredUnder(path, Path.Combine(downloadRoot, "kept")))
|
||||
{
|
||||
keptTracks++;
|
||||
}
|
||||
}
|
||||
return (cacheTracks, keptTracks);
|
||||
}
|
||||
|
||||
[HttpGet("activity")]
|
||||
public async Task<IActionResult> GetDashboardActivity(
|
||||
[FromQuery] int limit = 20,
|
||||
|
||||
Reference in new issue
Block a user