Projects (GanjooRazor -> DiwanRazor, GanjoorService.sln -> DiwanService.sln), files, folders, classes, namespaces, settings, API routes (/api/diwan) and DB tables (Diwan*). 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
3.4 KiB
C#
85 lines
3.4 KiB
C#
using DiwanRazor.Models.MuseumLink;
|
|
using DiwanRazor.Utils;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
using Newtonsoft.Json;
|
|
using RMuseum.Models.DiwanIntegration.ViewModels;
|
|
using System.Net;
|
|
using System.Net.Http;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace DiwanRazor.Pages
|
|
{
|
|
public class PinModel : PageModel
|
|
{
|
|
/// <summary>
|
|
/// related image suggestion model
|
|
/// </summary>
|
|
[BindProperty]
|
|
public RelatedImageSuggestionModel RelatedImageSuggestionModel { get; set; }
|
|
|
|
/// <summary>
|
|
/// ارسال موفق
|
|
/// </summary>
|
|
public bool Succeeded { get; set; }
|
|
|
|
/// <summary>
|
|
/// خطا
|
|
/// </summary>
|
|
public string LastError { get; set; }
|
|
|
|
/// <summary>
|
|
/// is logged on
|
|
/// </summary>
|
|
public bool LoggedIn { get; set; }
|
|
|
|
public async Task<IActionResult> OnPostAsync()
|
|
{
|
|
Succeeded = false;
|
|
LastError = "";
|
|
LoggedIn = !string.IsNullOrEmpty(Request.Cookies["Token"]);
|
|
if(!LoggedIn)
|
|
{
|
|
LastError = $"برای پیشنهاد تصاویر مرتبط با اشعار لازم است ابتدا با نام کاربری خود وارد دیوان شوید. </p><p><a href=\"/login/?redirect={RelatedImageSuggestionModel.DiwanUrl}\")>ورود به دیوان</a>";
|
|
}
|
|
else
|
|
if (Request.Query["final"] == "1")
|
|
{
|
|
using (HttpClient secureClient = new HttpClient(new DiwanReloginHandler(Request, Response)))
|
|
{
|
|
if(await DiwanSessionChecker.PrepareClient(secureClient, Request, Response))
|
|
{
|
|
PinterestLinkViewModel model = new PinterestLinkViewModel()
|
|
{
|
|
DiwanPostId = RelatedImageSuggestionModel.PoemId,
|
|
DiwanUrl = $"https://ganjoor.net{RelatedImageSuggestionModel.DiwanUrl}",
|
|
DiwanTitle = RelatedImageSuggestionModel.DiwanTitle,
|
|
AltText = RelatedImageSuggestionModel.AltText,
|
|
LinkType = RMuseum.Models.DiwanIntegration.LinkType.Pinterest,
|
|
PinterestUrl = RelatedImageSuggestionModel.PinterestUrl,
|
|
PinterestImageUrl = RelatedImageSuggestionModel.PinterestImageUrl
|
|
};
|
|
var stringContent = new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, "application/json");
|
|
var response = await secureClient.PostAsync($"{APIRoot.Url}/api/artifacts/pinterest", stringContent);
|
|
|
|
if (response.StatusCode != HttpStatusCode.OK)
|
|
{
|
|
LastError = JsonConvert.DeserializeObject<string>(await response.Content.ReadAsStringAsync());
|
|
}
|
|
else
|
|
{
|
|
Succeeded = true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
LastError = "لطفاً از دیوان خارج و مجددا به آن وارد شوید.";
|
|
}
|
|
}
|
|
}
|
|
return Page();
|
|
}
|
|
}
|
|
}
|