mirror of
https://github.com/SoPat712/allstarr.git
synced 2026-02-09 23:55:10 -05:00
Fix playlist linking to save all playlists and add restart banner
- Read playlists from .env file instead of stale in-memory config - This fixes issue where linking multiple playlists only saved the last one - Add prominent restart banner at top when config changes - Update UI immediately after linking/unlinking playlists - Banner shows 'Restart Now' button and dismissible option - All config changes now show the restart banner instead of toast messages - GetJellyfinPlaylists now reads from .env for accurate linked status
This commit is contained in:
@@ -450,7 +450,8 @@ public class AdminController : ControllerBase
|
||||
var decodedName = Uri.UnescapeDataString(name);
|
||||
_logger.LogInformation("Removing playlist: {Name}", decodedName);
|
||||
|
||||
var currentPlaylists = _spotifyImportSettings.Playlists.ToList();
|
||||
// Read current playlists from .env file (not stale in-memory config)
|
||||
var currentPlaylists = await ReadPlaylistsFromEnvFile();
|
||||
var playlist = currentPlaylists.FirstOrDefault(p => p.Name == decodedName);
|
||||
|
||||
if (playlist == null)
|
||||
@@ -767,6 +768,9 @@ public class AdminController : ControllerBase
|
||||
|
||||
var playlists = new List<object>();
|
||||
|
||||
// Read current playlists from .env file for accurate linked status
|
||||
var configuredPlaylists = await ReadPlaylistsFromEnvFile();
|
||||
|
||||
if (doc.RootElement.TryGetProperty("Items", out var items))
|
||||
{
|
||||
foreach (var item in items.EnumerateArray())
|
||||
@@ -784,7 +788,7 @@ public class AdminController : ControllerBase
|
||||
childCount = ric.GetInt32();
|
||||
|
||||
// Check if this playlist is configured in allstarr and get linked Spotify ID
|
||||
var configuredPlaylist = _spotifyImportSettings.Playlists
|
||||
var configuredPlaylist = configuredPlaylists
|
||||
.FirstOrDefault(p => p.Name.Equals(name, StringComparison.OrdinalIgnoreCase));
|
||||
var isConfigured = configuredPlaylist != null;
|
||||
var linkedSpotifyId = configuredPlaylist?.Id;
|
||||
@@ -909,8 +913,11 @@ public class AdminController : ControllerBase
|
||||
_logger.LogInformation("Linking Jellyfin playlist {JellyfinId} to Spotify playlist {SpotifyId} with name {Name}",
|
||||
jellyfinPlaylistId, request.SpotifyPlaylistId, request.Name);
|
||||
|
||||
// Read current playlists from .env file (not in-memory config which is stale)
|
||||
var currentPlaylists = await ReadPlaylistsFromEnvFile();
|
||||
|
||||
// Check if already configured
|
||||
var existingPlaylist = _spotifyImportSettings.Playlists
|
||||
var existingPlaylist = currentPlaylists
|
||||
.FirstOrDefault(p => p.Name.Equals(request.Name, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
if (existingPlaylist != null)
|
||||
@@ -919,7 +926,6 @@ public class AdminController : ControllerBase
|
||||
}
|
||||
|
||||
// Add the playlist to configuration
|
||||
var currentPlaylists = _spotifyImportSettings.Playlists.ToList();
|
||||
currentPlaylists.Add(new SpotifyPlaylistConfig
|
||||
{
|
||||
Name = request.Name,
|
||||
@@ -959,6 +965,64 @@ public class AdminController : ControllerBase
|
||||
return $"MediaBrowser Client=\"Allstarr\", Device=\"Server\", DeviceId=\"allstarr-admin\", Version=\"1.0.0\", Token=\"{_jellyfinSettings.ApiKey}\"";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read current playlists from .env file (not stale in-memory config)
|
||||
/// </summary>
|
||||
private async Task<List<SpotifyPlaylistConfig>> ReadPlaylistsFromEnvFile()
|
||||
{
|
||||
var playlists = new List<SpotifyPlaylistConfig>();
|
||||
|
||||
if (!System.IO.File.Exists(_envFilePath))
|
||||
{
|
||||
return playlists;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var lines = await System.IO.File.ReadAllLinesAsync(_envFilePath);
|
||||
foreach (var line in lines)
|
||||
{
|
||||
if (line.TrimStart().StartsWith("SPOTIFY_IMPORT_PLAYLISTS="))
|
||||
{
|
||||
var value = line.Substring(line.IndexOf('=') + 1).Trim();
|
||||
|
||||
if (string.IsNullOrWhiteSpace(value) || value == "[]")
|
||||
{
|
||||
return playlists;
|
||||
}
|
||||
|
||||
// Parse JSON array format: [["Name","Id","first|last"],...]
|
||||
var playlistArrays = JsonSerializer.Deserialize<string[][]>(value);
|
||||
if (playlistArrays != null)
|
||||
{
|
||||
foreach (var arr in playlistArrays)
|
||||
{
|
||||
if (arr.Length >= 2)
|
||||
{
|
||||
playlists.Add(new SpotifyPlaylistConfig
|
||||
{
|
||||
Name = arr[0].Trim(),
|
||||
Id = arr[1].Trim(),
|
||||
LocalTracksPosition = arr.Length >= 3 &&
|
||||
arr[2].Trim().Equals("last", StringComparison.OrdinalIgnoreCase)
|
||||
? LocalTracksPosition.Last
|
||||
: LocalTracksPosition.First
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to read playlists from .env file");
|
||||
}
|
||||
|
||||
return playlists;
|
||||
}
|
||||
|
||||
private static string MaskValue(string? value, int showLast = 0)
|
||||
{
|
||||
if (string.IsNullOrEmpty(value)) return "(not set)";
|
||||
|
||||
Reference in New Issue
Block a user