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>
159 lines
6.3 KiB
C#
159 lines
6.3 KiB
C#
using DivanRazor.Utils;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
using Newtonsoft.Json.Linq;
|
|
using Newtonsoft.Json;
|
|
using RMuseum.Models.Divan.ViewModels;
|
|
using System.Net.Http;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System;
|
|
using RMuseum.Utils;
|
|
|
|
namespace DivanRazor.Areas.User.Pages
|
|
{
|
|
public class CatEditorModel : PageModel
|
|
{
|
|
/// <summary>
|
|
/// my last edit
|
|
/// </summary>
|
|
public DivanCatCorrectionViewModel MyLastEdit { get; set; }
|
|
|
|
/// <summary>
|
|
/// page
|
|
/// </summary>
|
|
public DivanPageCompleteViewModel PageInformation { get; set; }
|
|
/// <summary>
|
|
/// fatal error
|
|
/// </summary>
|
|
public string FatalError { get; set; }
|
|
|
|
/// <summary>
|
|
/// cat id
|
|
/// </summary>
|
|
public int CatId { get; set; }
|
|
|
|
[BindProperty]
|
|
public DivanCatCorrectionViewModel Correction { get; set; }
|
|
|
|
/// <summary>
|
|
/// get
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<IActionResult> OnGetAsync()
|
|
{
|
|
if (string.IsNullOrEmpty(Request.Cookies["Token"]))
|
|
return Redirect("/");
|
|
|
|
FatalError = Request.Query["FatalError"];
|
|
using (HttpClient secureClient = new HttpClient(new DivanReloginHandler(Request, Response)))
|
|
{
|
|
if (await DivanSessionChecker.PrepareClient(secureClient, Request, Response))
|
|
{
|
|
var pageUrlResponse = await secureClient.GetAsync($"{APIRoot.Url}/api/divan/pageurl?id={Request.Query["id"]}");
|
|
if (!pageUrlResponse.IsSuccessStatusCode)
|
|
{
|
|
FatalError = JsonConvert.DeserializeObject<string>(await pageUrlResponse.Content.ReadAsStringAsync());
|
|
return Page();
|
|
}
|
|
var pageUrl = JsonConvert.DeserializeObject<string>(await pageUrlResponse.Content.ReadAsStringAsync());
|
|
|
|
var pageQuery = await secureClient.GetAsync($"{APIRoot.Url}/api/divan/page?url={pageUrl}");
|
|
if (!pageQuery.IsSuccessStatusCode)
|
|
{
|
|
FatalError = JsonConvert.DeserializeObject<string>(await pageQuery.Content.ReadAsStringAsync());
|
|
return Page();
|
|
}
|
|
PageInformation = JObject.Parse(await pageQuery.Content.ReadAsStringAsync()).ToObject<DivanPageCompleteViewModel>();
|
|
|
|
CatId = PageInformation.PoetOrCat.Cat.Id;
|
|
var editResponse = await secureClient.GetAsync($"{APIRoot.Url}/api/divan/cat/correction/last/{CatId}");
|
|
if (!editResponse.IsSuccessStatusCode)
|
|
{
|
|
FatalError = JsonConvert.DeserializeObject<string>(await editResponse.Content.ReadAsStringAsync());
|
|
return Page();
|
|
}
|
|
MyLastEdit = JsonConvert.DeserializeObject<DivanCatCorrectionViewModel>(await editResponse.Content.ReadAsStringAsync());
|
|
|
|
if (MyLastEdit != null)
|
|
{
|
|
Correction = JsonConvert.DeserializeObject<DivanCatCorrectionViewModel>(await editResponse.Content.ReadAsStringAsync());
|
|
}
|
|
else
|
|
{
|
|
Correction = new DivanCatCorrectionViewModel()
|
|
{
|
|
CatId = CatId,
|
|
DescriptionHtml = PageInformation.PoetOrCat.Cat.DescriptionHtml,
|
|
};
|
|
}
|
|
|
|
|
|
}
|
|
else
|
|
{
|
|
FatalError = "لطفاً از دیوان خارج و مجددا به آن وارد شوید.";
|
|
}
|
|
}
|
|
return Page();
|
|
}
|
|
|
|
public async Task<IActionResult> OnPostDeleteCatCorrectionAsync(int catid)
|
|
{
|
|
using (HttpClient secureClient = new HttpClient(new DivanReloginHandler(Request, Response)))
|
|
{
|
|
if (await DivanSessionChecker.PrepareClient(secureClient, Request, Response))
|
|
{
|
|
HttpResponseMessage response = await secureClient.DeleteAsync(
|
|
$"{APIRoot.Url}/api/divan/cat/correction/{catid}");
|
|
if (!response.IsSuccessStatusCode)
|
|
{
|
|
return BadRequest(JsonConvert.DeserializeObject<string>(await response.Content.ReadAsStringAsync()));
|
|
}
|
|
return new OkObjectResult(true);
|
|
}
|
|
}
|
|
return new BadRequestObjectResult("لطفاً از دیوان خارج و مجددا به آن وارد شوید.");
|
|
}
|
|
|
|
|
|
|
|
public async Task<IActionResult> OnPostAsync()
|
|
{
|
|
try
|
|
{
|
|
Correction.Description = DivanHtmlTools.StripHtmlTags(Correction.DescriptionHtml);
|
|
using (HttpClient secureClient = new HttpClient(new DivanReloginHandler(Request, Response)))
|
|
{
|
|
if (await DivanSessionChecker.PrepareClient(secureClient, Request, Response))
|
|
{
|
|
HttpResponseMessage response = await secureClient.PostAsync(
|
|
$"{APIRoot.Url}/api/divan/cat/correction",
|
|
new StringContent(JsonConvert.SerializeObject(Correction),
|
|
Encoding.UTF8,
|
|
"application/json"));
|
|
if (!response.IsSuccessStatusCode)
|
|
{
|
|
FatalError = JsonConvert.DeserializeObject<string>(await response.Content.ReadAsStringAsync());
|
|
}
|
|
}
|
|
else
|
|
{
|
|
FatalError = "لطفاً از دیوان خارج و مجددا به آن وارد شوید.";
|
|
}
|
|
|
|
}
|
|
}
|
|
catch (Exception exp)
|
|
{
|
|
FatalError = exp.ToString();
|
|
|
|
}
|
|
return Redirect($"/User/CatEditor?id={Request.Query["id"]}&FatalError={FatalError}");
|
|
|
|
}
|
|
|
|
|
|
}
|
|
}
|