Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ protected async Task<string> PostTusWhiteImage()

var response = await _httpClient.SendAsync(message);

return response.Headers.GetValues("Location").First().Substring(11);
return response.Headers.GetValues("Location").First().Replace("send_data", string.Empty).TrimStart('/');
}
private async Task CleanUpDirectories()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using FluentAssertions;
using System.Net;
using System.Net;
using FluentAssertions;
using Xunit;

namespace SF.PhotoPixels.API.Integration.Tests.ResumableEndpoints;
Expand All @@ -20,7 +20,7 @@ public async Task DeleteUpload_WithValidId_ShouldReturnNoContent()
var message = new HttpRequestMessage()
{
Method = HttpMethod.Delete,
RequestUri = new Uri($"/send_data/{id}", UriKind.Relative)
RequestUri = new Uri($"send_data/{id}", UriKind.Relative)
};

message.Headers.Add("Tus-Resumable", "1.0.0");
Expand All @@ -39,7 +39,7 @@ public async Task DeleteUpload_WithNonExistingId_ShouldReturnNotFound()
var message = new HttpRequestMessage()
{
Method = HttpMethod.Delete,
RequestUri = new Uri($"/send_data/{Guid.NewGuid():N}", UriKind.Relative)
RequestUri = new Uri($"send_data/{Guid.NewGuid():N}", UriKind.Relative)
};

message.Headers.Add("Tus-Resumable", "1.0.0");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Ardalis.ApiEndpoints;
using JasperFx.Core;
using Mediator;
using Microsoft.AspNetCore.Mvc;
using SF.PhotoPixels.Application.Commands.Tus;
Expand All @@ -18,7 +19,7 @@ public CreateUploadEndpoint(IMediator mediator)
}

[UpdateMetadata]
[TusCreation("create_upload")]
[TusCreationPhotopixels("create_upload")]
[SwaggerOperation(
Summary = "Create and get info on a new upload resource",
Tags = ["Tus"]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public GetUserUploadsEndpoint(IMediator mediator)
{
_mediator = mediator;
}
[HttpGet("/resumable_uploads")]
[HttpGet("resumable_uploads")]
[SwaggerOperation(
Summary = "Get User current resumable uploads",
Tags = ["Tus"]),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.AspNetCore.Mvc.Routing;
using Microsoft.Extensions.DependencyInjection;
using SolidTUS.Constants;
using SolidTUS.Models;
using SolidTUS.ProtocolFlows;
using SolidTUS.ProtocolHandlers;
using System.Diagnostics;
using System.Linq;
using Microsoft.AspNetCore.Routing;
using Endpoints = System.Collections.Generic.IEnumerable<Microsoft.AspNetCore.Routing.EndpointDataSource>;

using static Microsoft.AspNetCore.Http.HttpMethods;
using SolidTUS.Functional.Models;
namespace SolidTUS.Attributes;

/// <summary>
/// Identifies an action that supports TUS resource creation.
/// </summary>
[AttributeUsage(AttributeTargets.Method)]
public class TusCreationPhotopixelsAttribute : TusCreationAttribute
{
/// <summary>
/// Instantiate a new object of <see cref="TusCreationAttribute"/>
/// </summary>
public TusCreationPhotopixelsAttribute()
{
}

/// <summary>
/// Instantiate a new <see cref="TusCreationAttribute"/> creation endpoint handler.
/// </summary>
/// <param name="template">The route template</param>
public TusCreationPhotopixelsAttribute([StringSyntax("Route")] string template) : base(template)
{

}

public override async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
{
await base.OnActionExecutionAsync(context, next);
}

/// <inheritdoc />
public override async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next)
{
//base.OnResultExecutionAsync(context, next);
// Before sending headers -->
context.HttpContext.Response.OnStarting(state =>
{
var ctx = (ResultExecutingContext)state;
var isPost = IsPost(ctx.HttpContext.Request.Method);
var response = ctx.HttpContext.Response;
var isSuccess = response.StatusCode >= 200 && response.StatusCode < 300;
if (isPost && isSuccess)
{
ctx.HttpContext.Response.StatusCode = 201;
string location = ctx.HttpContext.Response.Headers["Location"]!;
ctx.HttpContext.Response.Headers["Location"] = location.TrimStart('/');
}
return Task.CompletedTask;
}, context);

await next();
}
}
Loading