-
Notifications
You must be signed in to change notification settings - Fork 95
Open
Description
Hey would you be ok if I do this ?
Need
- When clients enqueue downloads via
POST /api/v0/transfers/downloads/{username}, the API currently returns only a201status with no body. - Consumers must immediately query the list endpoints to locate the created transfers, which is inefficient and ambiguous when multiple requests are issued.
- Exposing the server-assigned download identifiers in the enqueue response will let clients track transfers without an extra round trip.
Proposed Implementation
- Update
TransfersController.EnqueueAsyncto capture theList<Transfer>returned byIDownloadService.EnqueueAsyncand project the non-nullTransfer.Idvalues into the HTTP response body. - Return a
201 Createdresponse with the GUID collection and aCreatedAtActionpointing toGetDownloadsAsyncto keep the response RESTful. - Ensure the controller’s
ProducesResponseTypeattribute documents the GUID payload so the OpenAPI surface reflects the new response shape.
+++ b/src/slskd/Transfers/API/Controllers/TransfersController.cs
@@ -201,7 +201,7 @@ namespace slskd.Transfers.API
/// <response code="500">An unexpected error was encountered.</response>
[HttpPost("downloads/{username}")]
[Authorize(Policy = AuthPolicy.Any)]
- [ProducesResponseType(201)]
+ [ProducesResponseType(typeof(IEnumerable<Guid>), 201)]
[ProducesResponseType(typeof(string), 403)]
[ProducesResponseType(typeof(string), 500)]
public async Task<IActionResult> EnqueueAsync([FromRoute, Required] string username, [FromBody] IEnumerable<QueueDownloadRequest> requests)
@@ -213,8 +213,16 @@ namespace slskd.Transfers.API
try
{
- await Transfers.Downloads.EnqueueAsync(username, requests.Select(r => (r.Filename, r.Size)));
- return StatusCode(201);
+ var downloads = await Transfers.Downloads.EnqueueAsync(username, requests.Select(r => (r.Filename, r.Size)));
+
+ var ids = downloads == null
+ ? Array.Empty<Guid>()
+ : downloads
+ .Where(transfer => transfer is not null)
+ .Select(transfer => transfer.Id)
+ .ToArray();
+
+ return CreatedAtAction(nameof(GetDownloadsAsync), new { username }, ids);
}
catch (Exception ex)
{
@@ -458,4 +466,4 @@ namespace slskd.Transfers.API
return Ok(upload);
}
}Metadata
Metadata
Assignees
Labels
No labels