ImportNaskbanPaperSources

This commit is contained in:
Hamid Reza Mohammadi 2024-07-26 11:58:35 +03:30
parent 28c2d36c7c
commit 80120da66a
3 changed files with 59 additions and 0 deletions

View File

@ -331,6 +331,8 @@
<p><a role="button" onclick="rebuildRebuildWordCounts(@Model.PageInformation.PoetOrCat.Poet.Id)" class="actionlink" title="شمارش واژگان">شمارش واژگان</a></p>
<p><a role="button" onclick="discoverNaskbanPaperSources(@Model.PageInformation.PoetOrCat.Poet.Id)" class="actionlink" title="فهرست کردن کتابهای نسکبان">فهرست کردن کتابهای نسکبان</a></p>
<p><a role="button" onclick="transilerate()" class="actionlink" title="برگردان تاجیکی">برگردان تاجیکی</a></p>

View File

@ -6,6 +6,7 @@ using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using RMuseum.Models.Ganjoor;
using RMuseum.Models.Ganjoor.ViewModels;
using RSecurityBackend.Models.Auth.ViewModels;
using System;
using System.Collections.Generic;
using System.Net.Http;
@ -429,6 +430,35 @@ namespace GanjooRazor.Areas.Admin.Pages
return new OkObjectResult(false);
}
public async Task<IActionResult> OnPostImportNaskbanPaperSourcesAsync(int poetId, string username, string password)
{
using (HttpClient secureClient = new HttpClient())
{
if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response))
{
LoginViewModel model = new LoginViewModel()
{
Username = username,
Password = password,
ClientAppName = "GanjooRazor",
Language = "fa-IR"
};
var stringContent = new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, "application/json");
HttpResponseMessage response = await secureClient.PutAsync($"{APIRoot.Url}/api/ganjoor/naskban/import/poetbooks/{poetId}", stringContent);
if (!response.IsSuccessStatusCode)
{
return BadRequest(JsonConvert.DeserializeObject<string>(await response.Content.ReadAsStringAsync()));
}
return new OkObjectResult(true);
}
}
return new OkObjectResult(false);
}

View File

@ -262,6 +262,33 @@
});
}
function discoverNaskbanPaperSources(poetId) {
var username = window.prompt('username:');
var password = window.prompt('password:');
var url = '?handler=ImportNaskbanPaperSources';
$.ajax({
type: "POST",
data: {
poetId: poetId,
username: username,
password: password,
},
url: url,
error: function () {
alert('خطا رخ داد.')
},
success: function () {
alert('فرایند بازسازی شروع شد.')
},
});
}