From 0d6731ed0b4dd42065e48df635bfecc6074693a9 Mon Sep 17 00:00:00 2001 From: Hamid Reza Mohammadi Date: Wed, 26 Jul 2023 11:47:06 +0330 Subject: [PATCH] #401 StartImportingKnownSourceAsync --- RMuseum/Controllers/PDFLibraryController.cs | 17 +++++++++++++++++ RMuseum/Services/IPDFLibraryService.cs | 6 ++++++ .../PDFLibraryService-SohaLibrary.cs | 3 +-- .../Implementation/PDFLibraryService.cs | 14 ++++++++++++++ 4 files changed, 38 insertions(+), 2 deletions(-) diff --git a/RMuseum/Controllers/PDFLibraryController.cs b/RMuseum/Controllers/PDFLibraryController.cs index e80e194d..065aac78 100644 --- a/RMuseum/Controllers/PDFLibraryController.cs +++ b/RMuseum/Controllers/PDFLibraryController.cs @@ -251,6 +251,23 @@ namespace RMuseum.Controllers return BadRequest(res.ExceptionString); return Ok(); } + /// + /// import from known sources + /// + /// + /// + + [HttpPost("import")] + [Authorize(Policy = RMuseumSecurableItem.PDFLibraryEntityShortName + ":" + SecurableItem.AddOperationShortName)] + [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))] + public async Task StartImportingKnownSourceAsync([FromBody]string srcUrl) + { + var res = await _pdfService.StartImportingKnownSourceAsync(srcUrl); + if (!string.IsNullOrEmpty(res.ExceptionString)) + return BadRequest(res.ExceptionString); + return Ok(); + } /// diff --git a/RMuseum/Services/IPDFLibraryService.cs b/RMuseum/Services/IPDFLibraryService.cs index 5b74baa9..d7839ebf 100644 --- a/RMuseum/Services/IPDFLibraryService.cs +++ b/RMuseum/Services/IPDFLibraryService.cs @@ -12,6 +12,12 @@ namespace RMuseum.Services /// public interface IPDFLibraryService { + /// + /// import from known sources + /// + /// + /// + Task> StartImportingKnownSourceAsync(string srcUrl); /// /// get pdf book by id /// diff --git a/RMuseum/Services/Implementation/PDFLibraryService-Partials/PDFLibraryService-SohaLibrary.cs b/RMuseum/Services/Implementation/PDFLibraryService-Partials/PDFLibraryService-SohaLibrary.cs index 7961227f..6e92f566 100644 --- a/RMuseum/Services/Implementation/PDFLibraryService-Partials/PDFLibraryService-SohaLibrary.cs +++ b/RMuseum/Services/Implementation/PDFLibraryService-Partials/PDFLibraryService-SohaLibrary.cs @@ -15,14 +15,13 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Net.Http; -using System.Security.Policy; using System.Text.RegularExpressions; using System.Threading.Tasks; namespace RMuseum.Services.Implementation { public partial class PDFLibraryService { - public async Task> StartImportingSohaLibraryUrlAsync(string srcUrl) + private async Task> StartImportingSohaLibraryUrlAsync(string srcUrl) { try { diff --git a/RMuseum/Services/Implementation/PDFLibraryService.cs b/RMuseum/Services/Implementation/PDFLibraryService.cs index 7857d192..bd92e5dd 100644 --- a/RMuseum/Services/Implementation/PDFLibraryService.cs +++ b/RMuseum/Services/Implementation/PDFLibraryService.cs @@ -23,6 +23,20 @@ namespace RMuseum.Services.Implementation /// public partial class PDFLibraryService : IPDFLibraryService { + /// + /// import from known sources + /// + /// + /// + public async Task> StartImportingKnownSourceAsync(string srcUrl) + { + if(srcUrl.Contains("https://sohalibrary.com/")) + { + return await StartImportingSohaLibraryUrlAsync(srcUrl); + } + return new RServiceResult(false, "Unknown source url"); + + } /// /// get pdf book by id ///