Skip to content

Commit

Permalink
Fix file transfer progress bar.
Browse files Browse the repository at this point in the history
  • Loading branch information
bitbound committed Apr 17, 2020
1 parent def7f55 commit eaa9fcb
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 14 deletions.
5 changes: 3 additions & 2 deletions Server/API/FileSharingController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -31,13 +32,13 @@ public ActionResult Get(string id)

[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;
Expand Down
8 changes: 4 additions & 4 deletions Server/Pages/RemoteControl.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down
6 changes: 3 additions & 3 deletions Server/Services/DataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public bool AddOrUpdateDevice(Device device, out Device updatedDevice)
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);
Expand All @@ -186,7 +186,7 @@ public string AddSharedFile(IFormFile file, string organizationID)
{
using (var ms = new MemoryStream())
{
stream.CopyTo(ms);
await stream.CopyToAsync(ms);
fileContents = ms.ToArray();
}
}
Expand All @@ -197,7 +197,7 @@ public string AddSharedFile(IFormFile file, string organizationID)
ContentType = file.ContentType,
OrganizationID = organizationID
});
RemotelyContext.SaveChanges();
await RemotelyContext.SaveChangesAsync();
return newEntity.Entity.ID;
}

Expand Down
11 changes: 11 additions & 0 deletions Server/wwwroot/css/remote-control.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
4 changes: 2 additions & 2 deletions Server/wwwroot/scripts/RemoteControl/UI.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Server/wwwroot/scripts/RemoteControl/UI.js.map

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions Server/wwwroot/scripts/RemoteControl/UI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit eaa9fcb

Please sign in to comment.