Refactor bumper template background management: rename background upload endpoint to reflect new functionality, update related command and handler to use image ID instead of extension, and adjust data models to support image references. Remove obsolete background handling code and enhance UI components for improved image selection and display.
This commit is contained in:
@@ -1,67 +0,0 @@
|
||||
using TeleWave.Application.Common.Interfaces;
|
||||
using TeleWave.Infrastructure.Media;
|
||||
|
||||
namespace TeleWave.Infrastructure.Metadata;
|
||||
|
||||
/// <summary>Скачивает и хранит картинки метаданных локально под metadata/shows/{id}.</summary>
|
||||
public sealed class MetadataImageStore(MediaPathResolver paths, IHttpClientFactory httpFactory)
|
||||
: IMetadataImageStore
|
||||
{
|
||||
public async Task<string?> DownloadEpisodeStillAsync(
|
||||
Guid episodeId,
|
||||
string url,
|
||||
CancellationToken cancellationToken
|
||||
)
|
||||
{
|
||||
try
|
||||
{
|
||||
var client = httpFactory.CreateClient("metadata");
|
||||
using var response = await client.GetAsync(url, cancellationToken);
|
||||
if (!response.IsSuccessStatusCode)
|
||||
return null;
|
||||
|
||||
var ext = ExtensionFor(url, response.Content.Headers.ContentType?.MediaType);
|
||||
var dir = paths.MetadataEpisodeDir(episodeId);
|
||||
Directory.CreateDirectory(dir);
|
||||
RemoveExisting(dir, "still");
|
||||
|
||||
var abs = paths.MetadataEpisodeStillPath(episodeId, ext);
|
||||
await using var content = await response.Content.ReadAsStreamAsync(cancellationToken);
|
||||
await using (var fs = File.Create(abs))
|
||||
await content.CopyToAsync(fs, cancellationToken);
|
||||
return paths.MetadataEpisodeStillRelative(episodeId, ext);
|
||||
}
|
||||
catch (Exception ex) when (ex is HttpRequestException or TaskCanceledException or IOException)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteEpisodeImages(Guid episodeId)
|
||||
{
|
||||
var dir = paths.MetadataEpisodeDir(episodeId);
|
||||
if (Directory.Exists(dir))
|
||||
Directory.Delete(dir, recursive: true);
|
||||
}
|
||||
|
||||
public string? ResolveAbsolutePath(string relativePath)
|
||||
{
|
||||
var abs = paths.ResolveRelative(relativePath);
|
||||
return abs is not null && File.Exists(abs) ? abs : null;
|
||||
}
|
||||
|
||||
private static void RemoveExisting(string dir, string baseName)
|
||||
{
|
||||
foreach (var file in Directory.EnumerateFiles(dir, baseName + ".*"))
|
||||
File.Delete(file);
|
||||
}
|
||||
|
||||
private static string ExtensionFor(string url, string? mediaType) =>
|
||||
mediaType switch
|
||||
{
|
||||
"image/png" => ".png",
|
||||
"image/webp" => ".webp",
|
||||
"image/jpeg" => ".jpg",
|
||||
_ => Path.GetExtension(new Uri(url).AbsolutePath) is { Length: > 1 } e ? e.ToLowerInvariant() : ".jpg",
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user