#262 loop for converting images added

This commit is contained in:
Hamid Reza Mohammadi 2021-12-17 12:12:49 +03:30
parent 5da8dda866
commit d3f14c7402

View File

@ -3,6 +3,7 @@ using RMuseum.DbContext;
using RSecurityBackend.Models.Generic;
using RSecurityBackend.Services.Implementation;
using System;
using System.IO;
namespace RMuseum.Services.Implementation
{
@ -28,6 +29,36 @@ namespace RMuseum.Services.Implementation
var job = (await jobProgressServiceEF.NewJob($"Converting Original Images To Webp", "Query data")).Result;
try
{
string imageStoragePath = $"{Configuration.GetSection("PictureFileService")["StoragePath"]}";
var artifacts = await context.Artifacts.Include(a => a.Items).ThenInclude(i => i.Images).AsNoTracking().ToArrayAsync();
int artifactNum = 0;
foreach (var artifact in artifacts)
{
await jobProgressServiceEF.UpdateJob(job.Id, ++artifactNum, $"from {artifact.ItemCount} processing {artifact.Name}");
foreach (var item in artifact.Items)
{
foreach (var image in item.Images)
{
if(image.ContentType == "image/jpeg")
{
var imagePath = Path.Combine(imageStoragePath, image.FolderName, image.StoredFileName);
var webpPath = Path.Combine(imageStoragePath, image.FolderName,$"{Path.GetFileNameWithoutExtension(image.StoredFileName)}.webp");
if(File.Exists(imagePath))
{
//convert to webp
}
if(File.Exists(webpPath))
{
//update db meta data
}
}
}
}
}
await jobProgressServiceEF.UpdateJob(job.Id, 100, "", true);
}
catch (Exception exp)