mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-01-28 14:08:22 +00:00
fix: Resolve CA1849/CA2007 synchronous IO in EpubImageProvider (#16124)
Some checks are pending
CodeQL / Analyze (csharp) (push) Waiting to run
OpenAPI / OpenAPI - BASE (push) Waiting to run
OpenAPI / OpenAPI - HEAD (push) Waiting to run
OpenAPI / OpenAPI - Difference (push) Blocked by required conditions
OpenAPI / OpenAPI - Publish Unstable Spec (push) Blocked by required conditions
OpenAPI / OpenAPI - Publish Stable Spec (push) Blocked by required conditions
Tests / run-tests (macos-latest) (push) Waiting to run
Tests / run-tests (ubuntu-latest) (push) Waiting to run
Tests / run-tests (windows-latest) (push) Waiting to run
Project Automation / Project board (push) Waiting to run
Merge Conflict Labeler / Labeling (push) Waiting to run
Some checks are pending
CodeQL / Analyze (csharp) (push) Waiting to run
OpenAPI / OpenAPI - BASE (push) Waiting to run
OpenAPI / OpenAPI - HEAD (push) Waiting to run
OpenAPI / OpenAPI - Difference (push) Blocked by required conditions
OpenAPI / OpenAPI - Publish Unstable Spec (push) Blocked by required conditions
OpenAPI / OpenAPI - Publish Stable Spec (push) Blocked by required conditions
Tests / run-tests (macos-latest) (push) Waiting to run
Tests / run-tests (ubuntu-latest) (push) Waiting to run
Tests / run-tests (windows-latest) (push) Waiting to run
Project Automation / Project board (push) Waiting to run
Merge Conflict Labeler / Labeling (push) Waiting to run
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user