using Microsoft.AspNetCore.Mvc; using PlaylistShared.Api.Services; namespace PlaylistShared.Api.Controllers; [ApiController] [Route("shared")] public class OgController : ControllerBase { private readonly SharedPlaylistService _sharedService; private readonly string _clientBaseUrl; public OgController(SharedPlaylistService sharedService, IConfiguration configuration) { _sharedService = sharedService; _clientBaseUrl = configuration["Client:BaseUrl"]?.TrimEnd('/') ?? ""; } [HttpGet("{token}")] [Produces("text/html")] public async Task GetOgPage(string token) { var entity = await _sharedService.GetEntityByTokenAsync(token); var pwaUrl = $"{_clientBaseUrl}/shared/{token}"; string title = entity?.Title ?? "Playlist Share"; string description = entity != null ? $"Слушайте плейлист «{entity.Title}» на Playlist Share" : "Совместные плейлисты Яндекс.Музыки"; string imageUrl = !string.IsNullOrEmpty(entity?.CoverUrl) ? entity.CoverUrl : ""; var html = $""" {HtmlEncode(title)} {(string.IsNullOrEmpty(imageUrl) ? "" : $"""""")} {(string.IsNullOrEmpty(imageUrl) ? "" : $"""""")}

Перенаправление на {HtmlEncode(title)}

"""; return Content(html, "text/html; charset=utf-8"); } private static string HtmlEncode(string s) => System.Web.HttpUtility.HtmlAttributeEncode(s); private static string JsEncode(string s) => s.Replace("\\", "\\\\").Replace("'", "\\'").Replace("\"", "\\\""); }