From 9921a9c17e6c09e04bb3370332b4ade1956b682c Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 22 Oct 2022 18:28:26 -0500 Subject: simplify stream handling --- .../Network/API/Controllers/NetworkController.cs | 32 ++++++---------------- 1 file changed, 9 insertions(+), 23 deletions(-) (limited to 'src/slskd/Network/API/Controllers') diff --git a/src/slskd/Network/API/Controllers/NetworkController.cs b/src/slskd/Network/API/Controllers/NetworkController.cs index cecaa39c..3ae2a6b5 100644 --- a/src/slskd/Network/API/Controllers/NetworkController.cs +++ b/src/slskd/Network/API/Controllers/NetworkController.cs @@ -81,31 +81,17 @@ namespace slskd.Network return Unauthorized(); } - // get the record for the waiting file - if (Network.PendingFileUploads.TryGetValue(guid, out var record)) - { - // get the stream from the multipart upload - var stream = Request.Form.Files.First().OpenReadStream(); - - // set the result for the stream - // this should pass control to the transfer service along with - // the stream - record.Stream.SetResult(stream); + // get the stream from the multipart upload + var stream = Request.Form.Files.First().OpenReadStream(); - Console.WriteLine("Stream handed off. Waiting for completion..."); + // pass the stream back to the network service, which will in turn pass it to the + // upload service, and use it to feed data into the remote upload. await this call, + // it will complete when the upload is complete. + await Network.HandleGetFileStreamResponse(agentName, filename: file.FileName, id: guid, stream); - // wait for the transfer service to set the completion result - await record.Completion.Task; - - stream.Dispose(); - Console.WriteLine("Upload complete"); - return Ok(); - } - else - { - Log.Warning("Agent"); - return NotFound(); - } + stream.Dispose(); + Console.WriteLine("Upload complete"); + return Ok(); } [HttpPost("shares/{agentName}/{token}")] -- cgit v1.2.3