I am slowly losing sanity
This commit is contained in:
@@ -13,7 +13,7 @@ public class ThumbnailJob : Job {
|
||||
ThumbnailJob? ParentJob;
|
||||
List<ThumbnailJob>? subJobs;
|
||||
Asset? Asset;
|
||||
string ThumbnailPath;
|
||||
string? ThumbnailPath;
|
||||
int processedAssets = 0;
|
||||
int totalAssets = 1; // Avoid division by zero
|
||||
int ThumbnailSize;
|
||||
@@ -37,7 +37,6 @@ public class ThumbnailJob : Job {
|
||||
Name = "Thumbnail Generation Job";
|
||||
}
|
||||
|
||||
|
||||
public ThumbnailJob(
|
||||
ThumbnailJob parentJob,
|
||||
Asset asset,
|
||||
@@ -61,19 +60,32 @@ public class ThumbnailJob : Job {
|
||||
if (ParentJob == null)
|
||||
MasterJob(token);
|
||||
else
|
||||
SlaveJob();
|
||||
SlaveJob(token);
|
||||
}
|
||||
|
||||
void SlaveJob(CancellationToken token) {
|
||||
if (token.IsCancellationRequested) {
|
||||
Status.Cancel("Cancellation requested from user.");
|
||||
return;
|
||||
}
|
||||
|
||||
void SlaveJob() {
|
||||
if (Asset == null) {
|
||||
Logger.LogError("Sub-job started without an asset. Canceling job.");
|
||||
Status.Fail("Sub-job started without an asset. Canceling job.");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
using var image = Image.Load(Asset.OriginalPath);
|
||||
Status.Start();
|
||||
|
||||
try {
|
||||
if (string.IsNullOrEmpty(Asset.OriginalPath) || !File.Exists(Asset.OriginalPath)) {
|
||||
var msg = $"Original file for asset ID {Asset.Id} not found at path {Asset.OriginalPath}";
|
||||
Logger.LogWarning(msg);
|
||||
Status.Fail(msg);
|
||||
return;
|
||||
}
|
||||
|
||||
using var image = Image.Load(Asset.OriginalPath);
|
||||
image.Mutate(x => x.Resize(
|
||||
new ResizeOptions {
|
||||
Size = new Size(ThumbnailSize),
|
||||
@@ -83,9 +95,17 @@ public class ThumbnailJob : Job {
|
||||
)
|
||||
);
|
||||
|
||||
if (ThumbnailPath == null) {
|
||||
var msg = "Thumbnail path is not set. Cannot save thumbnail.";
|
||||
Logger.LogError(msg);
|
||||
Status.Fail(msg);
|
||||
return;
|
||||
}
|
||||
|
||||
var path = PathFromGuid(Asset.Id, ThumbnailPath);
|
||||
|
||||
if (!Directory.Exists(path)) { Directory.CreateDirectory(Path.GetDirectoryName(path)); }
|
||||
if (!Directory.Exists(path))
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(path)!);
|
||||
|
||||
image.SaveAsJpeg(
|
||||
path,
|
||||
@@ -99,12 +119,13 @@ public class ThumbnailJob : Job {
|
||||
Asset.ThumbnailPath = path;
|
||||
AssetRepository.Update(Asset);
|
||||
AssetRepository.Save();
|
||||
Logger.LogInformation($"Thumbnail generated for asset ID {Asset.Id} at {path}");
|
||||
Status.Complete($"Thumbnail generated for asset ID {Asset.Id} at {path}");
|
||||
} catch (Exception ex) {
|
||||
Logger.LogError(ex, $"Failed to generate thumbnail for asset ID {Asset.Id}");
|
||||
Status.Fail($"Error: {ex.Message}");
|
||||
return;
|
||||
}
|
||||
Logger.LogInformation($"Thumbnail generated for asset ID {Asset.Id} at {Asset.ThumbnailPath}");
|
||||
Status.Complete($"Thumbnail generated for asset ID {Asset.Id} at {Asset.ThumbnailPath}");
|
||||
}
|
||||
|
||||
void MasterJob(CancellationToken token) {
|
||||
|
||||
Reference in New Issue
Block a user