#262 loop for converting images added
This commit is contained in:
parent
5da8dda866
commit
d3f14c7402
@ -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)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user