diff --git a/src/Inshapardaz.Api/Views/ChughtaiDownloadView.cs b/src/Inshapardaz.Api/Views/ChughtaiDownloadView.cs index 2145fc51..62599b37 100644 --- a/src/Inshapardaz.Api/Views/ChughtaiDownloadView.cs +++ b/src/Inshapardaz.Api/Views/ChughtaiDownloadView.cs @@ -6,7 +6,6 @@ public class ChughtaiDownloadView { [Required] public string BookUrl { get; set; } - [Required] public string SessionId { get; set; } public bool ConvertToPdf { get; set; } } diff --git a/src/Inshapardaz.Api/appsettings.Development.json b/src/Inshapardaz.Api/appsettings.Development.json deleted file mode 100644 index 357cd422..00000000 --- a/src/Inshapardaz.Api/appsettings.Development.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Debug", - "System": "Information", - "Microsoft": "Information", - "Microsoft.Hosting.Lifetime": "Information", - "Paramore": "Error" - } - } -} diff --git a/src/Inshapardaz.Api/appsettings.json b/src/Inshapardaz.Api/appsettings.json index 7080386a..219162c2 100644 --- a/src/Inshapardaz.Api/appsettings.json +++ b/src/Inshapardaz.Api/appsettings.json @@ -36,6 +36,6 @@ }, "FrontEndUrl": "", "Allowed_Origins": "", - "DefaultLibraryId" : 7 + "DefaultLibraryId" : 1 } } diff --git a/src/Inshapardaz.Domain/Adapters/Configuration/Settings.cs b/src/Inshapardaz.Domain/Adapters/Configuration/Settings.cs index 2c58bc04..6adced87 100644 --- a/src/Inshapardaz.Domain/Adapters/Configuration/Settings.cs +++ b/src/Inshapardaz.Domain/Adapters/Configuration/Settings.cs @@ -15,4 +15,6 @@ public record Settings public string FrontEndUrl { get; init; } public int DefaultLibraryId { get; init; } + + public bool SaveDownloadsToStorage { get; init; } = false; } diff --git a/src/Inshapardaz.Domain/Inshapardaz.Domain.csproj b/src/Inshapardaz.Domain/Inshapardaz.Domain.csproj index 0f6385dd..b5a4af9c 100644 --- a/src/Inshapardaz.Domain/Inshapardaz.Domain.csproj +++ b/src/Inshapardaz.Domain/Inshapardaz.Domain.csproj @@ -12,7 +12,7 @@ - + diff --git a/src/Inshapardaz.Domain/Ports/Command/Tools/DownloadChughtaiBookRequest.cs b/src/Inshapardaz.Domain/Ports/Command/Tools/DownloadChughtaiBookRequest.cs index 4f9df036..4e42d965 100644 --- a/src/Inshapardaz.Domain/Ports/Command/Tools/DownloadChughtaiBookRequest.cs +++ b/src/Inshapardaz.Domain/Ports/Command/Tools/DownloadChughtaiBookRequest.cs @@ -165,19 +165,22 @@ private async Task DownloadBook(BookModel book, DownloadChughtaiBookRequest comm { var exporter = new Chughtai.Downloader.BookDownloader(_logger); var path = $"../data/downloads/{Guid.NewGuid():D}"; - var filePath = await exporter.DownloadBook(command.Url, 10, command.SessionId, command.CreatePdf ? OutputType.Pdf : OutputType.Images, path, cancellationToken); + string filePath = null; + if (string.IsNullOrWhiteSpace(command.SessionId)) + { + filePath = await exporter.Download(command.Url, 10, command.CreatePdf ? OutputType.Pdf : OutputType.Images, path, cancellationToken); + } + else + { + filePath = await exporter.DownloadBook(command.Url, 10, command.SessionId, command.CreatePdf ? OutputType.Pdf : OutputType.Images, path, cancellationToken); + } + var bookInfo = await exporter.GetBookInformation(command.Url, cancellationToken); try { - if (book == null) - { - book = await CreateNewBook(bookInfo, command.Url, cancellationToken); - } - var result = new DownloadChughtaiBookRequest.Result { - FileName = Path.GetFileName(filePath), MimeType = command.CreatePdf ? MimeTypes.Pdf : MimeTypes.Zip }; @@ -185,8 +188,6 @@ private async Task DownloadBook(BookModel book, DownloadChughtaiBookRequest comm if (command.CreatePdf) { result.File = await System.IO.File.ReadAllBytesAsync(filePath, cancellationToken); - - await SaveBookPdfContents(book, filePath, result.File, cancellationToken); } else { @@ -202,11 +203,26 @@ private async Task DownloadBook(BookModel book, DownloadChughtaiBookRequest comm { zipFilePath.TryDeleteFile(); } - - await SaveBookPages(book, filePath, cancellationToken); } command.DownloadResult = result; + + if (_settings.SaveDownloadsToStorage) + { + if (book == null) + { + book = await CreateNewBook(bookInfo, command.Url, cancellationToken); + } + + if (command.CreatePdf) + { + await SaveBookPdfContents(book, filePath, result.File, cancellationToken); + } + else + { + await SaveBookPages(book, filePath, cancellationToken); + } + } } finally { diff --git a/src/Inshapardaz.Domain/Ports/Command/Tools/DownloadRekhtaBookRequest.cs b/src/Inshapardaz.Domain/Ports/Command/Tools/DownloadRekhtaBookRequest.cs index af7b1933..e27e3413 100644 --- a/src/Inshapardaz.Domain/Ports/Command/Tools/DownloadRekhtaBookRequest.cs +++ b/src/Inshapardaz.Domain/Ports/Command/Tools/DownloadRekhtaBookRequest.cs @@ -170,11 +170,6 @@ private async Task DownloadBook(BookModel book, DownloadRekhtaBookRequest comman try { - if (book == null) - { - book = await CreateNewBook(bookInfo, command.Url, cancellationToken); - } - var result = new DownloadRekhtaBookRequest.Result() { @@ -185,8 +180,6 @@ private async Task DownloadBook(BookModel book, DownloadRekhtaBookRequest comman if (command.CreatePdf) { result.File = await System.IO.File.ReadAllBytesAsync(filePath, cancellationToken); - - await SaveBookPdfContents(book, filePath, result.File, cancellationToken); } else { @@ -202,11 +195,27 @@ private async Task DownloadBook(BookModel book, DownloadRekhtaBookRequest comman { zipFilePath.TryDeleteFile(); } - - await SaveBookPages(book, filePath, cancellationToken); } command.DownloadResult = result; + + + if (_settings.SaveDownloadsToStorage) + { + if (book == null) + { + book = await CreateNewBook(bookInfo, command.Url, cancellationToken); + } + + if (command.CreatePdf) + { + await SaveBookPdfContents(book, filePath, result.File, cancellationToken); + } + else + { + await SaveBookPages(book, filePath, cancellationToken); + } + } } finally {