Fix file transfer progress bar.

This commit is contained in:
Jared Goodwin 2020-04-17 16:28:25 -07:00
parent def7f558a0
commit eaa9fcbe7b
7 changed files with 27 additions and 14 deletions

View File

@ -2,6 +2,7 @@
using System.Collections.Generic;
using Remotely.Server.Services;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
@ -31,13 +32,13 @@ namespace Remotely.Server.API
[HttpPost]
[RequestSizeLimit(500_000_000)]
public List<string> Post()
public async Task<List<string>> Post()
{
var fileIDs = new List<string>();
foreach (var file in Request.Form.Files)
{
var orgID = User.Identity.IsAuthenticated ? DataService.GetUserByName(User.Identity.Name).OrganizationID : null;
var id = DataService.AddSharedFile(file, orgID);
var id = await DataService.AddSharedFile(file, orgID);
fileIDs.Add(id);
}
return fileIDs;

View File

@ -182,14 +182,14 @@
</div>
<div id="fileTransferDiv" hidden="hidden">
<span>File Transfer:</span>
<progress id="fileTransferProgress"></progress>
</div>
<footer>
<div class="footer-wrapper">
<p>&copy; @DateTimeOffset.Now.Year - Translucency Software</p>
<p hidden="hidden">
<span>File Transfer:</span>
<progress id="fileTransferProgress"></progress>
</p>
</div>
</footer>
<script type="module" src="~/scripts/RemoteControl/Main.js">

View File

@ -175,7 +175,7 @@ namespace Remotely.Server.Services
return true;
}
public string AddSharedFile(IFormFile file, string organizationID)
public async Task<string> AddSharedFile(IFormFile file, string organizationID)
{
var expirationDate = DateTimeOffset.Now.AddDays(-AppConfig.DataRetentionInDays);
var expiredFiles = RemotelyContext.SharedFiles.Where(x => x.Timestamp < expirationDate);
@ -186,7 +186,7 @@ namespace Remotely.Server.Services
{
using (var ms = new MemoryStream())
{
stream.CopyTo(ms);
await stream.CopyToAsync(ms);
fileContents = ms.ToArray();
}
}
@ -197,7 +197,7 @@ namespace Remotely.Server.Services
ContentType = file.ContentType,
OrganizationID = organizationID
});
RemotelyContext.SaveChanges();
await RemotelyContext.SaveChangesAsync();
return newEntity.Entity.ID;
}

View File

@ -275,4 +275,15 @@ footer {
bottom: 25px;
right: 25px;
z-index: 4;
}
#fileTransferDiv {
position: fixed;
right: 5px;
bottom: 5px;
background-color: rgb(50, 50, 50);
color: white;
z-index: 3;
padding: 10px;
border-radius: 5px;
}

View File

@ -475,9 +475,9 @@ function uploadFiles(fileList) {
FileTransferProgress.parentElement.setAttribute("hidden", "hidden");
ShowMessage("File upload failed.");
});
xhr.addEventListener("progress", function (e) {
xhr.upload.onprogress = (e) => {
FileTransferProgress.value = isFinite(e.loaded / e.total) ? e.loaded / e.total : 0;
});
};
xhr.send(fd);
}
function closeAllHorizontalBars(exceptBarId) {

File diff suppressed because one or more lines are too long

View File

@ -524,9 +524,10 @@ function uploadFiles(fileList: FileList) {
FileTransferProgress.parentElement.setAttribute("hidden", "hidden");
ShowMessage("File upload failed.");
});
xhr.addEventListener("progress", function (e) {
xhr.upload.onprogress = (e) => {
FileTransferProgress.value = isFinite(e.loaded / e.total) ? e.loaded / e.total : 0;
});
}
xhr.send(fd);
}