mirror of
https://github.com/SoPat712/allstarr.git
synced 2026-04-23 10:42:37 -04:00
58 lines
1.7 KiB
C#
58 lines
1.7 KiB
C#
using allstarr.Models.Settings;
|
|
|
|
namespace allstarr.Services.Common;
|
|
|
|
public static class SpotifyPlaylistScopeResolver
|
|
{
|
|
public static SpotifyPlaylistConfig? ResolveConfig(
|
|
SpotifyImportSettings settings,
|
|
string playlistName,
|
|
string? userId = null,
|
|
string? jellyfinPlaylistId = null)
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(jellyfinPlaylistId))
|
|
{
|
|
var byJellyfinId = settings.GetPlaylistByJellyfinId(jellyfinPlaylistId.Trim());
|
|
if (byJellyfinId != null)
|
|
{
|
|
return byJellyfinId;
|
|
}
|
|
}
|
|
|
|
return settings.GetPlaylistByName(playlistName, userId, jellyfinPlaylistId);
|
|
}
|
|
|
|
public static string? GetUserId(SpotifyPlaylistConfig? playlist, string? fallbackUserId = null)
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(playlist?.UserId))
|
|
{
|
|
return playlist.UserId.Trim();
|
|
}
|
|
|
|
// A configured playlist with no explicit owner is global. Do not
|
|
// accidentally scope its caches to whichever Jellyfin user made
|
|
// the current request.
|
|
if (playlist != null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
return string.IsNullOrWhiteSpace(fallbackUserId) ? null : fallbackUserId.Trim();
|
|
}
|
|
|
|
public static string? GetScopeId(SpotifyPlaylistConfig? playlist, string? fallbackScopeId = null)
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(playlist?.JellyfinId))
|
|
{
|
|
return playlist.JellyfinId.Trim();
|
|
}
|
|
|
|
if (!string.IsNullOrWhiteSpace(playlist?.Id))
|
|
{
|
|
return playlist.Id.Trim();
|
|
}
|
|
|
|
return string.IsNullOrWhiteSpace(fallbackScopeId) ? null : fallbackScopeId.Trim();
|
|
}
|
|
}
|