mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-03-03 15:30:03 -05:00
fix: Resolve CA1849/CA2007 synchronous IO in EpubImageProvider (#16124)
This commit is contained in:
parent
b9e5cce383
commit
b97f5b809d
@ -48,13 +48,13 @@ namespace MediaBrowser.Providers.Books.OpenPackagingFormat
|
||||
{
|
||||
if (string.Equals(Path.GetExtension(item.Path), ".epub", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return GetFromZip(item);
|
||||
return GetFromZip(item, cancellationToken);
|
||||
}
|
||||
|
||||
return Task.FromResult(new DynamicImageResponse { HasImage = false });
|
||||
}
|
||||
|
||||
private async Task<DynamicImageResponse> LoadCover(ZipArchive epub, XmlDocument opf, string opfRootDirectory)
|
||||
private async Task<DynamicImageResponse> LoadCover(ZipArchive epub, XmlDocument opf, string opfRootDirectory, CancellationToken cancellationToken)
|
||||
{
|
||||
var utilities = new OpfReader<EpubImageProvider>(opf, _logger);
|
||||
var coverReference = utilities.ReadCoverPath(opfRootDirectory);
|
||||
@ -72,9 +72,11 @@ namespace MediaBrowser.Providers.Books.OpenPackagingFormat
|
||||
}
|
||||
|
||||
var memoryStream = new MemoryStream();
|
||||
using (var coverStream = coverFile.Open())
|
||||
|
||||
var coverStream = await coverFile.OpenAsync(cancellationToken).ConfigureAwait(false);
|
||||
await using (coverStream.ConfigureAwait(false))
|
||||
{
|
||||
await coverStream.CopyToAsync(memoryStream).ConfigureAwait(false);
|
||||
await coverStream.CopyToAsync(memoryStream, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
memoryStream.Position = 0;
|
||||
@ -85,9 +87,9 @@ namespace MediaBrowser.Providers.Books.OpenPackagingFormat
|
||||
return response;
|
||||
}
|
||||
|
||||
private async Task<DynamicImageResponse> GetFromZip(BaseItem item)
|
||||
private async Task<DynamicImageResponse> GetFromZip(BaseItem item, CancellationToken cancellationToken)
|
||||
{
|
||||
using var epub = ZipFile.OpenRead(item.Path);
|
||||
using var epub = await ZipFile.OpenReadAsync(item.Path, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
var opfFilePath = EpubUtils.ReadContentFilePath(epub);
|
||||
if (opfFilePath == null)
|
||||
@ -107,12 +109,12 @@ namespace MediaBrowser.Providers.Books.OpenPackagingFormat
|
||||
return new DynamicImageResponse { HasImage = false };
|
||||
}
|
||||
|
||||
using var opfStream = opfFile.Open();
|
||||
using var opfStream = await opfFile.OpenAsync(cancellationToken).ConfigureAwait(false);
|
||||
|
||||
var opfDocument = new XmlDocument();
|
||||
opfDocument.Load(opfStream);
|
||||
|
||||
return await LoadCover(epub, opfDocument, opfRootDirectory).ConfigureAwait(false);
|
||||
return await LoadCover(epub, opfDocument, opfRootDirectory, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user