Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request]: Convert Estranged.Lfs.Api to utilize minimal APIs instead of controllers #14

Closed
QuantumToasted opened this issue Apr 16, 2023 · 1 comment

Comments

@QuantumToasted
Copy link

QuantumToasted commented Apr 16, 2023

This may be an overkill suggestion, but as it doesn't seem possible (or easy) to add route prefixes to third-party controllers, I decided to convert them to minimal API methods. This may allow more user flexibility, if for some reason a user may require more configuration beyond customizing the route prefix.
Example for POST /objects/batch:

public static void MapGitHubLfsBatch(this IEndpointRouteBuilder endpoints, string pathBase = "")
{
    endpoints.MapPost($"{pathBase}/objects/batch", async (IObjectManager objectManager, [FromBody] BatchRequest request) =>
    {
        return request.Operation switch
        {
            LfsOperation.Upload => new BatchResponse
            {
                Transfer = request.Transfers.First(),
                Objects = await objectManager.UploadObjects(request.Objects, GenerateTimeoutToken())
                    .ConfigureAwait(false)
            },
            LfsOperation.Download => new BatchResponse
            {
                Transfer = request.Transfers.First(),
                Objects = await objectManager.DownloadObjects(request.Objects, GenerateTimeoutToken())
                    .ConfigureAwait(false)
            },
            _ => throw new Exception("Method not implemented")
        };
    }).AddEndpointFilter<BasicAuthEndpointFilter>();
    
    static CancellationToken GenerateTimeoutToken() => new CancellationTokenSource(TimeSpan.FromSeconds(25)).Token;
}

*Note: BasicAuthEndpointFilter is just a copy of the already existing BasicAuthFilter, converted to implement IEndpointFilter instead of IAsyncActionFilter.

I would be happy to submit a PR, but always like asking in Issues before bothering to do so.

@QuantumToasted
Copy link
Author

Update: My project which had a problem this proposal was intended to address has fallen out of scope for what I believe the intent of this library was. As such, I have decided to wrap the git-lfs API on my own terms without expecting a third-party library to bow to my will. You are free to still follow up on this as desired, but I do not have any plans to PR or expect a change of this magnitude.

Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant