aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2022-10-23 13:36:40 -0500
committerJP Dillingham <jp@dillingham.me>2022-10-23 13:36:40 -0500
commitdbca62ae931f9a0e9082c274bfbe9c4c76048cff (patch)
tree032abc4bddeb437bb8c1a93a4d3dc47de84f4572 /src
parentb41c5ad220a9beae7e5625830f89c09483e56a2c (diff)
downloadslskd-dbca62ae931f9a0e9082c274bfbe9c4c76048cff.tar.gz
fix boundary calculation
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Network/API/Controllers/NetworkController.cs56
1 files changed, 10 insertions, 46 deletions
diff --git a/src/slskd/Network/API/Controllers/NetworkController.cs b/src/slskd/Network/API/Controllers/NetworkController.cs
index 5d3f4c77..e7426035 100644
--- a/src/slskd/Network/API/Controllers/NetworkController.cs
+++ b/src/slskd/Network/API/Controllers/NetworkController.cs
@@ -20,7 +20,6 @@ namespace slskd.Network
using System;
using System.Collections.Generic;
using System.IO;
- using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
@@ -68,14 +67,14 @@ namespace slskd.Network
// todo: make sure agent is registered and return unauthorized if not
- if (!HttpContext.Request.HasFormContentType
- || !MediaTypeHeaderValue.TryParse(HttpContext.Request.ContentType, out var mediaTypeHeader)
+ if (!Request.HasFormContentType
+ || !MediaTypeHeaderValue.TryParse(Request.ContentType, out var mediaTypeHeader)
|| string.IsNullOrEmpty(mediaTypeHeader.Boundary.Value))
{
return new UnsupportedMediaTypeResult();
}
- Log.Debug("Handling file upload for token {Token} from a caller claiming to be agent {Agent}", token, agentName);
+ Log.Information("Handling file upload for token {Token} from a caller claiming to be agent {Agent}", token, agentName);
string credential = default;
Stream stream = default;
@@ -85,18 +84,16 @@ namespace slskd.Network
{
try
{
- var reader = new MultipartReader(mediaTypeHeader.Boundary.Value, Request.Body);
+ var reader = new MultipartReader(HeaderUtilities.RemoveQuotes(mediaTypeHeader.Boundary).Value, Request.Body);
- // the first section contains the credentail
- var section = await reader.ReadNextSectionAsync();
- using var sectionReader = new StreamReader(section.Body);
- credential = sectionReader.ReadToEnd();
+ var credentialSection = await reader.ReadNextSectionAsync();
+ using var sr = new StreamReader(credentialSection.Body);
+ credential = sr.ReadToEnd();
- // the second section contains the file
- section = await reader.ReadNextSectionAsync();
- var contentDisposition = ContentDispositionHeaderValue.Parse(section.ContentDisposition);
+ var fileSection = await reader.ReadNextSectionAsync();
+ var contentDisposition = ContentDispositionHeaderValue.Parse(fileSection.ContentDisposition);
filename = contentDisposition.FileName.Value;
- stream = section.Body;
+ stream = fileSection.Body;
}
catch (Exception ex)
{
@@ -126,39 +123,6 @@ namespace slskd.Network
}
}
- //[DisableFormValueModelBinding]
- //[RequestSizeLimit(MaxFileSize)]
- //[RequestFormLimits(MultipartBodyLengthLimit = MaxFileSize)]
- //public async Task ReceiveFile()
- //{
- // if (!MultipartRequestHelper.IsMultipartContentType(Request.ContentType))
- // throw new BadRequestException("Not a multipart request");
-
- // var boundary = MultipartRequestHelper.GetBoundary(MediaTypeHeaderValue.Parse(Request.ContentType));
- // var reader = new MultipartReader(boundary, Request.Body);
-
- // // note: this is for a single file, you could also process multiple files
- // var section = await reader.ReadNextSectionAsync();
-
- // if (section == null)
- // throw new BadRequestException("No sections in multipart defined");
-
- // if (!ContentDispositionHeaderValue.TryParse(section.ContentDisposition, out var contentDisposition))
- // throw new BadRequestException("No content disposition in multipart defined");
-
- // var fileName = contentDisposition.FileNameStar.ToString();
- // if (string.IsNullOrEmpty(fileName))
- // {
- // fileName = contentDisposition.FileName.ToString();
- // }
-
- // if (string.IsNullOrEmpty(fileName))
- // throw new BadRequestException("No filename defined.");
-
- // using var fileStream = section.Body;
- // await SendFileSomewhere(fileStream);
- //}
-
[HttpPost("shares/{agentName}/{token}")]
[Authorize]
public async Task<IActionResult> UploadShares(string agentName, string token)