39 lines
1005 B
JavaScript
39 lines
1005 B
JavaScript
var Uploader = function(terminal) {
|
|
|
|
var self = this;
|
|
|
|
this.terminal = terminal;
|
|
|
|
this.node = document.createElement('div');
|
|
|
|
this.input = document.createElement('input');
|
|
this.input.type = 'file';
|
|
|
|
this.loadFile = function() {
|
|
self.file = self.input.files[0];
|
|
self.reader.readAsArrayBuffer(self.file);
|
|
|
|
self.node.parentNode.removeChild(self.node);
|
|
};
|
|
|
|
this.input.onchange = this.loadFile;
|
|
|
|
this.reader = new FileReader();
|
|
this.saveCallback = function(packet, args) {
|
|
if (packet.opcode == 'Result') {
|
|
self.terminal.ui.print(packet.message);
|
|
} else if (packet.opcode == 'FileException') {
|
|
self.terminal.ui.println(packet.type);
|
|
} else {
|
|
self.terminal.ui.println(packet.opcode);
|
|
}
|
|
};
|
|
this.reader.onload = function(e) {
|
|
var path = self.terminal.session.toAbsolutePath(self.terminal.session.currentDirectory + '/' + self.file.name);
|
|
self.terminal.fileAPI.save(self.saveCallback, null, path, new Uint8Array(e.target.result));
|
|
};
|
|
|
|
this.node.appendChild(this.input);
|
|
|
|
};
|