Fixed a bug where publisher images would fail to download
This commit is contained in:
parent
519cf60fc8
commit
322b2953bb
1 changed files with 26 additions and 12 deletions
|
|
@ -206,17 +206,12 @@ public class CoverDbService : ICoverDbService
|
||||||
throw new KavitaException($"Could not grab publisher image for {publisherName}");
|
throw new KavitaException($"Could not grab publisher image for {publisherName}");
|
||||||
}
|
}
|
||||||
|
|
||||||
_logger.LogTrace("Fetching publisher image from {Url}", publisherLink.Sanitize());
|
|
||||||
// Download the publisher file using Flurl
|
|
||||||
var publisherStream = await publisherLink
|
|
||||||
.AllowHttpStatus("2xx,304")
|
|
||||||
.GetStreamAsync();
|
|
||||||
|
|
||||||
// Create the destination file path
|
// Create the destination file path
|
||||||
using var image = Image.NewFromStream(publisherStream);
|
|
||||||
var filename = ImageService.GetPublisherFormat(publisherName, encodeFormat);
|
var filename = ImageService.GetPublisherFormat(publisherName, encodeFormat);
|
||||||
|
|
||||||
image.WriteToFile(Path.Combine(_directoryService.PublisherDirectory, filename));
|
_logger.LogTrace("Fetching publisher image from {Url}", publisherLink.Sanitize());
|
||||||
|
await DownloadImageFromUrl(publisherName, encodeFormat, publisherLink, _directoryService.PublisherDirectory);
|
||||||
|
|
||||||
_logger.LogDebug("Publisher image for {PublisherName} downloaded and saved successfully", publisherName.Sanitize());
|
_logger.LogDebug("Publisher image for {PublisherName} downloaded and saved successfully", publisherName.Sanitize());
|
||||||
|
|
||||||
return filename;
|
return filename;
|
||||||
|
|
@ -302,7 +297,27 @@ public class CoverDbService : ICoverDbService
|
||||||
.GetStreamAsync();
|
.GetStreamAsync();
|
||||||
|
|
||||||
using var image = Image.NewFromStream(imageStream);
|
using var image = Image.NewFromStream(imageStream);
|
||||||
image.WriteToFile(targetFile);
|
try
|
||||||
|
{
|
||||||
|
image.WriteToFile(targetFile);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
switch (encodeFormat)
|
||||||
|
{
|
||||||
|
case EncodeFormat.PNG:
|
||||||
|
image.Pngsave(Path.Combine(_directoryService.FaviconDirectory, filename));
|
||||||
|
break;
|
||||||
|
case EncodeFormat.WEBP:
|
||||||
|
image.Webpsave(Path.Combine(_directoryService.FaviconDirectory, filename));
|
||||||
|
break;
|
||||||
|
case EncodeFormat.AVIF:
|
||||||
|
image.Heifsave(Path.Combine(_directoryService.FaviconDirectory, filename));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(encodeFormat), encodeFormat, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return filename;
|
return filename;
|
||||||
}
|
}
|
||||||
|
|
@ -385,14 +400,13 @@ public class CoverDbService : ICoverDbService
|
||||||
private async Task<string> FallbackToKavitaReaderPublisher(string publisherName)
|
private async Task<string> FallbackToKavitaReaderPublisher(string publisherName)
|
||||||
{
|
{
|
||||||
const string publisherFileName = "publishers.txt";
|
const string publisherFileName = "publishers.txt";
|
||||||
var externalLink = string.Empty;
|
|
||||||
var allOverrides = await GetCachedData(publisherFileName) ??
|
var allOverrides = await GetCachedData(publisherFileName) ??
|
||||||
await $"{NewHost}publishers/{publisherFileName}".GetStringAsync();
|
await $"{NewHost}publishers/{publisherFileName}".GetStringAsync();
|
||||||
|
|
||||||
// Cache immediately
|
// Cache immediately
|
||||||
await CacheDataAsync(publisherFileName, allOverrides);
|
await CacheDataAsync(publisherFileName, allOverrides);
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(allOverrides)) return externalLink;
|
if (string.IsNullOrEmpty(allOverrides)) return string.Empty;
|
||||||
|
|
||||||
var externalFile = allOverrides
|
var externalFile = allOverrides
|
||||||
.Split("\n")
|
.Split("\n")
|
||||||
|
|
@ -415,7 +429,7 @@ public class CoverDbService : ICoverDbService
|
||||||
throw new KavitaException($"Could not grab publisher image for {publisherName}");
|
throw new KavitaException($"Could not grab publisher image for {publisherName}");
|
||||||
}
|
}
|
||||||
|
|
||||||
return $"{NewHost}publishers/{externalLink}";
|
return $"{NewHost}publishers/{externalFile}";
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task CacheDataAsync(string fileName, string? content)
|
private async Task CacheDataAsync(string fileName, string? content)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue