Add remote computer's upload progress when downloading from console.

This commit is contained in:
Jared Goodwin 2020-08-08 16:12:56 -07:00
parent 29df1df67b
commit fea1b7cc7f
8 changed files with 28 additions and 8 deletions

View File

@ -174,6 +174,15 @@ namespace Remotely.Agent.Services
}
using var wc = new WebClient();
var lastProgressPercent = 0;
wc.UploadProgressChanged += async (sender, args) =>
{
if (args.ProgressPercentage > lastProgressPercent)
{
lastProgressPercent = args.ProgressPercentage;
await HubConnection.SendAsync("DownloadFileProgress", lastProgressPercent, senderConnectionID);
}
};
var response = await wc.UploadFileTaskAsync($"{ConnectionInfo.Host}/API/FileSharing/", filePath);
var fileIDs = JsonSerializer.Deserialize<string[]>(Encoding.UTF8.GetString(response));
await HubConnection.SendAsync("DownloadFile", fileIDs[0], senderConnectionID);

View File

@ -160,6 +160,11 @@ namespace Remotely.Server.Hubs
{
return BrowserHubContext.Clients.Client(requesterID).SendAsync("DownloadFile", fileID);
}
public Task DownloadFileProgress(int progressPercent, string requesterID)
{
return BrowserHubContext.Clients.Client(requesterID).SendAsync("DownloadFileProgress", progressPercent);
}
public override Task OnConnectedAsync()
{
return base.OnConnectedAsync();

View File

@ -370,7 +370,7 @@ var commands = [
];
function uploadFiles(fileList) {
return new Promise((resolve, reject) => {
AddConsoleOutput("File upload started...");
AddConsoleOutput("File upload started.");
var strPath = "/API/FileSharing/";
var fd = new FormData();
for (var i = 0; i < fileList.length; i++) {
@ -380,7 +380,7 @@ function uploadFiles(fileList) {
xhr.open('POST', strPath, true);
xhr.addEventListener("load", function () {
if (xhr.status === 200) {
AddConsoleOutput("File upload completed.");
AddConsoleOutput("File upload completed. It might take a while for the agent to download it.");
resolve(JSON.parse(xhr.responseText));
}
else {
@ -394,7 +394,7 @@ function uploadFiles(fileList) {
});
xhr.upload.onprogress = (e) => {
var currentPercent = isFinite(e.loaded / e.total) ? Math.round(e.loaded / e.total * 100) : 0;
if (currentPercent != uploadPercent) {
if (currentPercent > uploadPercent) {
var uploadPercent = currentPercent;
AddConsoleOutput("File upload progress: " + String(currentPercent) + "%");
}

File diff suppressed because one or more lines are too long

View File

@ -514,7 +514,7 @@ var commands: Array<ConsoleCommand> = [
function uploadFiles(fileList: FileList): Promise<string[]> {
return new Promise<string[]>((resolve, reject) => {
AddConsoleOutput("File upload started...");
AddConsoleOutput("File upload started.");
var strPath = "/API/FileSharing/";
var fd = new FormData();
@ -525,7 +525,7 @@ function uploadFiles(fileList: FileList): Promise<string[]> {
xhr.open('POST', strPath, true);
xhr.addEventListener("load", function () {
if (xhr.status === 200) {
AddConsoleOutput("File upload completed.");
AddConsoleOutput("File upload completed. It might take a while for the agent to download it.");
resolve(JSON.parse(xhr.responseText));
}
else {
@ -541,7 +541,7 @@ function uploadFiles(fileList: FileList): Promise<string[]> {
xhr.upload.onprogress = (e) => {
var currentPercent = isFinite(e.loaded / e.total) ? Math.round(e.loaded / e.total * 100) : 0;
if (currentPercent != uploadPercent) {
if (currentPercent > uploadPercent) {
var uploadPercent = currentPercent;
AddConsoleOutput("File upload progress: " + String(currentPercent) + "%");
}

View File

@ -87,6 +87,9 @@ function applyMessageHandlers(hubConnection) {
hubConnection.on("DownloadFile", (fileID) => {
location.assign(`/API/FileSharing/${fileID}`);
});
hubConnection.on("DownloadFileProgress", (progressPercent) => {
AddConsoleOutput(`Remote computer upload progress: ${progressPercent}%`);
});
hubConnection.on("TransferCompleted", (transferID) => {
var completedWrapper = document.getElementById(transferID + "-completed");
var count = parseInt(completedWrapper.innerHTML);

File diff suppressed because one or more lines are too long

View File

@ -103,6 +103,9 @@ function applyMessageHandlers(hubConnection) {
hubConnection.on("DownloadFile", (fileID: string) => {
location.assign(`/API/FileSharing/${fileID}`);
});
hubConnection.on("DownloadFileProgress", (progressPercent: number) => {
AddConsoleOutput(`Remote computer upload progress: ${progressPercent}%`)
});
hubConnection.on("TransferCompleted", (transferID: string) => {
var completedWrapper = document.getElementById(transferID + "-completed");
var count = parseInt(completedWrapper.innerHTML);