mirror of
https://github.com/C9Glax/tranga.git
synced 2025-10-11 05:09:49 +02:00
If image could not be processed, return the original stream
https://github.com/C9Glax/tranga/issues/466
This commit is contained in:
@@ -186,17 +186,17 @@ public class DownloadChapterFromMangaconnectorWorker(MangaConnectorId<Chapter> c
|
|||||||
};
|
};
|
||||||
private async Task<bool> AllDownloadsFinished() => (await StartNewChapterDownloadsWorker.GetMissingChapters(DbContext, CancellationToken)).Count == 0;
|
private async Task<bool> AllDownloadsFinished() => (await StartNewChapterDownloadsWorker.GetMissingChapters(DbContext, CancellationToken)).Count == 0;
|
||||||
|
|
||||||
private bool ProcessImage(Stream imageStream, out Stream processedImage)
|
private Stream ProcessImage(Stream imageStream)
|
||||||
{
|
{
|
||||||
Log.Debug("Processing image");
|
Log.Debug("Processing image");
|
||||||
|
imageStream.Position = 0;
|
||||||
if (!Tranga.Settings.BlackWhiteImages && Tranga.Settings.ImageCompression == 100)
|
if (!Tranga.Settings.BlackWhiteImages && Tranga.Settings.ImageCompression == 100)
|
||||||
{
|
{
|
||||||
Log.Debug("No processing requested for image");
|
Log.Debug("No processing requested for image");
|
||||||
processedImage = imageStream;
|
return imageStream;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
processedImage = new MemoryStream();
|
MemoryStream processedImage = new ();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using Image image = Image.Load(imageStream);
|
using Image image = Image.Load(imageStream);
|
||||||
@@ -208,7 +208,8 @@ public class DownloadChapterFromMangaconnectorWorker(MangaConnectorId<Chapter> c
|
|||||||
Quality = Tranga.Settings.ImageCompression
|
Quality = Tranga.Settings.ImageCompression
|
||||||
});
|
});
|
||||||
Log.Debug("Image processed");
|
Log.Debug("Image processed");
|
||||||
return true;
|
processedImage.Position = 0;
|
||||||
|
return processedImage;
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
@@ -224,7 +225,9 @@ public class DownloadChapterFromMangaconnectorWorker(MangaConnectorId<Chapter> c
|
|||||||
{
|
{
|
||||||
Log.Error(e);
|
Log.Error(e);
|
||||||
}
|
}
|
||||||
return false;
|
imageStream.CopyTo(processedImage);
|
||||||
|
processedImage.Position = 0;
|
||||||
|
return processedImage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -290,10 +293,8 @@ public class DownloadChapterFromMangaconnectorWorker(MangaConnectorId<Chapter> c
|
|||||||
|
|
||||||
if ((int)requestResult.StatusCode < 200 || (int)requestResult.StatusCode >= 300)
|
if ((int)requestResult.StatusCode < 200 || (int)requestResult.StatusCode >= 300)
|
||||||
return null;
|
return null;
|
||||||
if (requestResult.Content.ReadAsStream() == Stream.Null)
|
|
||||||
return null;
|
return ProcessImage(requestResult.Content.ReadAsStream());
|
||||||
|
|
||||||
return ProcessImage(requestResult.Content.ReadAsStream(), out Stream processedImage) ? processedImage : null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString() => $"{base.ToString()} {_mangaConnectorIdId}";
|
public override string ToString() => $"{base.ToString()} {_mangaConnectorIdId}";
|
||||||
|
Reference in New Issue
Block a user