docs: #379 generate missing book covers
This commit is contained in:
parent
a23bfc51e7
commit
b1483bc3c6
@ -513,6 +513,24 @@ namespace RMuseum.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// generate missing book covers
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPut("generatemissingbookcovers")]
|
||||
[Authorize(Policy = RMuseumSecurableItem.GanjoorEntityShortName + ":" + SecurableItem.ModifyOperationShortName)]
|
||||
[ProducesResponseType((int)HttpStatusCode.OK)]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
|
||||
[ProducesResponseType((int)HttpStatusCode.Unauthorized)]
|
||||
[ProducesResponseType((int)HttpStatusCode.Forbidden, Type = typeof(string))]
|
||||
public async Task<IActionResult> GenerateMissingBookCoversAsync()
|
||||
{
|
||||
var res = await _ganjoorService.GenerateMissingBookCoversAsync();
|
||||
if(!string.IsNullOrEmpty(res.ExceptionString))
|
||||
return BadRequest(res.ExceptionString);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// list of books
|
||||
/// </summary>
|
||||
|
||||
@ -996,6 +996,12 @@
|
||||
<param name="id"></param>
|
||||
<returns>only RImageId field is valid</returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Controllers.GanjoorController.GenerateMissingBookCoversAsync">
|
||||
<summary>
|
||||
generate missing book covers
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Controllers.GanjoorController.GetBooksAsync">
|
||||
<summary>
|
||||
list of books
|
||||
@ -12532,6 +12538,12 @@
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.IGanjoorService.GenerateMissingBookCoversAsync">
|
||||
<summary>
|
||||
generate missing book covers
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.IGanjoorService.GetPageByUrl(System.String,System.Boolean)">
|
||||
<summary>
|
||||
get page by url
|
||||
@ -15724,6 +15736,12 @@
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.GanjoorService.GenerateMissingBookCoversAsync">
|
||||
<summary>
|
||||
generate missing book covers
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.GanjoorService.GetCatById(System.Int32,System.Boolean,System.Boolean)">
|
||||
<summary>
|
||||
get cat by id
|
||||
|
||||
@ -79,6 +79,12 @@ namespace RMuseum.Services
|
||||
/// <returns></returns>
|
||||
Task<RServiceResult<GanjoorCatViewModel[]>> GetBooksAsync();
|
||||
|
||||
/// <summary>
|
||||
/// generate missing book covers
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task<RServiceResult<bool>> GenerateMissingBookCoversAsync();
|
||||
|
||||
/// <summary>
|
||||
/// get page by url
|
||||
/// </summary>
|
||||
|
||||
@ -24,6 +24,10 @@ using RMuseum.Models.Auth.Memory;
|
||||
using System.IO;
|
||||
using RSecurityBackend.Models.Image;
|
||||
using FluentFTP;
|
||||
using NAudio.Gui;
|
||||
using System.Drawing;
|
||||
using static System.Net.Mime.MediaTypeNames;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
|
||||
namespace RMuseum.Services.Implementation
|
||||
{
|
||||
@ -273,6 +277,58 @@ namespace RMuseum.Services.Implementation
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// generate missing book covers
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<RServiceResult<bool>> GenerateMissingBookCoversAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
var books = await _context.GanjoorCategories.Where(c => !string.IsNullOrEmpty(c.BookName) && c.RImageId == null).ToListAsync();
|
||||
foreach (var book in books)
|
||||
{
|
||||
using (System.Drawing.Image coverImg = System.Drawing.Image.FromFile(Configuration.GetSection("Ganjoor")["BooksCoverTemplate"]))
|
||||
{
|
||||
using (Graphics g = Graphics.FromImage(coverImg))
|
||||
{
|
||||
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
|
||||
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
|
||||
using(Font font = new Font(Configuration.GetSection("Ganjoor")["BooksCoverTitleFontName"], float.Parse(Configuration.GetSection("Ganjoor")["BooksCoverTitleFontSize"])))
|
||||
{
|
||||
SizeF sz = g.MeasureString(book.BookName, font);
|
||||
using (SolidBrush brsh = new SolidBrush(Color.FromArgb(51, 0, 0)))
|
||||
g.DrawString(book.BookName, font, brsh, new PointF(200.0f - sz.Width / 2, 230.0f - sz.Height / 2));
|
||||
}
|
||||
|
||||
}
|
||||
MemoryStream coverData = new MemoryStream();
|
||||
coverImg.Save(coverData, System.Drawing.Imaging.ImageFormat.Png);
|
||||
RServiceResult<RImage> imageRes = await _imageFileService.Add(null, coverData, $"Book-{book.Id}", Path.Combine(Configuration.GetSection("PictureFileService")["StoragePath"], "CategoryImages"));
|
||||
if(!string.IsNullOrEmpty(imageRes.ExceptionString))
|
||||
{
|
||||
return new RServiceResult<bool>(false, imageRes.ExceptionString);
|
||||
}
|
||||
imageRes = await _imageFileService.Store(imageRes.Result);
|
||||
if (!string.IsNullOrEmpty(imageRes.ExceptionString))
|
||||
{
|
||||
return new RServiceResult<bool>(false, imageRes.ExceptionString);
|
||||
}
|
||||
var finalRes = await SetCategoryExtraInfo(book.Id, book.BookName, imageRes.Result.Id, book.SumUpSubsGeoLocations, book.MapName);
|
||||
if(!string.IsNullOrEmpty(finalRes.ExceptionString))
|
||||
{
|
||||
return new RServiceResult<bool>(false, finalRes.ExceptionString);
|
||||
}
|
||||
}
|
||||
}
|
||||
return new RServiceResult<bool>(true);
|
||||
}
|
||||
catch (Exception exp)
|
||||
{
|
||||
return new RServiceResult<bool>(false, exp.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// get cat by id
|
||||
/// </summary>
|
||||
|
||||
@ -62,7 +62,10 @@
|
||||
"GDBStorage": "D:\\My Documents\\My Web Design\\ganjoor\\www\\i\\android\\sgdb",
|
||||
"GDBStorageImageSource": "D:\\My Documents\\My Web Design\\ganjoor\\www\\i\\android\\img",
|
||||
"GDBListXMLFile": "D:\\My Documents\\My Web Design\\ganjoor\\www\\i\\android\\sitepoets.xml",
|
||||
"GDBPreExisitingListXMLFile": "D:\\My Documents\\My Web Design\\ganjoor\\www\\i\\android\\programpoets.xml"
|
||||
"GDBPreExisitingListXMLFile": "D:\\My Documents\\My Web Design\\ganjoor\\www\\i\\android\\programpoets.xml",
|
||||
"BooksCoverTemplate": "C:\\inetpub\\epub\\res\\cover-image.png",
|
||||
"BooksCoverTitleFontName": "IranNastaliq",
|
||||
"BooksCoverTitleFontSize": "40"
|
||||
},
|
||||
"ExternalFTPServer": {
|
||||
"Host": "localhost",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user