Fixed routes and bugs
This commit is contained in:
@@ -32,10 +32,9 @@ namespace Musify.Infrastructure.MassTransit.Activities
|
||||
executeContext.CancellationToken);
|
||||
|
||||
var sourceFilePath = executeContext.GetVariable<string>(executeContext.Arguments.SourceFilePathVariableName);
|
||||
ArgumentNullException.ThrowIfNull(sourceFilePath, nameof(sourceFilePath));
|
||||
var workingDirectory = executeContext.GetVariable<string>(executeContext.Arguments.WorkingDirectoryVariableName);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(sourceFilePath) || string.IsNullOrWhiteSpace(workingDirectory))
|
||||
throw new InvalidOperationException("Transcode activity requires source file path and working directory variables.");
|
||||
ArgumentNullException.ThrowIfNull(sourceFilePath, nameof(sourceFilePath));
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
@@ -4,7 +4,6 @@ using Musify.Application.Contracts.Infrastructure;
|
||||
using Musify.Domain.Entities;
|
||||
using Musify.Infrastructure.MassTransit.Arguments;
|
||||
using Musify.Infrastructure.MassTransit.Logs;
|
||||
using Musify.Infrastructure.MassTransit.Activities;
|
||||
|
||||
namespace Musify.Infrastructure.MassTransit.Activities.Audio
|
||||
{
|
||||
|
||||
@@ -32,9 +32,7 @@ namespace Musify.Infrastructure.MassTransit.Activities
|
||||
executeContext.CancellationToken);
|
||||
|
||||
var destinationPath = executeContext.GetVariable<string>(executeContext.Arguments.DestinationFilePathVariableName);
|
||||
if (string.IsNullOrWhiteSpace(destinationPath))
|
||||
throw new InvalidOperationException(
|
||||
$"Download activity requires variable '{executeContext.Arguments.DestinationFilePathVariableName}' with destination file path.");
|
||||
ArgumentNullException.ThrowIfNull(destinationPath, nameof(destinationPath));
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
@@ -32,16 +32,10 @@ namespace Musify.Infrastructure.MassTransit.Activities
|
||||
executeContext.CancellationToken);
|
||||
|
||||
var folderPath = executeContext.GetVariable<string>(executeContext.Arguments.SourceDirectoryVariableName);
|
||||
if (string.IsNullOrWhiteSpace(folderPath))
|
||||
throw new InvalidOperationException(
|
||||
$"Transfer activity requires variable '{executeContext.Arguments.SourceDirectoryVariableName}' with source directory path.");
|
||||
ArgumentNullException.ThrowIfNull(folderPath, nameof(folderPath));
|
||||
|
||||
var destinationKeyName = executeContext.Arguments.DestinationKeyName;
|
||||
if (string.IsNullOrWhiteSpace(destinationKeyName) && !string.IsNullOrWhiteSpace(executeContext.Arguments.DestinationKeyNameVariableName))
|
||||
destinationKeyName = executeContext.GetVariable<string>(executeContext.Arguments.DestinationKeyNameVariableName);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(destinationKeyName))
|
||||
throw new InvalidOperationException("Transfer activity requires a destination key name from arguments or variables.");
|
||||
ArgumentNullException.ThrowIfNull(destinationKeyName, nameof(destinationKeyName));
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
@@ -32,8 +32,7 @@ namespace Musify.Infrastructure.MassTransit.Activities.Files
|
||||
executeContext.CancellationToken);
|
||||
|
||||
var sourceFilePath = executeContext.GetVariable<string>(executeContext.Arguments.FilePathVariableName);
|
||||
if (string.IsNullOrEmpty(sourceFilePath))
|
||||
throw new InvalidOperationException($"Upload activity requires variable '{executeContext.Arguments.FilePathVariableName}' with source file path.");
|
||||
ArgumentNullException.ThrowIfNull(sourceFilePath, nameof(sourceFilePath));
|
||||
var fileName = Path.GetFileName(sourceFilePath);
|
||||
|
||||
try
|
||||
|
||||
+10
-11
@@ -13,6 +13,8 @@ namespace Musify.Infrastructure.MassTransit.Activities
|
||||
{
|
||||
public const string ExecuteEndpointName = "generate-picture-workflow-paths";
|
||||
|
||||
internal const string ResizedPictureFileExtension = ".webp";
|
||||
|
||||
public async Task<ExecutionResult> Execute(ExecuteContext<GeneratePictureWorkflowPathsArguments> executeContext)
|
||||
{
|
||||
var processId = await processTrackingStore.GetOrCreateProcessAsync(
|
||||
@@ -32,19 +34,16 @@ namespace Musify.Infrastructure.MassTransit.Activities
|
||||
try
|
||||
{
|
||||
var destinationFolderName = Guid.NewGuid().ToString();
|
||||
var originalFileName = Path.GetFileName(executeContext.Arguments.SourceKeyName);
|
||||
var sourceFileExtension = Path.GetExtension(originalFileName);
|
||||
var workingDirectory = Path.Combine(executeContext.Arguments.TemporaryRootDirectory, destinationFolderName);
|
||||
|
||||
var sourceFileName = Guid.NewGuid().ToString() + sourceFileExtension;
|
||||
var smallPictureFileName = Guid.NewGuid().ToString() + sourceFileExtension;
|
||||
var mediumPictureFileName = Guid.NewGuid().ToString() + sourceFileExtension;
|
||||
var largePictureFileName = Guid.NewGuid().ToString() + sourceFileExtension;
|
||||
|
||||
var sourceFilePath = Path.Combine(workingDirectory, sourceFileName);
|
||||
var smallPictureFilePath = Path.Combine(workingDirectory, smallPictureFileName);
|
||||
var mediumPictureFilePath = Path.Combine(workingDirectory, mediumPictureFileName);
|
||||
var largePictureFilePath = Path.Combine(workingDirectory, largePictureFileName);
|
||||
var sourceFilePath = Path.Combine(
|
||||
workingDirectory, Guid.NewGuid().ToString() + Path.GetExtension(executeContext.Arguments.SourceKeyName));
|
||||
var smallPictureFilePath = Path.Combine(
|
||||
workingDirectory, Guid.NewGuid().ToString() + ResizedPictureFileExtension);
|
||||
var mediumPictureFilePath = Path.Combine(
|
||||
workingDirectory, Guid.NewGuid().ToString() + ResizedPictureFileExtension);
|
||||
var largePictureFilePath = Path.Combine(
|
||||
workingDirectory, Guid.NewGuid().ToString() + ResizedPictureFileExtension);
|
||||
|
||||
Directory.CreateDirectory(workingDirectory);
|
||||
|
||||
|
||||
@@ -33,10 +33,9 @@ namespace Musify.Infrastructure.MassTransit.Activities
|
||||
executeContext.CancellationToken);
|
||||
|
||||
var sourceFilePath = executeContext.GetVariable<string>(executeContext.Arguments.SourceFilePathVariableName);
|
||||
ArgumentNullException.ThrowIfNull(sourceFilePath, nameof(sourceFilePath));
|
||||
var destinationFilePath = executeContext.GetVariable<string>(executeContext.Arguments.DestinationFilePathVariableName);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(sourceFilePath) || string.IsNullOrWhiteSpace(destinationFilePath))
|
||||
throw new InvalidOperationException("Resize activity requires source and destination file path variables.");
|
||||
ArgumentNullException.ThrowIfNull(destinationFilePath, nameof(destinationFilePath));
|
||||
|
||||
try
|
||||
{
|
||||
@@ -48,7 +47,7 @@ namespace Musify.Infrastructure.MassTransit.Activities
|
||||
|
||||
await using var fileStream = File.OpenRead(sourceFilePath);
|
||||
|
||||
var resizedPicture = await pictureHandler.ResizePictureAsync(
|
||||
var resizedPicture = await pictureHandler.ResizePictureAsWebpAsync(
|
||||
fileStream,
|
||||
executeContext.Arguments.Width,
|
||||
executeContext.Arguments.Height,
|
||||
|
||||
@@ -31,6 +31,13 @@ namespace Musify.Infrastructure.MassTransit.Activities
|
||||
0,
|
||||
executeContext.CancellationToken);
|
||||
|
||||
var smallResizedVariable = executeContext.GetVariable<string>(executeContext.Arguments.SmallPictureVariableName);
|
||||
ArgumentNullException.ThrowIfNull(smallResizedVariable, nameof(smallResizedVariable));
|
||||
var mediumResizedVariable = executeContext.GetVariable<string>(executeContext.Arguments.MediumPictureVariableName);
|
||||
ArgumentNullException.ThrowIfNull(mediumResizedVariable, nameof(mediumResizedVariable));
|
||||
var largeResizedVariable = executeContext.GetVariable<string>(executeContext.Arguments.LargePictureVariableName);
|
||||
ArgumentNullException.ThrowIfNull(largeResizedVariable, nameof(largeResizedVariable));
|
||||
|
||||
try
|
||||
{
|
||||
var playList = await database.PlayLists.FindAsync(
|
||||
@@ -52,9 +59,9 @@ namespace Musify.Infrastructure.MassTransit.Activities
|
||||
playList.LargePictureKeyName);
|
||||
|
||||
playList.OriginalPictureKeyName = Path.GetFileName(executeContext.Arguments.OriginalPictureKeyName);
|
||||
playList.SmallPictureKeyName = Path.GetFileName(executeContext.Arguments.SmallPictureKeyName);
|
||||
playList.MediumPictureKeyName = Path.GetFileName(executeContext.Arguments.MediumPictureKeyName);
|
||||
playList.LargePictureKeyName = Path.GetFileName(executeContext.Arguments.LargePictureKeyName);
|
||||
playList.SmallPictureKeyName = Path.GetFileName(smallResizedVariable);
|
||||
playList.MediumPictureKeyName = Path.GetFileName(mediumResizedVariable);
|
||||
playList.LargePictureKeyName = Path.GetFileName(largeResizedVariable);
|
||||
|
||||
database.PlayLists.Update(playList);
|
||||
await database.SaveChangesAsync(executeContext.CancellationToken);
|
||||
|
||||
@@ -31,6 +31,13 @@ namespace Musify.Infrastructure.MassTransit.Activities
|
||||
0,
|
||||
executeContext.CancellationToken);
|
||||
|
||||
var smallResizedVariable = executeContext.GetVariable<string>(executeContext.Arguments.SmallPictureVariableName);
|
||||
ArgumentNullException.ThrowIfNull(smallResizedVariable, nameof(smallResizedVariable));
|
||||
var mediumResizedVariable = executeContext.GetVariable<string>(executeContext.Arguments.MediumPictureVariableName);
|
||||
ArgumentNullException.ThrowIfNull(mediumResizedVariable, nameof(mediumResizedVariable));
|
||||
var largeResizedVariable = executeContext.GetVariable<string>(executeContext.Arguments.LargePictureVariableName);
|
||||
ArgumentNullException.ThrowIfNull(largeResizedVariable, nameof(largeResizedVariable));
|
||||
|
||||
try
|
||||
{
|
||||
var track = await database.Tracks.FindAsync(
|
||||
@@ -52,9 +59,9 @@ namespace Musify.Infrastructure.MassTransit.Activities
|
||||
track.LargePictureKeyName);
|
||||
|
||||
track.OriginalPictureKeyName = Path.GetFileName(executeContext.Arguments.OriginalPictureKeyName);
|
||||
track.SmallPictureKeyName = Path.GetFileName(executeContext.Arguments.SmallPictureKeyName);
|
||||
track.MediumPictureKeyName = Path.GetFileName(executeContext.Arguments.MediumPictureKeyName);
|
||||
track.LargePictureKeyName = Path.GetFileName(executeContext.Arguments.LargePictureKeyName);
|
||||
track.SmallPictureKeyName = Path.GetFileName(smallResizedVariable);
|
||||
track.MediumPictureKeyName = Path.GetFileName(mediumResizedVariable);
|
||||
track.LargePictureKeyName = Path.GetFileName(largeResizedVariable);
|
||||
|
||||
database.Tracks.Update(track);
|
||||
await database.SaveChangesAsync(executeContext.CancellationToken);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
public record UpdatePlayListPictureArguments(
|
||||
Guid PlayListId,
|
||||
string OriginalPictureKeyName,
|
||||
string SmallPictureKeyName,
|
||||
string MediumPictureKeyName,
|
||||
string LargePictureKeyName);
|
||||
string SmallPictureVariableName,
|
||||
string MediumPictureVariableName,
|
||||
string LargePictureVariableName);
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
public record UpdateTrackPictureArguments(
|
||||
Guid TrackId,
|
||||
string OriginalPictureKeyName,
|
||||
string SmallPictureKeyName,
|
||||
string MediumPictureKeyName,
|
||||
string LargePictureKeyName);
|
||||
string SmallPictureVariableName,
|
||||
string MediumPictureVariableName,
|
||||
string LargePictureVariableName);
|
||||
}
|
||||
+13
-14
@@ -1,6 +1,5 @@
|
||||
using MassTransit;
|
||||
using MassTransit.Courier.Contracts;
|
||||
using MimeMapping;
|
||||
using Musify.Application.Events;
|
||||
using Musify.Infrastructure.Configuration;
|
||||
using Musify.Infrastructure.MassTransit.Activities;
|
||||
@@ -29,19 +28,15 @@ namespace Musify.Infrastructure.MassTransit.RoutingSlip.Builders
|
||||
message.LargePictureHeight,
|
||||
correlationId);
|
||||
|
||||
routingSlipBuilder.AddSubscription(
|
||||
MessagingHelper.BuildConsumerUri(RoutingSlipCleanUpConsumer.QueueName),
|
||||
RoutingSlipEvents.Completed | RoutingSlipEvents.Faulted);
|
||||
|
||||
routingSlipBuilder.AddActivity(
|
||||
ActivityNames.UpdateTrackPicture,
|
||||
MessagingHelper.BuildExecuteActivityUri(UpdateTrackPictureActivity.ExecuteEndpointName),
|
||||
new UpdateTrackPictureArguments(
|
||||
message.TrackId,
|
||||
message.SourceKeyName,
|
||||
message.SmallPictureRoute,
|
||||
message.MediumPictureRoute,
|
||||
message.LargePictureRoute));
|
||||
RoutingSlipVariableNames.Picture.SmallResizedFilePath,
|
||||
RoutingSlipVariableNames.Picture.MediumResizedFilePath,
|
||||
RoutingSlipVariableNames.Picture.LargeResizedFilePath));
|
||||
|
||||
return routingSlipBuilder;
|
||||
}
|
||||
@@ -51,13 +46,13 @@ namespace Musify.Infrastructure.MassTransit.RoutingSlip.Builders
|
||||
var routingSlipBuilder = BuildPictureWorkflow(
|
||||
message.SourceBucketName,
|
||||
message.SourceKeyName,
|
||||
message.SmallPictureKeyName,
|
||||
message.SmallPictureRoute,
|
||||
message.SmallPictureWidth,
|
||||
message.SmallPictureHeight,
|
||||
message.MediumPictureKeyName,
|
||||
message.MediumPictureRoute,
|
||||
message.MediumPictureWidth,
|
||||
message.MediumPictureHeight,
|
||||
message.LargePictureKeyName,
|
||||
message.LargePictureRoute,
|
||||
message.LargePictureWidth,
|
||||
message.LargePictureHeight,
|
||||
correlationId);
|
||||
@@ -68,9 +63,9 @@ namespace Musify.Infrastructure.MassTransit.RoutingSlip.Builders
|
||||
new UpdatePlayListPictureArguments(
|
||||
message.PlayListId,
|
||||
message.SourceKeyName,
|
||||
message.SmallPictureKeyName,
|
||||
message.MediumPictureKeyName,
|
||||
message.LargePictureKeyName));
|
||||
RoutingSlipVariableNames.Picture.SmallResizedFilePath,
|
||||
RoutingSlipVariableNames.Picture.MediumResizedFilePath,
|
||||
RoutingSlipVariableNames.Picture.LargeResizedFilePath));
|
||||
|
||||
return routingSlipBuilder;
|
||||
}
|
||||
@@ -91,6 +86,10 @@ namespace Musify.Infrastructure.MassTransit.RoutingSlip.Builders
|
||||
{
|
||||
var routingSlipBuilder = new RoutingSlipBuilder(NewId.NextGuid());
|
||||
|
||||
routingSlipBuilder.AddSubscription(
|
||||
MessagingHelper.BuildConsumerUri(RoutingSlipCleanUpConsumer.QueueName),
|
||||
RoutingSlipEvents.Completed | RoutingSlipEvents.Faulted);
|
||||
|
||||
routingSlipBuilder.AddVariable(RoutingSlipVariableNames.Workflow.CorrelationId, correlationId ?? Guid.Empty);
|
||||
|
||||
routingSlipBuilder.AddActivity(
|
||||
|
||||
@@ -22,10 +22,6 @@ namespace Musify.Infrastructure.MassTransit
|
||||
internal const string MediumResizedFilePath = "Picture.MediumResizedFilePath";
|
||||
internal const string LargeResizedFilePath = "Picture.LargeResizedFilePath";
|
||||
internal const string DestinationFolderName = "Picture.DestinationFolderName";
|
||||
|
||||
internal const string SmallPictureKeyName = "Picture.SmallPictureKeyName";
|
||||
internal const string MediumPictureKeyName = "Picture.MediumPictureKeyName";
|
||||
internal const string LargePictureKeyName = "Picture.LargePictureKeyName";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,11 +9,7 @@ namespace Musify.Infrastructure.Pictures
|
||||
public class PictureHandler(ILogger<PictureHandler> logger)
|
||||
: IPictureHandler
|
||||
{
|
||||
public string FileExtension => "webp";
|
||||
|
||||
public string ContentType => "image/webp";
|
||||
|
||||
public async Task<Result<Stream>> ResizePictureAsync(Stream pictureStream, int width, int height, CancellationToken cancellationToken)
|
||||
public async Task<Result<Stream>> ResizePictureAsWebpAsync(Stream pictureStream, int width, int height, CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user