Add torrent client integration and downloads management: introduce qbittorrent service in Docker setup, implement downloads endpoint in API, and enhance media storage to handle imported files. Update frontend routes and translations for downloads management.
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
using LiteCqrs;
|
||||
using TeleWave.Api.Common;
|
||||
using TeleWave.Application.Common.Interfaces;
|
||||
using TeleWave.Application.Media.Downloads;
|
||||
using TeleWave.Application.Media.Register;
|
||||
using TeleWave.Domain.Media;
|
||||
using TeleWave.Infrastructure.Identity;
|
||||
|
||||
namespace TeleWave.Api.Endpoints;
|
||||
|
||||
public static class DownloadsEndpoints
|
||||
{
|
||||
public static IEndpointRouteBuilder MapDownloadsEndpoints(this IEndpointRouteBuilder app)
|
||||
{
|
||||
var admin = app.MapGroup("/api/admin/downloads")
|
||||
.WithTags("Admin.Downloads")
|
||||
.RequireAuthorization(policy => policy.RequireRole(RoleNames.Admin));
|
||||
|
||||
admin.MapGet("", List).Produces<IReadOnlyList<DownloadFileDto>>();
|
||||
admin.MapPost("/import", Import).Produces<CreatedIdResponse>(StatusCodes.Status201Created);
|
||||
|
||||
return app;
|
||||
}
|
||||
|
||||
private static async Task<IResult> List(ISender sender, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await sender.Send(new ListDownloadsQuery(), cancellationToken);
|
||||
return Results.Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>Импорт выбранного файла из downloads/: регистрирует ассет (копией) и ставит в обработку.</summary>
|
||||
private static async Task<IResult> Import(
|
||||
ImportDownloadBody body,
|
||||
ISender sender,
|
||||
IMediaProcessingQueue queue,
|
||||
CancellationToken cancellationToken
|
||||
)
|
||||
{
|
||||
var fileName = Path.GetFileName(body.RelativePath);
|
||||
var result = await sender.Send(
|
||||
new RegisterMediaAssetCommand(body.RelativePath, MediaSource.Download, fileName),
|
||||
cancellationToken
|
||||
);
|
||||
if (!result.IsSuccess)
|
||||
return result.ToHttpResult();
|
||||
|
||||
queue.Enqueue(result.Value);
|
||||
return Results.Created($"/api/admin/media/{result.Value}", new CreatedIdResponse(result.Value));
|
||||
}
|
||||
}
|
||||
|
||||
public sealed record ImportDownloadBody(string RelativePath);
|
||||
Reference in New Issue
Block a user