#399 bug fixes
This commit is contained in:
parent
2f04c24395
commit
786c3dba4f
@ -29,9 +29,9 @@ namespace RMuseum.Controllers
|
||||
[Authorize(Policy = RMuseumSecurableItem.PDFLibraryEntityShortName + ":" + SecurableItem.ModifyOperationShortName)]
|
||||
[ProducesResponseType((int)HttpStatusCode.OK)]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
|
||||
public IActionResult StartImportingLocalPDF([FromBody] NewPDFBookViewModel model)
|
||||
public async Task<IActionResult> StartImportingLocalPDFAsync([FromBody] NewPDFBookViewModel model)
|
||||
{
|
||||
var res = _pdfService.StartImportingLocalPDF(model);
|
||||
var res = await _pdfService.StartImportingLocalPDFAsync(model);
|
||||
if (!string.IsNullOrEmpty(res.ExceptionString))
|
||||
return BadRequest(res.ExceptionString);
|
||||
return Ok();
|
||||
|
||||
@ -2343,7 +2343,7 @@
|
||||
<param name="numberingService"></param>
|
||||
<param name="configuration"></param>
|
||||
</member>
|
||||
<member name="M:RMuseum.Controllers.PDFLibraryController.StartImportingLocalPDF(RMuseum.Models.PDFLibrary.ViewModels.NewPDFBookViewModel)">
|
||||
<member name="M:RMuseum.Controllers.PDFLibraryController.StartImportingLocalPDFAsync(RMuseum.Models.PDFLibrary.ViewModels.NewPDFBookViewModel)">
|
||||
<summary>
|
||||
start importing a local pdf file
|
||||
</summary>
|
||||
@ -17496,7 +17496,7 @@
|
||||
<param name="statusArray"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.PDFLibraryService.StartImportingLocalPDF(RMuseum.Models.PDFLibrary.ViewModels.NewPDFBookViewModel)">
|
||||
<member name="M:RMuseum.Services.Implementation.PDFLibraryService.StartImportingLocalPDFAsync(RMuseum.Models.PDFLibrary.ViewModels.NewPDFBookViewModel)">
|
||||
<summary>
|
||||
start importing local pdf file
|
||||
</summary>
|
||||
@ -18386,7 +18386,7 @@
|
||||
<param name="multiVolumePDFCollection"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.IPDFLibraryService.StartImportingLocalPDF(RMuseum.Models.PDFLibrary.ViewModels.NewPDFBookViewModel)">
|
||||
<member name="M:RMuseum.Services.IPDFLibraryService.StartImportingLocalPDFAsync(RMuseum.Models.PDFLibrary.ViewModels.NewPDFBookViewModel)">
|
||||
<summary>
|
||||
start importing local pdf file
|
||||
</summary>
|
||||
|
||||
@ -60,6 +60,6 @@ namespace RMuseum.Services
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
RServiceResult<bool> StartImportingLocalPDF(NewPDFBookViewModel model);
|
||||
Task<RServiceResult<bool>> StartImportingLocalPDFAsync(NewPDFBookViewModel model);
|
||||
}
|
||||
}
|
||||
|
||||
@ -20,43 +20,11 @@ namespace RMuseum.Services.Implementation
|
||||
{
|
||||
public partial class PDFLibraryService
|
||||
{
|
||||
private async Task<RServiceResult<PDFBook>> ImportLocalPDFFileAsync(RMuseumDbContext context, int bookId, int? volumeId, int volumeOrder, string filePath, string srcUrl, bool skipUpload)
|
||||
private async Task<RServiceResult<PDFBook>> ImportLocalPDFFileAsync(RMuseumDbContext context, int bookId, int? volumeId, int volumeOrder, string filePath, string srcUrl, bool skipUpload, string fileChecksum)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (volumeId == 0) volumeId = null;
|
||||
string fileChecksum = PoemAudio.ComputeCheckSum(filePath);
|
||||
if (
|
||||
(
|
||||
await context.ImportJobs
|
||||
.Where(j => j.JobType == JobType.Pdf && j.SrcContent == fileChecksum && !(j.Status == ImportJobStatus.Failed || j.Status == ImportJobStatus.Aborted))
|
||||
.SingleOrDefaultAsync()
|
||||
)
|
||||
!=
|
||||
null
|
||||
)
|
||||
{
|
||||
return new RServiceResult<PDFBook>(null, $"Job is already scheduled or running for importing pdf file {filePath} (duplicated checksum: {fileChecksum})");
|
||||
}
|
||||
if (!string.IsNullOrEmpty(srcUrl))
|
||||
{
|
||||
if (
|
||||
(await context.PDFBooks.Where(a => a.OriginalSourceUrl == srcUrl).SingleOrDefaultAsync())
|
||||
!=
|
||||
null
|
||||
)
|
||||
{
|
||||
return new RServiceResult<PDFBook>(null, $"duplicated srcUrl '{srcUrl}'");
|
||||
}
|
||||
}
|
||||
if (
|
||||
(await context.PDFBooks.Where(a => a.FileMD5CheckSum == fileChecksum).SingleOrDefaultAsync())
|
||||
!=
|
||||
null
|
||||
)
|
||||
{
|
||||
return new RServiceResult<PDFBook>(null, $"duplicated pdf with checksum '{fileChecksum}'");
|
||||
}
|
||||
|
||||
ImportJob job = new ImportJob()
|
||||
{
|
||||
JobType = JobType.Pdf,
|
||||
@ -73,6 +41,40 @@ namespace RMuseum.Services.Implementation
|
||||
job
|
||||
);
|
||||
await context.SaveChangesAsync();
|
||||
|
||||
if (volumeId == 0) volumeId = null;
|
||||
|
||||
|
||||
if (!string.IsNullOrEmpty(srcUrl))
|
||||
{
|
||||
if (
|
||||
(await context.PDFBooks.Where(a => a.OriginalSourceUrl == srcUrl).SingleOrDefaultAsync())
|
||||
!=
|
||||
null
|
||||
)
|
||||
{
|
||||
job.EndTime = DateTime.Now;
|
||||
job.Status = ImportJobStatus.Failed;
|
||||
job.Exception = $"duplicated srcUrl '{srcUrl}'";
|
||||
context.Update(job);
|
||||
await context.SaveChangesAsync();
|
||||
return new RServiceResult<PDFBook>(null, job.Exception);
|
||||
}
|
||||
}
|
||||
if (
|
||||
(await context.PDFBooks.Where(a => a.FileMD5CheckSum == fileChecksum).SingleOrDefaultAsync())
|
||||
!=
|
||||
null
|
||||
)
|
||||
{
|
||||
job.EndTime = DateTime.Now;
|
||||
job.Status = ImportJobStatus.Failed;
|
||||
job.Exception = $"duplicated pdf with checksum '{fileChecksum}'";
|
||||
context.Update(job);
|
||||
await context.SaveChangesAsync();
|
||||
return new RServiceResult<PDFBook>(null, job.Exception);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var folderNumber = 1 + await context.PDFBooks.CountAsync();
|
||||
@ -96,14 +98,11 @@ namespace RMuseum.Services.Implementation
|
||||
};
|
||||
job.FriendlyUrl = pdfBook.StorageFolderName;
|
||||
List<RTagValue> meta = new List<RTagValue>();
|
||||
using (RMuseumDbContext importJobUpdaterDb = new RMuseumDbContext(new DbContextOptions<RMuseumDbContext>()))
|
||||
{
|
||||
job.StartTime = DateTime.Now;
|
||||
job.Status = ImportJobStatus.Running;
|
||||
job.SrcContent = "";
|
||||
importJobUpdaterDb.Update(job);
|
||||
await importJobUpdaterDb.SaveChangesAsync();
|
||||
}
|
||||
job.StartTime = DateTime.Now;
|
||||
job.Status = ImportJobStatus.Running;
|
||||
job.SrcContent = "";
|
||||
context.Update(job);
|
||||
await context.SaveChangesAsync();
|
||||
List<PDFPage> pages = await _ImportAndReturnPDFJobImages(pdfBook, job, 0);
|
||||
pdfBook.Tags = meta.ToArray();
|
||||
pdfBook.Pages = pages.ToArray();
|
||||
@ -119,7 +118,7 @@ namespace RMuseum.Services.Implementation
|
||||
}
|
||||
using (FileStream fs = new FileStream(filePath, FileMode.Open))
|
||||
{
|
||||
var pdfStorageResult = await _imageFileService.Add(null, fs, pdfBook.OriginalFileName, pdfBook.StorageFolderName, false);
|
||||
var pdfStorageResult = await _imageFileService.Add(null, fs, pdfBook.OriginalFileName, pdfBook.StorageFolderName, false, "application/pdf");
|
||||
if (!string.IsNullOrEmpty(pdfStorageResult.ExceptionString))
|
||||
{
|
||||
job.EndTime = DateTime.Now;
|
||||
@ -130,7 +129,6 @@ namespace RMuseum.Services.Implementation
|
||||
await context.SaveChangesAsync();
|
||||
return new RServiceResult<PDFBook>(null, job.Exception);
|
||||
}
|
||||
pdfStorageResult.Result.ContentType = "application/pdf";
|
||||
pdfBook.PDFFile = pdfStorageResult.Result;
|
||||
}
|
||||
await context.PDFBooks.AddAsync(pdfBook);
|
||||
|
||||
@ -1,7 +1,9 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using ganjoor;
|
||||
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;
|
||||
@ -9,6 +11,7 @@ using RSecurityBackend.Services;
|
||||
using RSecurityBackend.Services.Implementation;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@ -51,129 +54,154 @@ namespace RMuseum.Services.Implementation
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public RServiceResult<bool> StartImportingLocalPDF(NewPDFBookViewModel model)
|
||||
public async Task<RServiceResult<bool>> StartImportingLocalPDFAsync(NewPDFBookViewModel model)
|
||||
{
|
||||
if(model == null)
|
||||
try
|
||||
{
|
||||
return new RServiceResult<bool>(false, "model == null");
|
||||
}
|
||||
_backgroundTaskQueue.QueueBackgroundWorkItem
|
||||
if (model == null)
|
||||
{
|
||||
return new RServiceResult<bool>(false, "model == null");
|
||||
}
|
||||
if (!File.Exists(model.LocalImportingPDFFilePath))
|
||||
{
|
||||
return new RServiceResult<bool>(false, $"file does not exist! : {model.LocalImportingPDFFilePath}");
|
||||
}
|
||||
string fileChecksum = PoemAudio.ComputeCheckSum(model.LocalImportingPDFFilePath);
|
||||
if (
|
||||
(
|
||||
async token =>
|
||||
{
|
||||
using (RMuseumDbContext context = new RMuseumDbContext(new DbContextOptions<RMuseumDbContext>()))
|
||||
await _context.ImportJobs
|
||||
.Where(j => j.JobType == JobType.Pdf && j.SrcContent == fileChecksum && !(j.Status == ImportJobStatus.Failed || j.Status == ImportJobStatus.Aborted))
|
||||
.SingleOrDefaultAsync()
|
||||
)
|
||||
!=
|
||||
null
|
||||
)
|
||||
{
|
||||
return new RServiceResult<bool>(false, $"Job is already scheduled or running for importing pdf file {model.LocalImportingPDFFilePath} (duplicated checksum: {fileChecksum})");
|
||||
}
|
||||
_backgroundTaskQueue.QueueBackgroundWorkItem
|
||||
(
|
||||
async token =>
|
||||
{
|
||||
var pdfRes = await ImportLocalPDFFileAsync(context, model.BookId, model.MultiVolumePDFCollectionId, model.VolumeOrder, model.LocalImportingPDFFilePath, model.OriginalSourceUrl, model.SkipUpload);
|
||||
if (pdfRes.Result != null)
|
||||
using (RMuseumDbContext context = new RMuseumDbContext(new DbContextOptions<RMuseumDbContext>()))
|
||||
{
|
||||
var pdfBook = pdfRes.Result;
|
||||
pdfBook.Title = model.Title;
|
||||
pdfBook.SubTitle = model.SubTitle;
|
||||
pdfBook.AuthorsLine = model.AuthorsLine;
|
||||
pdfBook.ISBN = model.ISBN;
|
||||
pdfBook.Description = model.Description;
|
||||
pdfBook.IsTranslation = model.IsTranslation;
|
||||
pdfBook.TranslatorsLine = model.TranslatorsLine;
|
||||
pdfBook.TitleInOriginalLanguage = model.TitleInOriginalLanguage;
|
||||
pdfBook.PublisherLine = model.PublisherLine;
|
||||
pdfBook.PublishingDate = model.PublishingDate;
|
||||
pdfBook.PublishingLocation = model.PublishingLocation;
|
||||
pdfBook.PublishingNumber = model.PublishingNumber == 0 ? null : model.PublishingNumber;
|
||||
pdfBook.ClaimedPageCount = model.ClaimedPageCount == 0 ? null : model.ClaimedPageCount;
|
||||
pdfBook.OriginalSourceName = model.OriginalSourceName;
|
||||
pdfBook.OriginalFileUrl = model.OriginalFileUrl;
|
||||
List<AuthorRole> roles = new List<AuthorRole>();
|
||||
if (model.WriterId != null && model.WriterId != 0)
|
||||
var pdfRes = await ImportLocalPDFFileAsync(context, model.BookId, model.MultiVolumePDFCollectionId, model.VolumeOrder, model.LocalImportingPDFFilePath, model.OriginalSourceUrl, model.SkipUpload, fileChecksum);
|
||||
if (pdfRes.Result != null)
|
||||
{
|
||||
roles.Add(new AuthorRole()
|
||||
var pdfBook = pdfRes.Result;
|
||||
pdfBook.Title = model.Title;
|
||||
pdfBook.SubTitle = model.SubTitle;
|
||||
pdfBook.AuthorsLine = model.AuthorsLine;
|
||||
pdfBook.ISBN = model.ISBN;
|
||||
pdfBook.Description = model.Description;
|
||||
pdfBook.IsTranslation = model.IsTranslation;
|
||||
pdfBook.TranslatorsLine = model.TranslatorsLine;
|
||||
pdfBook.TitleInOriginalLanguage = model.TitleInOriginalLanguage;
|
||||
pdfBook.PublisherLine = model.PublisherLine;
|
||||
pdfBook.PublishingDate = model.PublishingDate;
|
||||
pdfBook.PublishingLocation = model.PublishingLocation;
|
||||
pdfBook.PublishingNumber = model.PublishingNumber == 0 ? null : model.PublishingNumber;
|
||||
pdfBook.ClaimedPageCount = model.ClaimedPageCount == 0 ? null : model.ClaimedPageCount;
|
||||
pdfBook.OriginalSourceName = model.OriginalSourceName;
|
||||
pdfBook.OriginalFileUrl = model.OriginalFileUrl;
|
||||
List<AuthorRole> roles = new List<AuthorRole>();
|
||||
if (model.WriterId != null && model.WriterId != 0)
|
||||
{
|
||||
Author = await context.Authors.Where(a => a.Id == model.WriterId).SingleAsync(),
|
||||
Role = "نویسنده",
|
||||
});
|
||||
}
|
||||
if (model.Writer2Id != null && model.Writer2Id != 0)
|
||||
{
|
||||
roles.Add(new AuthorRole()
|
||||
roles.Add(new AuthorRole()
|
||||
{
|
||||
Author = await context.Authors.Where(a => a.Id == model.WriterId).SingleAsync(),
|
||||
Role = "نویسنده",
|
||||
});
|
||||
}
|
||||
if (model.Writer2Id != null && model.Writer2Id != 0)
|
||||
{
|
||||
Author = await context.Authors.Where(a => a.Id == model.Writer2Id).SingleAsync(),
|
||||
Role = "نویسنده",
|
||||
});
|
||||
}
|
||||
if (model.Writer3Id != null && model.Writer3Id != 0)
|
||||
{
|
||||
roles.Add(new AuthorRole()
|
||||
roles.Add(new AuthorRole()
|
||||
{
|
||||
Author = await context.Authors.Where(a => a.Id == model.Writer2Id).SingleAsync(),
|
||||
Role = "نویسنده",
|
||||
});
|
||||
}
|
||||
if (model.Writer3Id != null && model.Writer3Id != 0)
|
||||
{
|
||||
Author = await context.Authors.Where(a => a.Id == model.Writer3Id).SingleAsync(),
|
||||
Role = "نویسنده",
|
||||
});
|
||||
}
|
||||
if (model.Writer4Id != null && model.Writer4Id != 0)
|
||||
{
|
||||
roles.Add(new AuthorRole()
|
||||
roles.Add(new AuthorRole()
|
||||
{
|
||||
Author = await context.Authors.Where(a => a.Id == model.Writer3Id).SingleAsync(),
|
||||
Role = "نویسنده",
|
||||
});
|
||||
}
|
||||
if (model.Writer4Id != null && model.Writer4Id != 0)
|
||||
{
|
||||
Author = await context.Authors.Where(a => a.Id == model.Writer4Id).SingleAsync(),
|
||||
Role = "نویسنده",
|
||||
});
|
||||
}
|
||||
if (model.TranslatorId != null && model.TranslatorId != 0)
|
||||
{
|
||||
roles.Add(new AuthorRole()
|
||||
roles.Add(new AuthorRole()
|
||||
{
|
||||
Author = await context.Authors.Where(a => a.Id == model.Writer4Id).SingleAsync(),
|
||||
Role = "نویسنده",
|
||||
});
|
||||
}
|
||||
if (model.TranslatorId != null && model.TranslatorId != 0)
|
||||
{
|
||||
Author = await context.Authors.Where(a => a.Id == model.TranslatorId).SingleAsync(),
|
||||
Role = "مترجم",
|
||||
});
|
||||
}
|
||||
if (model.Translator2Id != null && model.Translator2Id != 0)
|
||||
{
|
||||
roles.Add(new AuthorRole()
|
||||
roles.Add(new AuthorRole()
|
||||
{
|
||||
Author = await context.Authors.Where(a => a.Id == model.TranslatorId).SingleAsync(),
|
||||
Role = "مترجم",
|
||||
});
|
||||
}
|
||||
if (model.Translator2Id != null && model.Translator2Id != 0)
|
||||
{
|
||||
Author = await context.Authors.Where(a => a.Id == model.Translator2Id).SingleAsync(),
|
||||
Role = "مترجم",
|
||||
});
|
||||
}
|
||||
if (model.Translator3Id != null && model.Translator3Id != 0)
|
||||
{
|
||||
roles.Add(new AuthorRole()
|
||||
roles.Add(new AuthorRole()
|
||||
{
|
||||
Author = await context.Authors.Where(a => a.Id == model.Translator2Id).SingleAsync(),
|
||||
Role = "مترجم",
|
||||
});
|
||||
}
|
||||
if (model.Translator3Id != null && model.Translator3Id != 0)
|
||||
{
|
||||
Author = await context.Authors.Where(a => a.Id == model.Translator3Id).SingleAsync(),
|
||||
Role = "مترجم",
|
||||
});
|
||||
}
|
||||
if (model.Translator4Id != null && model.Translator4Id != 0)
|
||||
{
|
||||
roles.Add(new AuthorRole()
|
||||
roles.Add(new AuthorRole()
|
||||
{
|
||||
Author = await context.Authors.Where(a => a.Id == model.Translator3Id).SingleAsync(),
|
||||
Role = "مترجم",
|
||||
});
|
||||
}
|
||||
if (model.Translator4Id != null && model.Translator4Id != 0)
|
||||
{
|
||||
Author = await context.Authors.Where(a => a.Id == model.Translator4Id).SingleAsync(),
|
||||
Role = "مترجم",
|
||||
});
|
||||
}
|
||||
if (model.CollectorId != null && model.CollectorId != 0)
|
||||
{
|
||||
roles.Add(new AuthorRole()
|
||||
roles.Add(new AuthorRole()
|
||||
{
|
||||
Author = await context.Authors.Where(a => a.Id == model.Translator4Id).SingleAsync(),
|
||||
Role = "مترجم",
|
||||
});
|
||||
}
|
||||
if (model.CollectorId != null && model.CollectorId != 0)
|
||||
{
|
||||
Author = await context.Authors.Where(a => a.Id == model.CollectorId).SingleAsync(),
|
||||
Role = "مصحح",
|
||||
});
|
||||
}
|
||||
if (model.Collector2Id != null && model.Collector2Id != 0)
|
||||
{
|
||||
roles.Add(new AuthorRole()
|
||||
roles.Add(new AuthorRole()
|
||||
{
|
||||
Author = await context.Authors.Where(a => a.Id == model.CollectorId).SingleAsync(),
|
||||
Role = "مصحح",
|
||||
});
|
||||
}
|
||||
if (model.Collector2Id != null && model.Collector2Id != 0)
|
||||
{
|
||||
Author = await context.Authors.Where(a => a.Id == model.Collector2Id).SingleAsync(),
|
||||
Role = "مصحح",
|
||||
});
|
||||
roles.Add(new AuthorRole()
|
||||
{
|
||||
Author = await context.Authors.Where(a => a.Id == model.Collector2Id).SingleAsync(),
|
||||
Role = "مصحح",
|
||||
});
|
||||
}
|
||||
if (roles.Count > 0)
|
||||
{
|
||||
pdfBook.Contributers = roles;
|
||||
}
|
||||
context.Update(pdfBook);
|
||||
await context.SaveChangesAsync();
|
||||
}
|
||||
if (roles.Count > 0)
|
||||
{
|
||||
pdfBook.Contributers = roles;
|
||||
}
|
||||
context.Update(pdfBook);
|
||||
await context.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
return new RServiceResult<bool>(true);
|
||||
);
|
||||
return new RServiceResult<bool>(true);
|
||||
}
|
||||
catch (Exception exp)
|
||||
{
|
||||
return new RServiceResult<bool>(false, exp.ToString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user