Fix lint errors

pull/1/head
yflory 8 years ago
parent d7292e69c6
commit 11e2226f1a

@ -59,7 +59,7 @@ define([
var sendChunk = function (box, cb) { var sendChunk = function (box, cb) {
var enc = Nacl.util.encodeBase64(box); var enc = Nacl.util.encodeBase64(box);
Cryptpad.rpc.send.unauthenticated('UPLOAD', enc, function (e, msg) { common.rpc.send.unauthenticated('UPLOAD', enc, function (e, msg) {
console.log(box); console.log(box);
cb(e, msg); cb(e, msg);
}); });
@ -84,14 +84,14 @@ define([
} }
// if not box then done // if not box then done
Cryptpad.uploadComplete(function (e, id) { common.uploadComplete(function (e, id) {
if (e) { return void console.error(e); } if (e) { return void console.error(e); }
var uri = ['', 'blob', id.slice(0,2), id].join('/'); var uri = ['', 'blob', id.slice(0,2), id].join('/');
console.log("encrypted blob is now available as %s", uri); console.log("encrypted blob is now available as %s", uri);
var b64Key = Nacl.util.encodeBase64(key); var b64Key = Nacl.util.encodeBase64(key);
var hash = Cryptpad.getFileHashFromKeys(id, b64Key); var hash = common.getFileHashFromKeys(id, b64Key);
var href = '/file/#' + hash; var href = '/file/#' + hash;
$link.attr('href', href) $link.attr('href', href)
.click(function (e) { .click(function (e) {
@ -103,42 +103,40 @@ define([
//APP.toolbar.addElement(['fileshare'], {}); //APP.toolbar.addElement(['fileshare'], {});
var title = document.title = metadata.name; var title = document.title = metadata.name;
myFile = blob;
myDataType = metadata.type;
Cryptpad.renamePad(title || "", href, function (err) { common.renamePad(title || "", href, function (err) {
if (err) { console.error(err); } // TODO if (err) { console.error(err); } // TODO
console.log(title); console.log(title);
Cryptpad.log(Messages._getKey('upload_success', [title])); common.log(Messages._getKey('upload_success', [title]));
queue.inProgress = false; queue.inProgress = false;
queue.next(); queue.next();
}) });
//Title.updateTitle(title || "", href); //Title.updateTitle(title || "", href);
//APP.toolbar.title.show(); //APP.toolbar.title.show();
}); });
}; };
Cryptpad.uploadStatus(estimate, function (e, pending) { common.uploadStatus(estimate, function (e, pending) {
if (e) { if (e) {
queue.inProgress = false; queue.inProgress = false;
queue.next(); queue.next();
if (e === 'TOO_LARGE') { if (e === 'TOO_LARGE') {
// TODO update table to say too big? // TODO update table to say too big?
return void Cryptpad.alert(Messages.upload_tooLarge); return void common.alert(Messages.upload_tooLarge);
} }
if (e === 'NOT_ENOUGH_SPACE') { if (e === 'NOT_ENOUGH_SPACE') {
// TODO update table to say not enough space? // TODO update table to say not enough space?
return void Cryptpad.alert(Messages.upload_notEnoughSpace); return void common.alert(Messages.upload_notEnoughSpace);
} }
console.error(e); console.error(e);
return void Cryptpad.alert(Messages.upload_serverError); return void common.alert(Messages.upload_serverError);
} }
if (pending) { if (pending) {
// TODO keep this message in case of pending files in another window? // TODO keep this message in case of pending files in another window?
return void Cryptpad.confirm(Messages.upload_uploadPending, function (yes) { return void common.confirm(Messages.upload_uploadPending, function (yes) {
if (!yes) { return; } if (!yes) { return; }
Cryptpad.uploadCancel(function (e, res) { common.uploadCancel(function (e, res) {
if (e) { if (e) {
return void console.error(e); return void console.error(e);
} }
@ -152,9 +150,9 @@ define([
}; };
var prettySize = function (bytes) { var prettySize = function (bytes) {
var kB = Cryptpad.bytesToKilobytes(bytes); var kB = common.bytesToKilobytes(bytes);
if (kB < 1024) { return kB + Messages.KB; } if (kB < 1024) { return kB + Messages.KB; }
var mB = Cryptpad.bytesToMegabytes(bytes); var mB = common.bytesToMegabytes(bytes);
return mB + Messages.MB; return mB + Messages.MB;
}; };
@ -250,7 +248,7 @@ define([
File.createUploader = function ($area, $hover, $body) { File.createUploader = function ($area, $hover, $body) {
createAreaHandlers($area, null, handleFile); createAreaHandlers($area, null, handleFile);
var $c = createTableContainer($body); createTableContainer($body);
}; };
return File; return File;

@ -23,7 +23,6 @@ define([
var $form = $iframe.find('#upload-form'); var $form = $iframe.find('#upload-form');
var $dlform = $iframe.find('#download-form'); var $dlform = $iframe.find('#download-form');
var $label = $form.find('label'); var $label = $form.find('label');
var $table = $iframe.find('#status');
var $progress = $iframe.find('#progress'); var $progress = $iframe.find('#progress');
var $body = $iframe.find('body'); var $body = $iframe.find('body');
@ -36,178 +35,7 @@ define([
var myFile; var myFile;
var myDataType; var myDataType;
/*
var queue = {
queue: [],
inProgress: false
};
var uid = function () {
return 'file-' + String(Math.random()).substring(2);
};
var upload = function (blob, metadata, id) {
console.log(metadata);
if (queue.inProgress) { return; }
queue.inProgress = true;
var $row = $table.find('tr[id="'+id+'"]');
$row.find('.upCancel').html('-');
var $pv = $row.find('.progressValue');
var $pb = $row.find('.progressContainer');
var $link = $row.find('.upLink');
var updateProgress = function (progressValue) {
$pv.text(Math.round(progressValue*100)/100 + '%');
$pb.css({
width: (progressValue/100)*188+'px'
});
};
var u8 = new Uint8Array(blob);
var key = Nacl.randomBytes(32);
var next = FileCrypto.encrypt(u8, metadata, key);
var estimate = FileCrypto.computeEncryptedSize(blob.byteLength, metadata);
var sendChunk = function (box, cb) {
var enc = Nacl.util.encodeBase64(box);
Cryptpad.rpc.send.unauthenticated('UPLOAD', enc, function (e, msg) {
console.log(box);
cb(e, msg);
});
};
var actual = 0;
var again = function (err, box) {
if (err) { throw new Error(err); }
if (box) {
actual += box.length;
var progressValue = (actual / estimate * 100);
updateProgress(progressValue);
return void sendChunk(box, function (e) {
if (e) { return console.error(e); }
next(again);
});
}
if (actual !== estimate) {
console.error('Estimated size does not match actual size');
}
// if not box then done
Cryptpad.uploadComplete(function (e, id) {
if (e) { return void console.error(e); }
var uri = ['', 'blob', id.slice(0,2), id].join('/');
console.log("encrypted blob is now available as %s", uri);
var b64Key = Nacl.util.encodeBase64(key);
var hash = Cryptpad.getFileHashFromKeys(id, b64Key);
$link.attr('href', '/file/#' + hash)
.click(function (e) {
e.preventDefault();
window.open($link.attr('href'), '_blank');
});
// TODO add button to table which copies link to clipboard?
//APP.toolbar.addElement(['fileshare'], {});
var title = document.title = metadata.name;
myFile = blob;
myDataType = metadata.type;
var defaultName = Cryptpad.getDefaultName(Cryptpad.parsePadUrl(window.location.href));
Title.updateTitle(title || defaultName);
APP.toolbar.title.show();
console.log(title);
Cryptpad.log(Messages._getKey('upload_success', [title]));
queue.inProgress = false;
queue.next();
});
};
Cryptpad.uploadStatus(estimate, function (e, pending) {
if (e) {
queue.inProgress = false;
queue.next();
if (e === 'TOO_LARGE') {
// TODO update table to say too big?
return void Cryptpad.alert(Messages.upload_tooLarge);
}
if (e === 'NOT_ENOUGH_SPACE') {
// TODO update table to say not enough space?
return void Cryptpad.alert(Messages.upload_notEnoughSpace);
}
console.error(e);
return void Cryptpad.alert(Messages.upload_serverError);
}
if (pending) {
// TODO keep this message in case of pending files in another window?
return void Cryptpad.confirm(Messages.upload_uploadPending, function (yes) {
if (!yes) { return; }
Cryptpad.uploadCancel(function (e, res) {
if (e) {
return void console.error(e);
}
console.log(res);
next(again);
});
});
}
next(again);
});
};
var prettySize = function (bytes) {
var kB = Cryptpad.bytesToKilobytes(bytes);
if (kB < 1024) { return kB + Messages.KB; }
var mB = Cryptpad.bytesToMegabytes(bytes);
return mB + Messages.MB;
};
queue.next = function () {
if (queue.queue.length === 0) { return; }
if (queue.inProgress) { return; }
var file = queue.queue.shift();
upload(file.blob, file.metadata, file.id);
};
queue.push = function (obj) {
var id = uid();
obj.id = id;
queue.queue.push(obj);
$table.show();
var estimate = FileCrypto.computeEncryptedSize(obj.blob.byteLength, obj.metadata);
var $progressBar = $('<div>', {'class':'progressContainer'});
var $progressValue = $('<span>', {'class':'progressValue'}).text(Messages.upload_pending);
var $tr = $('<tr>', {id: id}).appendTo($table);
var $cancel = $('<span>', {'class': 'cancel fa fa-times'}).click(function () {
queue.queue = queue.queue.filter(function (el) { return el.id !== id; });
$cancel.remove();
$tr.find('.upCancel').text('-');
$tr.find('.progressValue').text(Messages.upload_cancelled);
});
var $link = $('<a>', {
'class': 'upLink',
}).text(obj.metadata.name);
$('<td>').append($link).appendTo($tr);
$('<td>').text(prettySize(estimate)).appendTo($tr);
$('<td>', {'class': 'upProgress'}).append($progressBar).append($progressValue).appendTo($tr);
$('<td>', {'class': 'upCancel'}).append($cancel).appendTo($tr);
queue.next();
};
*/
var uploadMode = false; var uploadMode = false;
var andThen = function () { var andThen = function () {
@ -330,21 +158,6 @@ define([
display: 'block', display: 'block',
}); });
/*var handleFile = function (file) {
console.log(file);
var reader = new FileReader();
reader.onloadend = function () {
queue.push({
blob: this.result,
metadata: {
name: file.name,
type: file.type,
}
});
};
reader.readAsArrayBuffer(file);
};*/
var FM = Cryptpad.createFileManager(); var FM = Cryptpad.createFileManager();
$form.find("#file").on('change', function (e) { $form.find("#file").on('change', function (e) {

Loading…
Cancel
Save