Merge branch 'staging' of github.com:xwiki-labs/cryptpad into staging

pull/1/head
ansuz 8 years ago
commit 06eceed8b3

@ -21,14 +21,9 @@
data-localization="download_button"></label> data-localization="download_button"></label>
<span class="block" id="progress"></span> <span class="block" id="progress"></span>
</div> </div>
<!--<table id="status" style="display: none;"> <div id="download-view" style="display: none;">
<tr> <media-tag id="encryptedFile"></media-tag>
<td data-localization="upload_name">File name</td> </div>
<td data-localization="upload_size">Size</td>
<td data-localization="upload_progress">Progress</td>
<td data-localization="cancel">Cancel</td>
</tr>
</table>-->
<div id="feedback" class="block hidden"> <div id="feedback" class="block hidden">
</div> </div>
</body> </body>

@ -23,6 +23,7 @@ define([
var $iframe = $('#pad-iframe').contents(); var $iframe = $('#pad-iframe').contents();
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 $dlview = $iframe.find('#download-view');
var $label = $form.find('label'); var $label = $form.find('label');
var $progress = $iframe.find('#progress'); var $progress = $iframe.find('#progress');
var $body = $iframe.find('body'); var $body = $iframe.find('body');
@ -94,7 +95,6 @@ define([
Title.updateTitle(Cryptpad.initialName || getTitle() || Title.defaultTitle); Title.updateTitle(Cryptpad.initialName || getTitle() || Title.defaultTitle);
if (!uploadMode) { if (!uploadMode) {
$dlform.show();
var src = Cryptpad.getBlobPathFromHex(hexFileName); var src = Cryptpad.getBlobPathFromHex(hexFileName);
var cryptKey = secret.keys && secret.keys.fileKeyStr; var cryptKey = secret.keys && secret.keys.fileKeyStr;
var key = Nacl.util.decodeBase64(cryptKey); var key = Nacl.util.decodeBase64(cryptKey);
@ -104,42 +104,81 @@ define([
var title = document.title = metadata.name; var title = document.title = metadata.name;
Title.updateTitle(title || Title.defaultTitle); Title.updateTitle(title || Title.defaultTitle);
Cryptpad.removeLoadingScreen(); var displayFile = function (ev) {
var decrypting = false; var $mt = $dlview.find('media-tag');
$dlform.find('#dl, #progress').click(function () { var cryptKey = secret.keys && secret.keys.fileKeyStr;
if (decrypting) { return; } var hexFileName = Cryptpad.base64ToHex(secret.channel);
if (myFile) { return void exportFile(); } $mt.attr('src', '/blob/' + hexFileName.slice(0,2) + '/' + hexFileName);
decrypting = true; $mt.attr('data-crypto-key', 'cryptpad:'+cryptKey);
return Cryptpad.fetch(src, function (e, u8) { $(window.document).on('decryption', function (e) {
if (e) { var decrypted = e.originalEvent;
decrypting = false; if (decrypted.callback) { decrypted.callback(); }
return void Cryptpad.alert(e); $dlview.show();
} $dlform.hide();
if (ev) {
// now decrypt the u8 var $dlButton = $dlview.find('media-tag button');
if (!u8 || !u8.length) { $dlButton.click();
return void Cryptpad.errorLoadingScreen(e);
} }
Cryptpad.removeLoadingScreen();
})
.on('decryptionError', function (e) {
var error = e.originalEvent;
Cryptpad.alert(error.message);
})
.on('decryptionProgress', function (e) {
var progress = e.originalEvent;
var p = progress.percent +'%';
$progress.width(p);
console.log(progress.percent);
});
FileCrypto.decrypt(u8, key, function (e, data) { require(['/common/media-tag.js'], function (MediaTag) {
if (e) { /**
decrypting = false; * Allowed mime types that have to be set for a rendering after a decryption.
return console.error(e); *
} * @type {Array}
console.log(data); */
var title = document.title = data.metadata.name; var allowedMediaTypes = [
myFile = data.content; 'image/png',
myDataType = data.metadata.type; 'image/jpeg',
Title.updateTitle(title || Title.defaultTitle); 'image/jpg',
exportFile(); 'image/gif',
decrypting = false; 'audio/mp3',
}, function (progress) { 'audio/ogg',
var p = progress * 100 +'%'; 'audio/wav',
$progress.width(p); 'audio/webm',
console.error(progress); 'video/mp4',
}); 'video/ogg',
'video/webm',
'application/pdf',
'application/dash+xml',
'download'
];
MediaTag.CryptoFilter.setAllowedMediaTypes(allowedMediaTypes);
MediaTag($mt[0]);
}); });
};
var todoBigFile = function (sizeMb) {
$dlform.show();
Cryptpad.removeLoadingScreen();
var decrypting = false;
var onClick = function () {
if (decrypting) { return; }
if (myFile) { return void exportFile(); }
decrypting = true;
displayFile();
};
if (sizeMb < 5) { return void onClick(); }
Cryptpad.removeLoadingScreen();
$dlform.find('#dl, #progress').click(onClick);
};
Cryptpad.getFileSize(window.location.href, function (e, data) {
if (e) { return void Cryptpad.errorLoadingScreen(e); }
var size = Cryptpad.bytesToMegabytes(data);
return void todoBigFile(size);
}); });
}); });
return; return;

Loading…
Cancel
Save