aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2022-10-10 18:16:10 -0500
committerJP Dillingham <jp@dillingham.me>2022-10-10 18:16:10 -0500
commit4bb2484d7b5f3bd1d0e49f8393c4065fa1e59339 (patch)
tree9fbffe112430f787c130361efb780426bbe1ae71 /src
parent35edcb342ded5a9bdc4f0627f0c213b85c033bba (diff)
downloadslskd-4bb2484d7b5f3bd1d0e49f8393c4065fa1e59339.tar.gz
save to a temp file
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Network/API/Controllers/NetworkController.cs21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/slskd/Network/API/Controllers/NetworkController.cs b/src/slskd/Network/API/Controllers/NetworkController.cs
index 8f863ce4..69e3d789 100644
--- a/src/slskd/Network/API/Controllers/NetworkController.cs
+++ b/src/slskd/Network/API/Controllers/NetworkController.cs
@@ -18,6 +18,7 @@
namespace slskd.Network
{
using System;
+ using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
@@ -96,7 +97,7 @@ namespace slskd.Network
[HttpPost("shares/{id}")]
[Authorize]
- public IActionResult UploadShares(string id)
+ public async Task<IActionResult> UploadShares(string id)
{
if (!Guid.TryParse(id, out var guid))
{
@@ -108,11 +109,19 @@ namespace slskd.Network
return Unauthorized();
}
- // todo: save the uploaded file to a temp location
- // todo: open the uploaded file as a sqlite database
- // todo: load the contents of the file into the local share database
- // while modifying the records somehow to indicate which agent
- // is hosting it
+ var temp = Path.Combine(Path.GetTempPath(), $"slskd_share_{agent}_{Path.GetRandomFileName()}.db");
+
+ Log.Debug("Uploading share from {Agent} to {Filename}", agent, temp);
+
+ using var outputStream = new FileStream(temp, FileMode.CreateNew, FileAccess.Write);
+ using var inputStream = Request.Form.Files.First().OpenReadStream();
+
+ await inputStream.CopyToAsync(outputStream);
+
+ Log.Debug("Upload of share from {Agent} to {Filename} complete", agent, temp);
+
+ // todo: validate database
+ // todo: add contents of db to local db
return Ok();
}