Move the mediatag viewer into a media app

This commit is contained in:
yflory
2017-04-26 14:55:06 +02:00
parent 6a8274518b
commit f50aa5c29b
10 changed files with 239 additions and 20 deletions

View File

@@ -7,9 +7,11 @@ define([
'/common/visible.js',
'/common/notify.js',
'/bower_components/tweetnacl/nacl-fast.min.js',
'/bower_components/file-saver/FileSaver.min.js',
], function ($, Crypto, realtimeInput, Toolbar, Cryptpad, Visible, Notify) {
var Messages = Cryptpad.Messages;
window.Nacl = window.nacl;
var saveAs = window.saveAs;
//window.Nacl = window.nacl;
$(function () {
var ifrw = $('#pad-iframe')[0].contentWindow;
@@ -21,15 +23,14 @@ define([
var $bar = $iframe.find('.toolbar-container');
var secret = Cryptpad.getSecrets();
if (secret.keys) { throw new Error("You need a hash"); } // TODO
if (!secret.keys) { throw new Error("You need a hash"); } // TODO
var cryptKey = secret.key;
var fileId = secret.file;
var cryptKey = secret.keys && secret.keys.fileKeyStr;
var fileId = secret.channel;
var hexFileName = Cryptpad.base64ToHex(fileId);
var type = secret.type;
var type = "image/png";
// Test hash:
// #/2/K6xWU-LT9BJHCQcDCT-DcQ/TBo77200c0e-FdldQFcnQx4Y/image-png
// #/2/K6xWU-LT9BJHCQcDCT-DcQ/TBo77200c0e-FdldQFcnQx4Y/
var parsed = Cryptpad.parsePadUrl(window.location.href);
var defaultName = Cryptpad.getDefaultName(parsed);
@@ -62,26 +63,48 @@ define([
document.title = title;
};
var blob;
var exportFile = function () {
var suggestion = document.title;
Cryptpad.prompt(Messages.exportPrompt,
Cryptpad.fixFileName(suggestion) + '.html', function (filename) {
if (!(typeof(filename) === 'string' && filename)) { return; }
//var blob = new Blob([html], {type: "text/html;charset=utf-8"});
saveAs(blob, filename);
});
};
var $mt = $iframe.find('#encryptedFile');
$mt.attr('src', '/blob/' + hexFileName.slice(0,2) + '/' + hexFileName);
$mt.attr('data-crypto-key', cryptKey);
$mt.attr('data-type', type);
require(['/common/media-tag.js'], function (MediaTag) {
MediaTag($mt[0]);
Cryptpad.removeLoadingScreen();
var configTb = {
displayed: ['useradmin', 'newpad'],
displayed: ['useradmin', 'share', 'newpad'],
ifrw: ifrw,
common: Cryptpad,
title: {
onRename: renameCb,
defaultName: defaultName,
suggestName: suggestName
},
share: {
secret: secret,
channel: hexFileName
}
};
Toolbar.create($bar, null, null, null, null, configTb);
var $rightside = $bar.find('.' + Toolbar.constants.rightside);
var $export = Cryptpad.createButton('export', true, {}, exportFile);
$rightside.append($export);
updateTitle(Cryptpad.initialName || getTitle() || defaultName);
var mt = MediaTag($mt[0]);
Cryptpad.removeLoadingScreen();
});
};