Files
PlaylistShared/PlaylistShared.Pwa/Extensions/StringExtensions.cs

19 lines
1.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
namespace PlaylistShared.Pwa.Extensions;
public static class StringExtensions
{
/// <summary>
/// Преобразует шаблон URL обложки Яндекс.Музыки в полный URL с указанным размером.
/// </summary>
/// <param name="coverUri">Шаблон URL (например, "avatars.yandex.net/get-music-content/.../%%")</param>
/// <param name="width">Желаемая ширина обложки (по умолчанию 200)</param>
/// <param name="height">Желаемая высота обложки (по умолчанию 200)</param>
/// <returns>Полный URL обложки или пустую строку, если входная строка null или пуста.</returns>
public static string FormatCoverUrl(this string? coverUri, int width = 200, int height = 200)
{
if (string.IsNullOrEmpty(coverUri))
return string.Empty;
return "https://" + coverUri.Replace("%%", $"{width}x{height}");
}
}