adds update of existing images
All checks were successful
PiwigoDirectorySync/pipeline/head This commit looks good
All checks were successful
PiwigoDirectorySync/pipeline/head This commit looks good
This commit is contained in:
parent
b92aabfbcb
commit
c94956abdd
@ -19,12 +19,12 @@
|
|||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.10"/>
|
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.10"/>
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.10"/>
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.10"/>
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="7.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="7.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="7.0.0"/>
|
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="7.0.4" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="7.0.0"/>
|
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="7.0.0"/>
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0"/>
|
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0"/>
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="7.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="7.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="7.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="7.0.0" />
|
||||||
<PackageReference Include="Piwigo.Client" Version="0.1.0.17"/>
|
<PackageReference Include="Piwigo.Client" Version="0.1.0.19" />
|
||||||
<PackageReference Include="Spectre.Console.Analyzer" Version="0.47.0">
|
<PackageReference Include="Spectre.Console.Analyzer" Version="0.47.0">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
@ -36,6 +36,31 @@ public class ImageSynchronizer : IImageSynchronizer
|
|||||||
|
|
||||||
await GetImageIdsFromServerAsync(piwigoClient, piwigoServer, ct);
|
await GetImageIdsFromServerAsync(piwigoClient, piwigoServer, ct);
|
||||||
await UploadNewImagesToServerAsync(piwigoClient, piwigoServer, ct);
|
await UploadNewImagesToServerAsync(piwigoClient, piwigoServer, ct);
|
||||||
|
await UploadChangedImagesToServerAsync(piwigoClient, piwigoServer, ct);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task UploadChangedImagesToServerAsync(IPiwigoClient piwigoClient, ServerEntity piwigoServer, CancellationToken ct)
|
||||||
|
{
|
||||||
|
var imagesToUpload = await _persistenceContext.PiwigoImages.Include(i => i.Album)
|
||||||
|
.Where(i => i.ServerImageId != null && i.Album.ServerId == piwigoServer.Id && i.UploadRequired)
|
||||||
|
.ToListAsync(ct);
|
||||||
|
|
||||||
|
_logger.LogInformation("Updating {Count} images", imagesToUpload.Count);
|
||||||
|
|
||||||
|
foreach (var imageEntity in imagesToUpload)
|
||||||
|
{
|
||||||
|
var fileInfo = new FileInfo(Path.Combine(piwigoServer.RootDirectory, imageEntity.FilePath));
|
||||||
|
var imageUpload = GetImageUpload(imageEntity, fileInfo.CreationTime);
|
||||||
|
var imageUploaded = await piwigoClient.UploadImageAsync(fileInfo, imageUpload, ct);
|
||||||
|
|
||||||
|
imageEntity.ServerImageId = imageUploaded.ImageId;
|
||||||
|
imageEntity.UploadRequired = false;
|
||||||
|
|
||||||
|
_logger.LogInformation("Updated image {ImageEntityName} ({ImageEntityId}) on piwigo server with id {ImageEntityServerImageId}", imageEntity.Name, imageEntity.Id,
|
||||||
|
imageEntity.ServerImageId);
|
||||||
|
|
||||||
|
await _persistenceContext.SaveChangesAsync(ct);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task UploadNewImagesToServerAsync(IPiwigoClient piwigoClient, ServerEntity piwigoServer, CancellationToken ct)
|
private async Task UploadNewImagesToServerAsync(IPiwigoClient piwigoClient, ServerEntity piwigoServer, CancellationToken ct)
|
||||||
@ -44,6 +69,8 @@ public class ImageSynchronizer : IImageSynchronizer
|
|||||||
.Where(i => i.ServerImageId == null && i.Album.ServerId == piwigoServer.Id)
|
.Where(i => i.ServerImageId == null && i.Album.ServerId == piwigoServer.Id)
|
||||||
.ToListAsync(ct);
|
.ToListAsync(ct);
|
||||||
|
|
||||||
|
_logger.LogInformation("Uploading {Count} images", imagesToUpload.Count);
|
||||||
|
|
||||||
foreach (var imageEntity in imagesToUpload)
|
foreach (var imageEntity in imagesToUpload)
|
||||||
{
|
{
|
||||||
var fileInfo = new FileInfo(Path.Combine(piwigoServer.RootDirectory, imageEntity.FilePath));
|
var fileInfo = new FileInfo(Path.Combine(piwigoServer.RootDirectory, imageEntity.FilePath));
|
||||||
@ -79,6 +106,8 @@ public class ImageSynchronizer : IImageSynchronizer
|
|||||||
.Where(i => i.ServerImageId == null && i.Album.ServerId == piwigoServer.Id)
|
.Where(i => i.ServerImageId == null && i.Album.ServerId == piwigoServer.Id)
|
||||||
.ToListAsync(ct);
|
.ToListAsync(ct);
|
||||||
|
|
||||||
|
_logger.LogInformation("Checking {Count} images if they exist", imagesToSearch.Count);
|
||||||
|
|
||||||
var md5SumsToCheck = imagesToSearch.Where(i => i.Md5Sum != null).DistinctBy(i => i.Md5Sum).ToDictionary(i => i.Md5Sum!, i => i, StringComparer.OrdinalIgnoreCase);
|
var md5SumsToCheck = imagesToSearch.Where(i => i.Md5Sum != null).DistinctBy(i => i.Md5Sum).ToDictionary(i => i.Md5Sum!, i => i, StringComparer.OrdinalIgnoreCase);
|
||||||
|
|
||||||
var processedImages = 0;
|
var processedImages = 0;
|
||||||
@ -91,6 +120,8 @@ public class ImageSynchronizer : IImageSynchronizer
|
|||||||
{
|
{
|
||||||
var imageEntity = md5SumsToCheck[existingImage.Key];
|
var imageEntity = md5SumsToCheck[existingImage.Key];
|
||||||
imageEntity.ServerImageId = existingImage.Value;
|
imageEntity.ServerImageId = existingImage.Value;
|
||||||
|
imageEntity.UploadRequired = false;
|
||||||
|
|
||||||
_logger.LogInformation("Found image {ImageEntityName} ({ImageEntityId}) on piwigo server with id {ImageEntityServerImageId}", imageEntity.Name, imageEntity.Id,
|
_logger.LogInformation("Found image {ImageEntityName} ({ImageEntityId}) on piwigo server with id {ImageEntityServerImageId}", imageEntity.Name, imageEntity.Id,
|
||||||
imageEntity.ServerImageId);
|
imageEntity.ServerImageId);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user