Backport pull request #12940 from jellyfin/release-10.10.z

Remove DynamicImageResponse local image after saved to metadata folder

Original-merge: 3a9b48a2aa

Merged-by: joshuaboniface <joshua@boniface.me>

Backported-by: Joshua M. Boniface <joshua@boniface.me>
This commit is contained in:
gnattu 2024-11-03 10:55:53 -05:00 committed by Joshua M. Boniface
parent 9e386ecc27
commit 46fb6c1579
5 changed files with 24 additions and 8 deletions

View File

@ -122,7 +122,6 @@ namespace Emby.Server.Implementations.Images
} }
await ProviderManager.SaveImage(item, outputPath, mimeType, imageType, null, false, cancellationToken).ConfigureAwait(false); await ProviderManager.SaveImage(item, outputPath, mimeType, imageType, null, false, cancellationToken).ConfigureAwait(false);
File.Delete(outputPath);
return ItemUpdateType.ImageUpdate; return ItemUpdateType.ImageUpdate;
} }

View File

@ -77,7 +77,8 @@ namespace MediaBrowser.Controller.Providers
Task SaveImage(BaseItem item, Stream source, string mimeType, ImageType type, int? imageIndex, CancellationToken cancellationToken); Task SaveImage(BaseItem item, Stream source, string mimeType, ImageType type, int? imageIndex, CancellationToken cancellationToken);
/// <summary> /// <summary>
/// Saves the image. /// Saves the image by giving the image path on filesystem.
/// This method will remove the image on the source path after saving it to the destination.
/// </summary> /// </summary>
/// <param name="item">Image to save.</param> /// <param name="item">Image to save.</param>
/// <param name="source">Source of image.</param> /// <param name="source">Source of image.</param>

View File

@ -229,9 +229,7 @@ namespace MediaBrowser.Providers.Manager
{ {
var mimeType = MimeTypes.GetMimeType(response.Path); var mimeType = MimeTypes.GetMimeType(response.Path);
var stream = AsyncFile.OpenRead(response.Path); await _providerManager.SaveImage(item, response.Path, mimeType, imageType, null, null, cancellationToken).ConfigureAwait(false);
await _providerManager.SaveImage(item, stream, mimeType, imageType, null, cancellationToken).ConfigureAwait(false);
} }
} }

View File

@ -7,6 +7,7 @@ using System.Linq;
using System.Net; using System.Net;
using System.Net.Http; using System.Net.Http;
using System.Net.Mime; using System.Net.Mime;
using System.Runtime.ExceptionServices;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using AsyncKeyedLock; using AsyncKeyedLock;
@ -251,15 +252,29 @@ namespace MediaBrowser.Providers.Manager
} }
/// <inheritdoc/> /// <inheritdoc/>
public Task SaveImage(BaseItem item, string source, string mimeType, ImageType type, int? imageIndex, bool? saveLocallyWithMedia, CancellationToken cancellationToken) public async Task SaveImage(BaseItem item, string source, string mimeType, ImageType type, int? imageIndex, bool? saveLocallyWithMedia, CancellationToken cancellationToken)
{ {
if (string.IsNullOrWhiteSpace(source)) if (string.IsNullOrWhiteSpace(source))
{ {
throw new ArgumentNullException(nameof(source)); throw new ArgumentNullException(nameof(source));
} }
var fileStream = AsyncFile.OpenRead(source); try
return new ImageSaver(_configurationManager, _libraryMonitor, _fileSystem, _logger).SaveImage(item, fileStream, mimeType, type, imageIndex, saveLocallyWithMedia, cancellationToken); {
var fileStream = AsyncFile.OpenRead(source);
await new ImageSaver(_configurationManager, _libraryMonitor, _fileSystem, _logger).SaveImage(item, fileStream, mimeType, type, imageIndex, saveLocallyWithMedia, cancellationToken);
}
finally
{
try
{
File.Delete(source);
}
catch (Exception ex)
{
_logger.LogError(ex, "Source file {Source} not found or in use, skip removing", source);
}
}
} }
/// <inheritdoc/> /// <inheritdoc/>

View File

@ -292,6 +292,9 @@ namespace Jellyfin.Providers.Tests.Manager
providerManager.Setup(pm => pm.SaveImage(item, It.IsAny<Stream>(), It.IsAny<string>(), imageType, null, It.IsAny<CancellationToken>())) providerManager.Setup(pm => pm.SaveImage(item, It.IsAny<Stream>(), It.IsAny<string>(), imageType, null, It.IsAny<CancellationToken>()))
.Callback<BaseItem, Stream, string, ImageType, int?, CancellationToken>((callbackItem, _, _, callbackType, _, _) => callbackItem.SetImagePath(callbackType, 0, new FileSystemMetadata())) .Callback<BaseItem, Stream, string, ImageType, int?, CancellationToken>((callbackItem, _, _, callbackType, _, _) => callbackItem.SetImagePath(callbackType, 0, new FileSystemMetadata()))
.Returns(Task.CompletedTask); .Returns(Task.CompletedTask);
providerManager.Setup(pm => pm.SaveImage(item, It.IsAny<string>(), It.IsAny<string>(), imageType, null, null, It.IsAny<CancellationToken>()))
.Callback<BaseItem, string, string, ImageType, int?, bool?, CancellationToken>((callbackItem, _, _, callbackType, _, _, _) => callbackItem.SetImagePath(callbackType, 0, new FileSystemMetadata()))
.Returns(Task.CompletedTask);
var itemImageProvider = GetItemImageProvider(providerManager.Object, null); var itemImageProvider = GetItemImageProvider(providerManager.Object, null);
var result = await itemImageProvider.RefreshImages(item, libraryOptions, new List<IImageProvider> { dynamicProvider.Object }, refreshOptions, CancellationToken.None); var result = await itemImageProvider.RefreshImages(item, libraryOptions, new List<IImageProvider> { dynamicProvider.Object }, refreshOptions, CancellationToken.None);