Projects (GanjooRazor -> DivanRazor, GanjoorService.sln -> DivanService.sln), files, folders, classes, namespaces, settings, API routes (/api/divan) and DB tables (Divan*). External addresses (ganjoor.net, github.com/ganjoor) unchanged. Migrations renamed consistently (no pending model changes); requires a fresh database. Upstream RUNNING_LOCALLY/SEMANTIC_SEARCH docs archived unmodified under docs/. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
85 lines
2.8 KiB
C#
85 lines
2.8 KiB
C#
using System.Net.Http;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Newtonsoft.Json;
|
|
using RMuseum.Models.Divan.ViewModels;
|
|
using RMuseum.Models.DivanAudio.ViewModels;
|
|
|
|
namespace DivanRazor.Pages
|
|
{
|
|
public class AudioClipModel : PageModel
|
|
{
|
|
/// <summary>
|
|
/// HttpClient instance
|
|
/// </summary>
|
|
private readonly HttpClient _httpClient;
|
|
|
|
/// <summary>
|
|
/// configration file reader (appsettings.json)
|
|
/// </summary>
|
|
private readonly IConfiguration Configuration;
|
|
|
|
|
|
/// <summary>
|
|
/// constructor
|
|
/// </summary>
|
|
/// <param name="httpClient"></param>
|
|
/// <param name="configuration"></param>
|
|
public AudioClipModel(HttpClient httpClient, IConfiguration configuration)
|
|
{
|
|
_httpClient = httpClient;
|
|
Configuration = configuration;
|
|
}
|
|
|
|
/// <summary>
|
|
/// recitation
|
|
/// </summary>
|
|
public PublicRecitationViewModel Recitation { get; set; }
|
|
|
|
/// <summary>
|
|
/// poem
|
|
/// </summary>
|
|
public DivanPoemCompleteViewModel Poem { get; set; }
|
|
|
|
public string LastError { get; set; }
|
|
|
|
public async Task<IActionResult> OnGetAsync()
|
|
{
|
|
if (bool.Parse(Configuration["MaintenanceMode"]))
|
|
{
|
|
return StatusCode(503);
|
|
}
|
|
|
|
if (!ModelState.IsValid)
|
|
{
|
|
return BadRequest();
|
|
}
|
|
|
|
ViewData["TrackingScript"] = Configuration["TrackingScript"] != null && string.IsNullOrEmpty(Request.Cookies["Token"]) ? Configuration["TrackingScript"].Replace("loggedon", "") : Configuration["TrackingScript"];
|
|
|
|
var response = await _httpClient.GetAsync($"{APIRoot.Url}/api/audio/published/{Request.Query["a"]}");
|
|
if (!response.IsSuccessStatusCode)
|
|
{
|
|
LastError = JsonConvert.DeserializeObject<string>(await response.Content.ReadAsStringAsync());
|
|
return Page();
|
|
}
|
|
|
|
Recitation = JsonConvert.DeserializeObject<PublicRecitationViewModel>(await response.Content.ReadAsStringAsync());
|
|
|
|
var responsePoem = await _httpClient.GetAsync($"{APIRoot.Url}/api/divan/poem/{Recitation.PoemId}?verseDetails=true&catInfo=true&rhymes=false&recitations=false&images=false&songs=false&comments=false&navigation=false");
|
|
if (!responsePoem.IsSuccessStatusCode)
|
|
{
|
|
LastError = JsonConvert.DeserializeObject<string>(await responsePoem.Content.ReadAsStringAsync());
|
|
return Page();
|
|
}
|
|
|
|
Poem = JsonConvert.DeserializeObject<DivanPoemCompleteViewModel>(await responsePoem.Content.ReadAsStringAsync());
|
|
|
|
return Page();
|
|
|
|
}
|
|
}
|
|
}
|