mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 05:07:41 +00:00
GUACAMOLE-44: Merge change to use REST endpoint for upload/download.
This commit is contained in:
@@ -755,7 +755,7 @@ angular.module('client').controller('clientController', ['$scope', '$routeParams
|
|||||||
if (!$scope.client)
|
if (!$scope.client)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return !!($scope.client.uploads.length || $scope.client.downloads.length);
|
return !!$scope.client.uploads.length;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -83,11 +83,6 @@ angular.module('client').directive('guacFileTransferManager', [function guacFile
|
|||||||
return isInProgress(upload.transferState);
|
return isInProgress(upload.transferState);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Remove completed downloads
|
|
||||||
$scope.client.downloads = $scope.client.downloads.filter(function isDownloadInProgress(download) {
|
|
||||||
return isInProgress(download.transferState);
|
|
||||||
});
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}]
|
}]
|
||||||
|
@@ -28,7 +28,6 @@ angular.module('client').factory('ManagedClient', ['$rootScope', '$injector',
|
|||||||
var ClientIdentifier = $injector.get('ClientIdentifier');
|
var ClientIdentifier = $injector.get('ClientIdentifier');
|
||||||
var ManagedClientState = $injector.get('ManagedClientState');
|
var ManagedClientState = $injector.get('ManagedClientState');
|
||||||
var ManagedDisplay = $injector.get('ManagedDisplay');
|
var ManagedDisplay = $injector.get('ManagedDisplay');
|
||||||
var ManagedFileDownload = $injector.get('ManagedFileDownload');
|
|
||||||
var ManagedFilesystem = $injector.get('ManagedFilesystem');
|
var ManagedFilesystem = $injector.get('ManagedFilesystem');
|
||||||
var ManagedFileUpload = $injector.get('ManagedFileUpload');
|
var ManagedFileUpload = $injector.get('ManagedFileUpload');
|
||||||
|
|
||||||
@@ -41,6 +40,7 @@ angular.module('client').factory('ManagedClient', ['$rootScope', '$injector',
|
|||||||
var clipboardService = $injector.get('clipboardService');
|
var clipboardService = $injector.get('clipboardService');
|
||||||
var connectionGroupService = $injector.get('connectionGroupService');
|
var connectionGroupService = $injector.get('connectionGroupService');
|
||||||
var connectionService = $injector.get('connectionService');
|
var connectionService = $injector.get('connectionService');
|
||||||
|
var tunnelService = $injector.get('tunnelService');
|
||||||
var guacAudio = $injector.get('guacAudio');
|
var guacAudio = $injector.get('guacAudio');
|
||||||
var guacHistory = $injector.get('guacHistory');
|
var guacHistory = $injector.get('guacHistory');
|
||||||
var guacImage = $injector.get('guacImage');
|
var guacImage = $injector.get('guacImage');
|
||||||
@@ -104,15 +104,6 @@ angular.module('client').factory('ManagedClient', ['$rootScope', '$injector',
|
|||||||
*/
|
*/
|
||||||
this.clipboardData = template.clipboardData || '';
|
this.clipboardData = template.clipboardData || '';
|
||||||
|
|
||||||
/**
|
|
||||||
* All downloaded files. As files are downloaded, their progress can be
|
|
||||||
* observed through the elements of this array. It is intended that
|
|
||||||
* this array be manipulated externally as needed.
|
|
||||||
*
|
|
||||||
* @type ManagedFileDownload[]
|
|
||||||
*/
|
|
||||||
this.downloads = template.downloads || [];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* All uploaded files. As files are uploaded, their progress can be
|
* All uploaded files. As files are uploaded, their progress can be
|
||||||
* observed through the elements of this array. It is intended that
|
* observed through the elements of this array. It is intended that
|
||||||
@@ -453,9 +444,7 @@ angular.module('client').factory('ManagedClient', ['$rootScope', '$injector',
|
|||||||
|
|
||||||
// Handle any received files
|
// Handle any received files
|
||||||
client.onfile = function clientFileReceived(stream, mimetype, filename) {
|
client.onfile = function clientFileReceived(stream, mimetype, filename) {
|
||||||
$rootScope.$apply(function startDownload() {
|
tunnelService.downloadStream(tunnel.uuid, stream, mimetype, filename);
|
||||||
managedClient.downloads.push(ManagedFileDownload.getInstance(stream, mimetype, filename));
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Handle any received filesystem objects
|
// Handle any received filesystem objects
|
||||||
@@ -530,7 +519,7 @@ angular.module('client').factory('ManagedClient', ['$rootScope', '$injector',
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Start and manage file upload
|
// Start and manage file upload
|
||||||
managedClient.uploads.push(ManagedFileUpload.getInstance(managedClient.client, file, object, streamName));
|
managedClient.uploads.push(ManagedFileUpload.getInstance(managedClient, file, object, streamName));
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -1,153 +0,0 @@
|
|||||||
/*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one
|
|
||||||
* or more contributor license agreements. See the NOTICE file
|
|
||||||
* distributed with this work for additional information
|
|
||||||
* regarding copyright ownership. The ASF licenses this file
|
|
||||||
* to you under the Apache License, Version 2.0 (the
|
|
||||||
* "License"); you may not use this file except in compliance
|
|
||||||
* with the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Provides the ManagedFileDownload class used by the guacClientManager service.
|
|
||||||
*/
|
|
||||||
angular.module('client').factory('ManagedFileDownload', ['$rootScope', '$injector',
|
|
||||||
function defineManagedFileDownload($rootScope, $injector) {
|
|
||||||
|
|
||||||
// Required types
|
|
||||||
var ManagedFileTransferState = $injector.get('ManagedFileTransferState');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Object which serves as a surrogate interface, encapsulating a Guacamole
|
|
||||||
* file download while it is active, allowing it to be detached and
|
|
||||||
* reattached from different client views.
|
|
||||||
*
|
|
||||||
* @constructor
|
|
||||||
* @param {ManagedFileDownload|Object} [template={}]
|
|
||||||
* The object whose properties should be copied within the new
|
|
||||||
* ManagedFileDownload.
|
|
||||||
*/
|
|
||||||
var ManagedFileDownload = function ManagedFileDownload(template) {
|
|
||||||
|
|
||||||
// Use empty object by default
|
|
||||||
template = template || {};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The current state of the file transfer stream.
|
|
||||||
*
|
|
||||||
* @type ManagedFileTransferState
|
|
||||||
*/
|
|
||||||
this.transferState = template.transferState || new ManagedFileTransferState();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The mimetype of the file being transferred.
|
|
||||||
*
|
|
||||||
* @type String
|
|
||||||
*/
|
|
||||||
this.mimetype = template.mimetype;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The filename of the file being transferred.
|
|
||||||
*
|
|
||||||
* @type String
|
|
||||||
*/
|
|
||||||
this.filename = template.filename;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The number of bytes transferred so far.
|
|
||||||
*
|
|
||||||
* @type Number
|
|
||||||
*/
|
|
||||||
this.progress = template.progress;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A blob containing the complete downloaded file. This is available
|
|
||||||
* only after the download has finished.
|
|
||||||
*
|
|
||||||
* @type Blob
|
|
||||||
*/
|
|
||||||
this.blob = template.blob;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new ManagedFileDownload which downloads the contents of the
|
|
||||||
* given stream as a file having the given mimetype and filename.
|
|
||||||
*
|
|
||||||
* @param {Guacamole.InputStream} stream
|
|
||||||
* The stream whose contents should be downloaded as a file.
|
|
||||||
*
|
|
||||||
* @param {String} mimetype
|
|
||||||
* The mimetype of the stream contents.
|
|
||||||
*
|
|
||||||
* @param {String} filename
|
|
||||||
* The filename of the file being received over the steram.
|
|
||||||
*
|
|
||||||
* @return {ManagedFileDownload}
|
|
||||||
* A new ManagedFileDownload object which can be used to track the
|
|
||||||
* progress of the download.
|
|
||||||
*/
|
|
||||||
ManagedFileDownload.getInstance = function getInstance(stream, mimetype, filename) {
|
|
||||||
|
|
||||||
// Init new file download object
|
|
||||||
var managedFileDownload = new ManagedFileDownload({
|
|
||||||
mimetype : mimetype,
|
|
||||||
filename : filename,
|
|
||||||
progress : 0,
|
|
||||||
transferState : new ManagedFileTransferState({
|
|
||||||
streamState : ManagedFileTransferState.StreamState.OPEN
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
// Begin file download
|
|
||||||
var blob_reader = new Guacamole.BlobReader(stream, mimetype);
|
|
||||||
|
|
||||||
// Update progress as data is received
|
|
||||||
blob_reader.onprogress = function onprogress() {
|
|
||||||
|
|
||||||
// Update progress
|
|
||||||
$rootScope.$apply(function downloadStreamProgress() {
|
|
||||||
managedFileDownload.progress = blob_reader.getLength();
|
|
||||||
});
|
|
||||||
|
|
||||||
// Signal server that data was received
|
|
||||||
stream.sendAck("Received", Guacamole.Status.Code.SUCCESS);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
// Save blob and close stream when complete
|
|
||||||
blob_reader.onend = function onend() {
|
|
||||||
$rootScope.$apply(function downloadStreamEnd() {
|
|
||||||
|
|
||||||
// Save blob
|
|
||||||
managedFileDownload.blob = blob_reader.getBlob();
|
|
||||||
|
|
||||||
// Mark stream as closed
|
|
||||||
ManagedFileTransferState.setStreamState(managedFileDownload.transferState,
|
|
||||||
ManagedFileTransferState.StreamState.CLOSED);
|
|
||||||
|
|
||||||
// Notify of upload completion
|
|
||||||
$rootScope.$broadcast('guacDownloadComplete', filename);
|
|
||||||
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
// Signal server that data is ready to be received
|
|
||||||
stream.sendAck("Ready", Guacamole.Status.Code.SUCCESS);
|
|
||||||
|
|
||||||
return managedFileDownload;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
return ManagedFileDownload;
|
|
||||||
|
|
||||||
}]);
|
|
@@ -24,10 +24,11 @@ angular.module('client').factory('ManagedFileUpload', ['$rootScope', '$injector'
|
|||||||
function defineManagedFileUpload($rootScope, $injector) {
|
function defineManagedFileUpload($rootScope, $injector) {
|
||||||
|
|
||||||
// Required types
|
// Required types
|
||||||
|
var Error = $injector.get('Error');
|
||||||
var ManagedFileTransferState = $injector.get('ManagedFileTransferState');
|
var ManagedFileTransferState = $injector.get('ManagedFileTransferState');
|
||||||
|
|
||||||
// Required services
|
// Required services
|
||||||
var $window = $injector.get('$window');
|
var tunnelService = $injector.get('tunnelService');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Object which serves as a surrogate interface, encapsulating a Guacamole
|
* Object which serves as a surrogate interface, encapsulating a Guacamole
|
||||||
@@ -81,32 +82,12 @@ angular.module('client').factory('ManagedFileUpload', ['$rootScope', '$injector'
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts the given bytes to a base64-encoded string.
|
|
||||||
*
|
|
||||||
* @param {Uint8Array} bytes A Uint8Array which contains the data to be
|
|
||||||
* encoded as base64.
|
|
||||||
* @return {String} The base64-encoded string.
|
|
||||||
*/
|
|
||||||
var getBase64 = function getBase64(bytes) {
|
|
||||||
|
|
||||||
var data = "";
|
|
||||||
|
|
||||||
// Produce binary string from bytes in buffer
|
|
||||||
for (var i=0; i<bytes.byteLength; i++)
|
|
||||||
data += String.fromCharCode(bytes[i]);
|
|
||||||
|
|
||||||
// Convert to base64
|
|
||||||
return $window.btoa(data);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new ManagedFileUpload which uploads the given file to the
|
* Creates a new ManagedFileUpload which uploads the given file to the
|
||||||
* server through the given Guacamole client.
|
* server through the given Guacamole client.
|
||||||
*
|
*
|
||||||
* @param {Guacamole.Client} client
|
* @param {ManagedClient} managedClient
|
||||||
* The Guacamole client through which the file is to be uploaded.
|
* The ManagedClient through which the file is to be uploaded.
|
||||||
*
|
*
|
||||||
* @param {File} file
|
* @param {File} file
|
||||||
* The file to upload.
|
* The file to upload.
|
||||||
@@ -123,10 +104,13 @@ angular.module('client').factory('ManagedFileUpload', ['$rootScope', '$injector'
|
|||||||
* A new ManagedFileUpload object which can be used to track the
|
* A new ManagedFileUpload object which can be used to track the
|
||||||
* progress of the upload.
|
* progress of the upload.
|
||||||
*/
|
*/
|
||||||
ManagedFileUpload.getInstance = function getInstance(client, file, object, streamName) {
|
ManagedFileUpload.getInstance = function getInstance(managedClient, file, object, streamName) {
|
||||||
|
|
||||||
var managedFileUpload = new ManagedFileUpload();
|
var managedFileUpload = new ManagedFileUpload();
|
||||||
var streamAcknowledged = false;
|
|
||||||
|
// Pull Guacamole.Tunnel and Guacamole.Client from given ManagedClient
|
||||||
|
var client = managedClient.client;
|
||||||
|
var tunnel = managedClient.tunnel;
|
||||||
|
|
||||||
// Open file for writing
|
// Open file for writing
|
||||||
var stream;
|
var stream;
|
||||||
@@ -153,10 +137,8 @@ angular.module('client').factory('ManagedFileUpload', ['$rootScope', '$injector'
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
var writer = new Guacamole.FileWriter(stream);
|
// Upload file once stream is acknowledged
|
||||||
|
stream.onack = function beginUpload(status) {
|
||||||
// Begin upload when stream is acknowledged, notify of any errors
|
|
||||||
writer.onack = function ackReceived(status) {
|
|
||||||
|
|
||||||
// Notify of any errors from the Guacamole server
|
// Notify of any errors from the Guacamole server
|
||||||
if (status.isError()) {
|
if (status.isError()) {
|
||||||
@@ -165,50 +147,48 @@ angular.module('client').factory('ManagedFileUpload', ['$rootScope', '$injector'
|
|||||||
ManagedFileTransferState.StreamState.ERROR,
|
ManagedFileTransferState.StreamState.ERROR,
|
||||||
status.code);
|
status.code);
|
||||||
});
|
});
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Begin sending the requested file once stream is acknowledged
|
// Begin upload
|
||||||
else if (!streamAcknowledged) {
|
tunnelService.uploadToStream(tunnel.uuid, stream, file, function uploadContinuing(length) {
|
||||||
writer.sendFile(file);
|
$rootScope.$apply(function uploadStreamProgress() {
|
||||||
streamAcknowledged = true;
|
managedFileUpload.progress = length;
|
||||||
}
|
});
|
||||||
|
})
|
||||||
|
|
||||||
};
|
// Notify if upload succeeds
|
||||||
|
.then(function uploadSuccessful() {
|
||||||
|
|
||||||
// Abort and notify if the file cannot be read
|
// Upload complete
|
||||||
writer.onerror = function fileReadError(file, offset, error) {
|
managedFileUpload.progress = file.size;
|
||||||
|
ManagedFileTransferState.setStreamState(managedFileUpload.transferState,
|
||||||
|
ManagedFileTransferState.StreamState.CLOSED);
|
||||||
|
|
||||||
// Abort transfer
|
// Notify of upload completion
|
||||||
writer.sendEnd();
|
$rootScope.$broadcast('guacUploadComplete', file.name);
|
||||||
|
|
||||||
// Upload failed
|
},
|
||||||
ManagedFileTransferState.setStreamState(managedFileUpload.transferState,
|
|
||||||
ManagedFileTransferState.StreamState.ERROR);
|
|
||||||
|
|
||||||
};
|
// Notify if upload fails
|
||||||
|
function uploadFailed(error) {
|
||||||
|
|
||||||
// Notify of upload progress
|
// Use provide status code if the error is coming from the stream
|
||||||
writer.onprogress = function uploadProgressing(file, length) {
|
if (error.type === Error.Type.STREAM_ERROR)
|
||||||
|
ManagedFileTransferState.setStreamState(managedFileUpload.transferState,
|
||||||
|
ManagedFileTransferState.StreamState.ERROR,
|
||||||
|
error.statusCode);
|
||||||
|
|
||||||
|
// Fail with internal error for all other causes
|
||||||
|
else
|
||||||
|
ManagedFileTransferState.setStreamState(managedFileUpload.transferState,
|
||||||
|
ManagedFileTransferState.StreamState.ERROR,
|
||||||
|
Guacamole.Status.Code.INTERNAL_ERROR);
|
||||||
|
|
||||||
$rootScope.$apply(function uploadStreamProgress() {
|
|
||||||
managedFileUpload.progress = length;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
};
|
// Ignore all further acks
|
||||||
|
stream.onack = null;
|
||||||
// Clean up and notify when upload completes
|
|
||||||
writer.oncomplete = function uploadComplete(file) {
|
|
||||||
|
|
||||||
// If at end, stop upload
|
|
||||||
writer.sendEnd();
|
|
||||||
managedFileUpload.progress = file.size;
|
|
||||||
|
|
||||||
// Upload complete
|
|
||||||
ManagedFileTransferState.setStreamState(managedFileUpload.transferState,
|
|
||||||
ManagedFileTransferState.StreamState.CLOSED);
|
|
||||||
|
|
||||||
// Notify of upload completion
|
|
||||||
$rootScope.$broadcast('guacUploadComplete', file.name);
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -25,8 +25,7 @@ angular.module('client').factory('ManagedFilesystem', ['$rootScope', '$injector'
|
|||||||
function defineManagedFilesystem($rootScope, $injector) {
|
function defineManagedFilesystem($rootScope, $injector) {
|
||||||
|
|
||||||
// Required types
|
// Required types
|
||||||
var ManagedFileDownload = $injector.get('ManagedFileDownload');
|
var tunnelService = $injector.get('tunnelService');
|
||||||
var ManagedFileUpload = $injector.get('ManagedFileUpload');
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Object which serves as a surrogate interface, encapsulating a Guacamole
|
* Object which serves as a surrogate interface, encapsulating a Guacamole
|
||||||
@@ -194,8 +193,8 @@ angular.module('client').factory('ManagedFilesystem', ['$rootScope', '$injector'
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Downloads the given file from the server using the given Guacamole
|
* Downloads the given file from the server using the given Guacamole
|
||||||
* client and filesystem. The file transfer can be monitored through the
|
* client and filesystem. The browser will automatically start the
|
||||||
* corresponding entry in the downloads array of the given ManagedClient.
|
* download upon completion of this function.
|
||||||
*
|
*
|
||||||
* @param {ManagedClient} managedClient
|
* @param {ManagedClient} managedClient
|
||||||
* The ManagedClient from which the file is to be downloaded.
|
* The ManagedClient from which the file is to be downloaded.
|
||||||
@@ -215,8 +214,8 @@ angular.module('client').factory('ManagedFilesystem', ['$rootScope', '$injector'
|
|||||||
// Parse filename from string
|
// Parse filename from string
|
||||||
var filename = path.match(/(.*[\\/])?(.*)/)[2];
|
var filename = path.match(/(.*[\\/])?(.*)/)[2];
|
||||||
|
|
||||||
// Start and track download
|
// Start download
|
||||||
managedClient.downloads.push(ManagedFileDownload.getInstance(stream, mimetype, filename));
|
tunnelService.downloadStream(managedClient.tunnel.uuid, stream, mimetype, filename);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user