#403 using ftp service in pdf service
This commit is contained in:
parent
4f605bd3fe
commit
e75e6b5200
@ -18293,12 +18293,17 @@
|
||||
image file service
|
||||
</summary>
|
||||
</member>
|
||||
<member name="F:RMuseum.Services.Implementation.PDFLibraryService._ftpService">
|
||||
<summary>
|
||||
ftp service
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:RMuseum.Services.Implementation.PDFLibraryService.Configuration">
|
||||
<summary>
|
||||
Configuration
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.PDFLibraryService.#ctor(RMuseum.DbContext.RMuseumDbContext,RSecurityBackend.Services.IBackgroundTaskQueue,RSecurityBackend.Services.IImageFileService,Microsoft.Extensions.Configuration.IConfiguration)">
|
||||
<member name="M:RMuseum.Services.Implementation.PDFLibraryService.#ctor(RMuseum.DbContext.RMuseumDbContext,RSecurityBackend.Services.IBackgroundTaskQueue,RSecurityBackend.Services.IImageFileService,Microsoft.Extensions.Configuration.IConfiguration,RMuseum.Services.IQueuedFTPUploadService)">
|
||||
<summary>
|
||||
constructor
|
||||
</summary>
|
||||
@ -18306,6 +18311,7 @@
|
||||
<param name="backgroundTaskQueue"></param>
|
||||
<param name="imageFileService"></param>
|
||||
<param name="configuration"></param>
|
||||
<param name="ftpService"></param>
|
||||
</member>
|
||||
<member name="T:RMuseum.Services.Implementation.PictureFileService">
|
||||
<summary>
|
||||
|
||||
@ -1,6 +1,4 @@
|
||||
using FluentFTP;
|
||||
using FluentFTP.Client.BaseClient;
|
||||
using ganjoor;
|
||||
using ganjoor;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using RMuseum.DbContext;
|
||||
using RMuseum.Models.Artifact;
|
||||
@ -461,55 +459,43 @@ namespace RMuseum.Services.Implementation
|
||||
var job = (await jobProgressServiceEF.NewJob("_UploadArtifactToExternalServer", $"Uploading {book.StorageFolderName}")).Result;
|
||||
try
|
||||
{
|
||||
if (bool.Parse(Configuration.GetSection("ExternalFTPServer")["UploadEnabled"]))
|
||||
var localPDFFilePath = _imageFileService.GetImagePath(book.PDFFile).Result;
|
||||
var remotePDFFilePath = $"{Configuration.GetSection("ExternalFTPServer")["RootPath"]}/pdf/{book.StorageFolderName}/{Path.GetFileName(localPDFFilePath)}";
|
||||
if (!skipUpload)
|
||||
{
|
||||
var ftpClient = new AsyncFtpClient
|
||||
(
|
||||
Configuration.GetSection("ExternalFTPServer")["Host"],
|
||||
Configuration.GetSection("ExternalFTPServer")["Username"],
|
||||
Configuration.GetSection("ExternalFTPServer")["Password"]
|
||||
);
|
||||
if (!skipUpload)
|
||||
{
|
||||
ftpClient.ValidateCertificate += FtpClient_ValidateCertificate;
|
||||
await ftpClient.AutoConnect();
|
||||
ftpClient.Config.RetryAttempts = 3;
|
||||
}
|
||||
var localPDFFilePath = _imageFileService.GetImagePath(book.PDFFile).Result;
|
||||
var remotePDFFilePath = $"{Configuration.GetSection("ExternalFTPServer")["RootPath"]}/pdf/{book.StorageFolderName}/{Path.GetFileName(localPDFFilePath)}";
|
||||
if (!skipUpload)
|
||||
{
|
||||
await jobProgressServiceEF.UpdateJob(job.Id, 0, localPDFFilePath);
|
||||
await ftpClient.UploadFile(localPDFFilePath, remotePDFFilePath, createRemoteDir: true);
|
||||
}
|
||||
var localCoverImageFilePath = _imageFileService.GetImagePath(book.CoverImage).Result;
|
||||
var remoteCoverImageFilePath = $"{Configuration.GetSection("ExternalFTPServer")["RootPath"]}/pdf/{book.StorageFolderName}/{Path.GetFileName(localCoverImageFilePath)}";
|
||||
if (!skipUpload)
|
||||
{
|
||||
await jobProgressServiceEF.UpdateJob(job.Id, 0, localCoverImageFilePath);
|
||||
await ftpClient.UploadFile(localCoverImageFilePath, remoteCoverImageFilePath, createRemoteDir: true);
|
||||
}
|
||||
book.ExternalPDFFileUrl = $"{Configuration.GetSection("ExternalFTPServer")["RootUrl"]}/pdf/{book.StorageFolderName}/{Path.GetFileName(localPDFFilePath)}";
|
||||
book.ExtenalCoverImageUrl = $"{Configuration.GetSection("ExternalFTPServer")["RootUrl"]}/pdf/{book.StorageFolderName}/{Path.GetFileName(localCoverImageFilePath)}";
|
||||
context.Update(book);
|
||||
foreach (var item in book.Pages)
|
||||
{
|
||||
var localFilePath = _imageFileService.GetImagePath(item.ThumbnailImage).Result;
|
||||
item.ExtenalThumbnailImageUrl = $"{Configuration.GetSection("ExternalFTPServer")["RootUrl"]}/pdf/{book.StorageFolderName}/{Path.GetFileName(localFilePath)}";
|
||||
context.Update(item);
|
||||
if (!skipUpload)
|
||||
{
|
||||
await jobProgressServiceEF.UpdateJob(job.Id, 0, localFilePath);
|
||||
var remoteFilePath = $"{Configuration.GetSection("ExternalFTPServer")["RootPath"]}/pdf/{book.CoverImage.FolderName}/{Path.GetFileName(localFilePath)}";
|
||||
await ftpClient.UploadFile(localFilePath, remoteFilePath, createRemoteDir: true);
|
||||
}
|
||||
}
|
||||
if (!skipUpload)
|
||||
{
|
||||
await ftpClient.Disconnect();
|
||||
}
|
||||
await jobProgressServiceEF.UpdateJob(job.Id, 100, "", true);
|
||||
await jobProgressServiceEF.UpdateJob(job.Id, 0, $"{localPDFFilePath} => {remotePDFFilePath}");
|
||||
await _ftpService.AddAsync(localPDFFilePath, remotePDFFilePath, true);
|
||||
}
|
||||
var localCoverImageFilePath = _imageFileService.GetImagePath(book.CoverImage).Result;
|
||||
var remoteCoverImageFilePath = $"{Configuration.GetSection("ExternalFTPServer")["RootPath"]}/pdf/{book.StorageFolderName}/{Path.GetFileName(localCoverImageFilePath)}";
|
||||
if (!skipUpload)
|
||||
{
|
||||
await jobProgressServiceEF.UpdateJob(job.Id, 0, $"{localCoverImageFilePath} => {remoteCoverImageFilePath}");
|
||||
await _ftpService.AddAsync(localCoverImageFilePath, remoteCoverImageFilePath, true);
|
||||
}
|
||||
book.ExternalPDFFileUrl = $"{Configuration.GetSection("ExternalFTPServer")["RootUrl"]}/pdf/{book.StorageFolderName}/{Path.GetFileName(localPDFFilePath)}";
|
||||
book.ExtenalCoverImageUrl = $"{Configuration.GetSection("ExternalFTPServer")["RootUrl"]}/pdf/{book.StorageFolderName}/{Path.GetFileName(localCoverImageFilePath)}";
|
||||
context.Update(book);
|
||||
foreach (var item in book.Pages)
|
||||
{
|
||||
var localFilePath = _imageFileService.GetImagePath(item.ThumbnailImage).Result;
|
||||
item.ExtenalThumbnailImageUrl = $"{Configuration.GetSection("ExternalFTPServer")["RootUrl"]}/pdf/{book.StorageFolderName}/{Path.GetFileName(localFilePath)}";
|
||||
context.Update(item);
|
||||
if (!skipUpload)
|
||||
{
|
||||
var remoteFilePath = $"{Configuration.GetSection("ExternalFTPServer")["RootPath"]}/pdf/{book.CoverImage.FolderName}/{Path.GetFileName(localFilePath)}";
|
||||
await jobProgressServiceEF.UpdateJob(job.Id, 0, $"{localFilePath} => {remoteFilePath}");
|
||||
await _ftpService.AddAsync(localFilePath, remoteFilePath, true);
|
||||
}
|
||||
}
|
||||
if (!skipUpload)
|
||||
{
|
||||
if(false == await context.QueuedFTPUploads.AsNoTracking().Where(p => p.Processing).AnyAsync())
|
||||
{
|
||||
await _ftpService.ProcessQueueAsync();
|
||||
}
|
||||
}
|
||||
await jobProgressServiceEF.UpdateJob(job.Id, 100, "", true);
|
||||
return new RServiceResult<bool>(true);
|
||||
}
|
||||
catch (Exception exp)
|
||||
@ -518,10 +504,6 @@ namespace RMuseum.Services.Implementation
|
||||
return new RServiceResult<bool>(false, exp.ToString());
|
||||
}
|
||||
}
|
||||
private void FtpClient_ValidateCertificate(BaseFtpClient control, FtpSslValidationEventArgs e)
|
||||
{
|
||||
e.Accept = true;
|
||||
}
|
||||
/// <summary>
|
||||
/// عرض تصویر بندانگشتی
|
||||
/// </summary>
|
||||
|
||||
@ -103,7 +103,7 @@ namespace RMuseum.Services.Implementation
|
||||
model.OriginalSourceUrl = srcUrl;
|
||||
model.BookScriptType = BookScriptType.Printed;
|
||||
model.Language = "فارسی";
|
||||
model.SkipUpload = true;
|
||||
model.SkipUpload = false;
|
||||
|
||||
string html = "";
|
||||
using (var client = new HttpClient())
|
||||
|
||||
@ -1,9 +1,7 @@
|
||||
using ganjoor;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using RMuseum.DbContext;
|
||||
using RMuseum.Models.Artifact;
|
||||
using RMuseum.Models.ImportJob;
|
||||
using RMuseum.Models.PDFLibrary;
|
||||
using RMuseum.Models.PDFLibrary.ViewModels;
|
||||
using RSecurityBackend.Models.Generic;
|
||||
@ -1256,6 +1254,10 @@ namespace RMuseum.Services.Implementation
|
||||
/// </summary>
|
||||
protected readonly IImageFileService _imageFileService;
|
||||
/// <summary>
|
||||
/// ftp service
|
||||
/// </summary>
|
||||
protected readonly IQueuedFTPUploadService _ftpService;
|
||||
/// <summary>
|
||||
/// Configuration
|
||||
/// </summary>
|
||||
protected IConfiguration Configuration { get; }
|
||||
@ -1266,12 +1268,14 @@ namespace RMuseum.Services.Implementation
|
||||
/// <param name="backgroundTaskQueue"></param>
|
||||
/// <param name="imageFileService"></param>
|
||||
/// <param name="configuration"></param>
|
||||
public PDFLibraryService(RMuseumDbContext context, IBackgroundTaskQueue backgroundTaskQueue, IImageFileService imageFileService, IConfiguration configuration)
|
||||
/// <param name="ftpService"></param>
|
||||
public PDFLibraryService(RMuseumDbContext context, IBackgroundTaskQueue backgroundTaskQueue, IImageFileService imageFileService, IConfiguration configuration, IQueuedFTPUploadService ftpService)
|
||||
{
|
||||
_context = context;
|
||||
_backgroundTaskQueue = backgroundTaskQueue;
|
||||
_imageFileService = imageFileService;
|
||||
Configuration = configuration;
|
||||
_ftpService = ftpService;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user