#399 basic code for importing local PDF files
This commit is contained in:
parent
1c57095fab
commit
3ea7dc6f91
@ -27,7 +27,7 @@
|
||||
</PackageReference>
|
||||
<PackageReference Include="NAudio" Version="2.1.0" />
|
||||
<PackageReference Include="PDFtoImage" Version="2.2.0" />
|
||||
<PackageReference Include="RSecurityBackend" Version="1.1.7" />
|
||||
<PackageReference Include="RSecurityBackend" Version="1.1.8" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.4.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.Filters" Version="7.0.6" />
|
||||
|
||||
@ -99,7 +99,7 @@ namespace RMuseum.Services.Implementation
|
||||
{
|
||||
using (Stream imageStream = await imageResult.Content.ReadAsStreamAsync())
|
||||
{
|
||||
RServiceResult<RImage> image = await imageFileService.Add(null, imageStream, $"{beepId}.jpg", Path.Combine(configuration.GetSection("PictureFileService")["StoragePath"], "SingerImages"));
|
||||
RServiceResult<RImage> image = await imageFileService.Add(null, imageStream, $"{beepId}.jpg", Path.Combine(configuration.GetSection("PictureFileService")["StoragePath"], "SingerImages"), true);
|
||||
if (string.IsNullOrEmpty(image.ExceptionString))
|
||||
{
|
||||
image = await imageFileService.Store(image.Result);
|
||||
|
||||
@ -139,17 +139,35 @@ namespace RMuseum.Services.Implementation
|
||||
|
||||
if (pages.Count == 0)
|
||||
{
|
||||
using (RMuseumDbContext importJobUpdaterDb = new RMuseumDbContext(new DbContextOptions<RMuseumDbContext>()))
|
||||
job.EndTime = DateTime.Now;
|
||||
job.Status = ImportJobStatus.Failed;
|
||||
job.Exception = "Pages.Count == 0";
|
||||
context.Update(job);
|
||||
await context.SaveChangesAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
string pdfFilePath = Path.Combine(Path.Combine(_imageFileService.ImageStoragePath, pdfBook.StorageFolderName), pdfBook.OriginalFileName);
|
||||
|
||||
using(FileStream fs = new FileStream(pdfFilePath, FileMode.Open))
|
||||
{
|
||||
var pdfStorageResult = await _imageFileService.Add(null, fs, pdfBook.OriginalFileName, pdfBook.StorageFolderName, false);
|
||||
if(!string.IsNullOrEmpty(pdfStorageResult.ExceptionString))
|
||||
{
|
||||
job.EndTime = DateTime.Now;
|
||||
job.Status = ImportJobStatus.Failed;
|
||||
job.Exception = "Pages.Count == 0";
|
||||
importJobUpdaterDb.Update(job);
|
||||
await importJobUpdaterDb.SaveChangesAsync();
|
||||
job.Exception = $"pdfStorageResult.ExceptionString): {pdfStorageResult.ExceptionString}";
|
||||
|
||||
job.EndTime = DateTime.Now;
|
||||
context.Update(job);
|
||||
await context.SaveChangesAsync();
|
||||
return;
|
||||
}
|
||||
return;
|
||||
pdfStorageResult.Result.ContentType = "application/pdf";
|
||||
pdfBook.PDFFile = pdfStorageResult.Result;
|
||||
}
|
||||
|
||||
|
||||
await context.PDFBooks.AddAsync(pdfBook);
|
||||
await context.SaveChangesAsync();
|
||||
|
||||
@ -291,19 +309,7 @@ namespace RMuseum.Services.Implementation
|
||||
|
||||
if (page.PageNumber == 1)
|
||||
{
|
||||
RImage copy = new RImage()
|
||||
{
|
||||
OriginalFileName = picture.Result.OriginalFileName,
|
||||
ContentType = picture.Result.ContentType,
|
||||
DataTime = picture.Result.DataTime,
|
||||
FileSizeInBytes = picture.Result.FileSizeInBytes,
|
||||
FolderName = picture.Result.FolderName,
|
||||
ImageHeight = picture.Result.ImageHeight,
|
||||
ImageWidth = picture.Result.ImageWidth,
|
||||
LastModified = picture.Result.LastModified,
|
||||
StoredFileName = picture.Result.StoredFileName,
|
||||
};
|
||||
pdfBook.CoverImage = copy;
|
||||
pdfBook.CoverImage = picture.Result.DuplicateExcludingId(picture.Result);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -346,18 +352,29 @@ namespace RMuseum.Services.Implementation
|
||||
ftpClient.Config.RetryAttempts = 3;
|
||||
}
|
||||
|
||||
|
||||
|
||||
var localPDFFilePath = _imageFileService.GetImagePath(book.PDFFile).Result;
|
||||
var remotePDFFilePath = $"{Configuration.GetSection("ExternalFTPServer")["RootPath"]}/images/{book.StorageFolderName}/{Path.GetFileName(localPDFFilePath)}";
|
||||
|
||||
if (!skipUpload)
|
||||
{
|
||||
var localFilePath = _imageFileService.GetImagePath(book.CoverImage).Result;
|
||||
await jobProgressServiceEF.UpdateJob(job.Id, 0, localFilePath);
|
||||
|
||||
var remoteFilePath = $"{Configuration.GetSection("ExternalFTPServer")["RootPath"]}/images/{book.CoverImage.FolderName}/{Path.GetFileName(localFilePath)}";
|
||||
await ftpClient.UploadFile(localFilePath, remoteFilePath, createRemoteDir: true);
|
||||
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"]}/images/{book.StorageFolderName}/{Path.GetFileName(localCoverImageFilePath)}";
|
||||
|
||||
if (!skipUpload)
|
||||
{
|
||||
await jobProgressServiceEF.UpdateJob(job.Id, 0, localCoverImageFilePath);
|
||||
await ftpClient.UploadFile(localCoverImageFilePath, remoteCoverImageFilePath, createRemoteDir: true);
|
||||
}
|
||||
|
||||
book.ExternalPDFFileUrl = remotePDFFilePath;
|
||||
book.ExtenalCoverImageUrl = remoteCoverImageFilePath;
|
||||
|
||||
context.Update(book);
|
||||
|
||||
|
||||
foreach (var item in book.Pages)
|
||||
{
|
||||
@ -377,7 +394,6 @@ namespace RMuseum.Services.Implementation
|
||||
await ftpClient.Disconnect();
|
||||
}
|
||||
await jobProgressServiceEF.UpdateJob(job.Id, 100, "", true);
|
||||
await context.SaveChangesAsync();//redundant
|
||||
}
|
||||
|
||||
return new RServiceResult<bool>(true);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user