Release 1.0.0.11: repair broken virtual folders

This commit is contained in:
1xDed committed 2026-12-01 02:48:50 +03:00
1 parent 0dbf00a055
commit 4bb222af8b
6 files changed
+64 -11

No files matched your search

@@ -1,5 +1,7 @@
using System.Collections.Concurrent;
using Jellyfin.Plugin.YandexMusic.Yandex;
using MediaBrowser.Controller;
using MediaBrowser.Controller.Library;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
@@ -16,13 +18,20 @@ public class YandexMusicController : ControllerBase
private static readonly ConcurrentDictionary<string, DateTimeOffset> Sessions = new();
private readonly YandexMusicClient _client;
private readonly IServerApplicationPaths _paths;
private readonly ILibraryManager _libraryManager;
/// <summary>
/// Initializes a new instance of the <see cref="YandexMusicController"/> class.
/// </summary>
public YandexMusicController(YandexMusicClient client)
public YandexMusicController(
YandexMusicClient client,
IServerApplicationPaths paths,
ILibraryManager libraryManager)
{
_client = client;
_paths = paths;
_libraryManager = libraryManager;
}
/// <summary>Starts the device flow.</summary>
@@ -88,6 +97,47 @@ public class YandexMusicController : ControllerBase
connected ? null : "api.music.yandex.net недоступен");
}
/// <summary>
/// Removes broken virtual-folder entries (e.g. a library left without an item id or paths),
/// which Jellyfin cannot delete through its own API.
/// </summary>
[HttpPost("RepairLibraries")]
public ActionResult<RepairLibrariesResult> RepairLibraries()
{
var live = _libraryManager.GetVirtualFolders();
var deleted = new List<string>();
if (Directory.Exists(_paths.DefaultUserViewsPath))
{
foreach (var directory in Directory.EnumerateDirectories(_paths.DefaultUserViewsPath))
{
var name = Path.GetFileName(directory);
var info = live.FirstOrDefault(v => string.Equals(v.Name, name, StringComparison.OrdinalIgnoreCase));
var broken = info is null
|| string.IsNullOrEmpty(info.ItemId)
|| info.Locations.Length == 0;
if (broken)
{
try
{
Directory.Delete(directory, true);
deleted.Add(name);
}
catch (Exception ex)
{
return StatusCode(500, new { error = ex.Message, name });
}
}
}
}
return new RepairLibrariesResult(
deleted,
live.Where(v => !deleted.Contains(v.Name, StringComparer.OrdinalIgnoreCase))
.Select(v => v.Name)
.ToList());
}
/// <summary>Clears the saved token.</summary>
[HttpPost("Logout")]
public ActionResult Logout()
@@ -115,3 +165,6 @@ public record DevicePollResult(string Status, string? Token, string? Error);
/// <summary>Plugin status.</summary>
public record StatusResult(bool Connected, bool HasToken, string? Error);
/// <summary>Result of the broken-library cleanup.</summary>
public record RepairLibrariesResult(List<string> Deleted, List<string> Remaining);