Merge branch 'download' into cacheRT

pull/1/head
yflory 4 years ago
commit 0df93dca19

@ -279,7 +279,7 @@ button:not(.btn).primary:hover{
var built = false; var built = false;
var types = ['less', 'drive', 'migrate', 'sf', 'team', 'pad', 'end']; var types = ['less', 'drive', 'migrate', 'sf', 'team', 'pad', 'end'];
var current; var current, progress;
var makeList = function (data) { var makeList = function (data) {
var c = types.indexOf(data.type); var c = types.indexOf(data.type);
current = c; current = c;
@ -295,7 +295,7 @@ button:not(.btn).primary:hover{
}; };
var list = '<ul>'; var list = '<ul>';
types.forEach(function (el, i) { types.forEach(function (el, i) {
if (i >= 6) { return; } if (el === "end") { return; }
list += getLi(i); list += getLi(i);
}); });
list += '</ul>'; list += '</ul>';
@ -303,7 +303,7 @@ button:not(.btn).primary:hover{
}; };
var makeBar = function (data) { var makeBar = function (data) {
var c = types.indexOf(data.type); var c = types.indexOf(data.type);
var l = types.length; var l = types.length - 1; // don't count "end" as a type
var progress = Math.min(data.progress, 100); var progress = Math.min(data.progress, 100);
var p = (progress / l) + (100 * c / l); var p = (progress / l) + (100 * c / l);
var bar = '<div class="cp-loading-progress-bar">'+ var bar = '<div class="cp-loading-progress-bar">'+
@ -315,8 +315,13 @@ button:not(.btn).primary:hover{
var hasErrored = false; var hasErrored = false;
var updateLoadingProgress = function (data) { var updateLoadingProgress = function (data) {
if (!built || !data) { return; } if (!built || !data) { return; }
// Make sure progress doesn't go backward
var c = types.indexOf(data.type); var c = types.indexOf(data.type);
if (c < current) { return console.error(data); } if (c < current) { return console.error(data); }
if (c === current && progress > data.progress) { return console.error(data); }
progress = data.progress;
try { try {
var el1 = document.querySelector('.cp-loading-spinner-container'); var el1 = document.querySelector('.cp-loading-spinner-container');
if (el1) { el1.style.display = 'none'; } if (el1) { el1.style.display = 'none'; }

@ -118,7 +118,7 @@
//border-radius: 0 0.25em 0.25em 0; //border-radius: 0 0.25em 0.25em 0;
//border: 1px solid #adadad; //border: 1px solid #adadad;
border-left: 0px; border-left: 0px;
height: @variables_input-height; height: 40px;
margin: 0 !important; margin: 0 !important;
} }
} }

@ -65,12 +65,13 @@ define([
switch (e.which) { switch (e.which) {
case 27: // cancel case 27: // cancel
if (typeof(no) === 'function') { no(e); } if (typeof(no) === 'function') { no(e); }
$(el || window).off('keydown', handler);
break; break;
case 13: // enter case 13: // enter
if (typeof(yes) === 'function') { yes(e); } if (typeof(yes) === 'function') { yes(e); }
$(el || window).off('keydown', handler);
break; break;
} }
$(el || window).off('keydown', handler);
}; };
$(el || window).keydown(handler); $(el || window).keydown(handler);

@ -701,7 +701,7 @@ define([
}); });
}; };
common.useFile = function (Crypt, cb, optsPut) { common.useFile = function (Crypt, cb, optsPut, onProgress) {
var fileHost = Config.fileHost || window.location.origin; var fileHost = Config.fileHost || window.location.origin;
var data = common.fromFileData; var data = common.fromFileData;
var parsed = Hash.parsePadUrl(data.href); var parsed = Hash.parsePadUrl(data.href);
@ -758,7 +758,9 @@ define([
return void cb(err); return void cb(err);
} }
u8 = _u8; u8 = _u8;
})); }), function (progress) {
onProgress(progress * 50);
});
}).nThen(function (waitFor) { }).nThen(function (waitFor) {
require(["/file/file-crypto.js"], waitFor(function (FileCrypto) { require(["/file/file-crypto.js"], waitFor(function (FileCrypto) {
FileCrypto.decrypt(u8, key, waitFor(function (err, _res) { FileCrypto.decrypt(u8, key, waitFor(function (err, _res) {
@ -767,7 +769,9 @@ define([
return void cb(err); return void cb(err);
} }
res = _res; res = _res;
})); }), function (progress) {
onProgress(50 + progress * 50);
});
})); }));
}).nThen(function (waitFor) { }).nThen(function (waitFor) {
var ext = Util.parseFilename(data.title).ext; var ext = Util.parseFilename(data.title).ext;

@ -17,11 +17,18 @@ define([
var Nacl = window.nacl; var Nacl = window.nacl;
// Configure MediaTags to use our local viewer // Configure MediaTags to use our local viewer
// This file is loaded by sframe-common so the following config is used in all the inner apps
if (MediaTag) { if (MediaTag) {
MediaTag.setDefaultConfig('pdf', { MediaTag.setDefaultConfig('pdf', {
viewer: '/common/pdfjs/web/viewer.html' viewer: '/common/pdfjs/web/viewer.html'
}); });
Messages.mediatag_saveButton = "Save"; // XXX
MediaTag.setDefaultConfig('download', {
text: Messages.download_mt_button,
textDl: Messages.mediatag_saveButton
});
} }
MT.MediaTag = MediaTag;
// Cache of the avatars outer html (including <media-tag>) // Cache of the avatars outer html (including <media-tag>)
var avatars = {}; var avatars = {};
@ -68,7 +75,7 @@ define([
childList: true, childList: true,
characterData: false characterData: false
}); });
MediaTag($tag[0]).on('error', function (data) { MediaTag($tag[0], {force: true}).on('error', function (data) {
console.error(data); console.error(data);
}); });
}; };
@ -362,6 +369,10 @@ define([
}); });
}; };
Messages.pad_mediatagShare = "Share file"; // XXX
Messages.pad_mediatagOpen = "Open file"; // XXX
Messages.mediatag_notReady = "Not ready"; // XXX
var mediatagContextMenu; var mediatagContextMenu;
MT.importMediaTagMenu = function (common) { MT.importMediaTagMenu = function (common) {
if (mediatagContextMenu) { return mediatagContextMenu; } if (mediatagContextMenu) { return mediatagContextMenu; }
@ -377,6 +388,14 @@ define([
'tabindex': '-1', 'tabindex': '-1',
'data-icon': "fa-eye", 'data-icon': "fa-eye",
}, Messages.pad_mediatagPreview)), }, Messages.pad_mediatagPreview)),
h('li.cp-svg', h('a.cp-app-code-context-openin.dropdown-item', {
'tabindex': '-1',
'data-icon': "fa-external-link",
}, Messages.pad_mediatagOpen)),
h('li.cp-svg', h('a.cp-app-code-context-share.dropdown-item', {
'tabindex': '-1',
'data-icon': "fa-shhare-alt",
}, Messages.pad_mediatagShare)),
h('li', h('a.cp-app-code-context-saveindrive.dropdown-item', { h('li', h('a.cp-app-code-context-saveindrive.dropdown-item', {
'tabindex': '-1', 'tabindex': '-1',
'data-icon': "fa-cloud-upload", 'data-icon': "fa-cloud-upload",
@ -413,12 +432,29 @@ define([
} }
else if ($this.hasClass("cp-app-code-context-download")) { else if ($this.hasClass("cp-app-code-context-download")) {
var media = Util.find($mt, [0, '_mediaObject']); var media = Util.find($mt, [0, '_mediaObject']);
if (!media) { return void console.error('no media'); }
if (!media.complete) { return void UI.warn(Messages.mediatag_notReady); }
if (!(media && media._blob)) { return void console.error($mt); } if (!(media && media._blob)) { return void console.error($mt); }
window.saveAs(media._blob.content, media.name); window.saveAs(media._blob.content, media.name);
} }
else if ($this.hasClass("cp-app-code-context-open")) { else if ($this.hasClass("cp-app-code-context-open")) {
$mt.trigger('preview'); $mt.trigger('preview');
} }
else if ($this.hasClass("cp-app-code-context-openin")) {
var hash = common.getHashFromMediaTag($mt);
common.openURL(Hash.hashToHref(hash, 'file'));
}
else if ($this.hasClass("cp-app-code-context-share")) {
var data = {
file: true,
pathname: '/file/',
hashes: {
fileHash: common.getHashFromMediaTag($mt)
},
title: Util.find($mt[0], ['_mediaObject', 'name']) || ''
};
common.getSframeChannel().event('EV_SHARE_OPEN', data);
}
}); });
return m; return m;

@ -603,7 +603,8 @@ var factory = function (Cache) {
if (cfg.force) { dl(); return mediaObject; } if (cfg.force) { dl(); return mediaObject; }
var maxSize = 5 * 1024 * 1024; var maxSize = typeof(config.maxDownloadSize) === "number" ? config.maxDownloadSize
: (5 * 1024 * 1024);
getFileSize(src, function (err, size) { getFileSize(src, function (err, size) {
if (err) { if (err) {
return void error(err); return void error(err);

@ -1808,7 +1808,12 @@ define([
} }
startRealtime(); startRealtime();
cb(); cb();
}, cryptputCfg); }, cryptputCfg, function (progress) {
sframeChan.event('EV_LOADING_INFO', {
type: 'pad',
progress: progress
});
});
return; return;
} }
// Start realtime outside the iframe and callback // Start realtime outside the iframe and callback

@ -142,7 +142,7 @@ define([
} }
return; return;
}; };
funcs.importMediaTag = function ($mt) { var getMtData = function ($mt) {
if (!$mt || !$mt.is('media-tag')) { return; } if (!$mt || !$mt.is('media-tag')) { return; }
var chanStr = $mt.attr('src'); var chanStr = $mt.attr('src');
var keyStr = $mt.attr('data-crypto-key'); var keyStr = $mt.attr('data-crypto-key');
@ -154,10 +154,27 @@ define([
var channel = src.replace(/\/blob\/[0-9a-f]{2}\//i, ''); var channel = src.replace(/\/blob\/[0-9a-f]{2}\//i, '');
// Get key // Get key
var key = keyStr.replace(/cryptpad:/i, ''); var key = keyStr.replace(/cryptpad:/i, '');
return {
channel: channel,
key: key
};
};
funcs.getHashFromMediaTag = function ($mt) {
var data = getMtData($mt);
if (!data) { return; }
return Hash.getFileHashFromKeys({
version: 1,
channel: data.channel,
keys: { fileKeyStr: data.key }
});
};
funcs.importMediaTag = function ($mt) {
var data = getMtData($mt);
if (!data) { return; }
var metadata = $mt[0]._mediaObject._blob.metadata; var metadata = $mt[0]._mediaObject._blob.metadata;
ctx.sframeChan.query('Q_IMPORT_MEDIATAG', { ctx.sframeChan.query('Q_IMPORT_MEDIATAG', {
channel: channel, channel: data.channel,
key: key, key: data.key,
name: metadata.name, name: metadata.name,
type: metadata.type, type: metadata.type,
owners: metadata.owners owners: metadata.owners
@ -792,6 +809,12 @@ define([
var privateData = ctx.metadataMgr.getPrivateData(); var privateData = ctx.metadataMgr.getPrivateData();
funcs.addShortcuts(window, Boolean(privateData.app)); funcs.addShortcuts(window, Boolean(privateData.app));
var mt = Util.find(privateData, ['settings', 'general', 'mediatag-size']);
if (MT.MediaTag && typeof(mt) === "number") {
var maxMtSize = mt === -1 ? Infinity : mt * 1024 * 1024;
MT.MediaTag.setDefaultConfig('maxDownloadSize', maxMtSize);
}
try { try {
var feedback = privateData.feedbackAllowed; var feedback = privateData.feedbackAllowed;
Feedback.init(feedback); Feedback.init(feedback);

@ -39,9 +39,6 @@ define([
var Nacl = window.nacl; var Nacl = window.nacl;
var APP = window.APP = {}; var APP = window.APP = {};
MediaTag.setDefaultConfig('download', {
text: Messages.download_mt_button
});
var andThen = function (common) { var andThen = function (common) {
var $appContainer = $('#cp-app-file-content'); var $appContainer = $('#cp-app-file-content');
@ -203,7 +200,6 @@ define([
cb(); cb();
} }
}).on('progress', function (data) { }).on('progress', function (data) {
if (data.progress > 75) { return; }
var p = data.progress +'%'; var p = data.progress +'%';
$progress.width(p); $progress.width(p);
$progressTxt.text(Math.floor(data.progress) + '%'); $progressTxt.text(Math.floor(data.progress) + '%');

@ -46,6 +46,7 @@ define([
'/common/test.js', '/common/test.js',
'/bower_components/diff-dom/diffDOM.js', '/bower_components/diff-dom/diffDOM.js',
'/bower_components/file-saver/FileSaver.min.js',
'css!/customize/src/print.css', 'css!/customize/src/print.css',
'css!/bower_components/bootstrap/dist/css/bootstrap.min.css', 'css!/bower_components/bootstrap/dist/css/bootstrap.min.css',
@ -1085,6 +1086,9 @@ define([
border: Messages.pad_mediatagBorder, border: Messages.pad_mediatagBorder,
preview: Messages.pad_mediatagPreview, preview: Messages.pad_mediatagPreview,
'import': Messages.pad_mediatagImport, 'import': Messages.pad_mediatagImport,
download: Messages.download_mt_button,
share: Messages.pad_mediatagShare,
open: Messages.pad_mediatagOpen,
options: Messages.pad_mediatagOptions options: Messages.pad_mediatagOptions
}; };
Ckeditor._commentsTranslations = { Ckeditor._commentsTranslations = {
@ -1165,6 +1169,28 @@ define([
editor.plugins.mediatag.import = function($mt) { editor.plugins.mediatag.import = function($mt) {
framework._.sfCommon.importMediaTag($mt); framework._.sfCommon.importMediaTag($mt);
}; };
editor.plugins.mediatag.download = function($mt) {
var media = Util.find($mt, [0, '_mediaObject']);
if (!media) { return void console.error('no media'); }
if (!media.complete) { return void UI.warn(Messages.mediatag_notReady); }
if (!(media && media._blob)) { return void console.error($mt); }
window.saveAs(media._blob.content, media.name);
};
editor.plugins.mediatag.open = function($mt) {
var hash = framework._.sfCommon.getHashFromMediaTag($mt);
framework._.sfCommon.openURL(Hash.hashToHref(hash, 'file'));
};
editor.plugins.mediatag.share = function($mt) {
var data = {
file: true,
pathname: '/file/',
hashes: {
fileHash: framework._.sfCommon.getHashFromMediaTag($mt)
},
title: Util.find($mt[0], ['_mediaObject', 'name']) || ''
};
framework._.sfCommon.getSframeChannel().event('EV_SHARE_OPEN', data);
};
Links.init(Ckeditor, editor); Links.init(Ckeditor, editor);
}).nThen(function() { }).nThen(function() {
// Move ckeditor parts to have a structure like the other apps // Move ckeditor parts to have a structure like the other apps

@ -53,15 +53,57 @@
editor.plugins.mediatag.import($mt); editor.plugins.mediatag.import($mt);
} }
}); });
editor.addCommand('downloadMT', {
exec: function (editor) {
var w = targetWidget;
targetWidget = undefined;
var $mt = $(w.$).find('media-tag');
editor.plugins.mediatag.download($mt);
}
});
editor.addCommand('openMT', {
exec: function (editor) {
var w = targetWidget;
targetWidget = undefined;
var $mt = $(w.$).find('media-tag');
editor.plugins.mediatag.open($mt);
}
});
editor.addCommand('shareMT', {
exec: function (editor) {
var w = targetWidget;
targetWidget = undefined;
var $mt = $(w.$).find('media-tag');
editor.plugins.mediatag.share($mt);
}
});
if (editor.addMenuItems) { if (editor.addMenuItems) {
editor.addMenuGroup('mediatag'); editor.addMenuGroup('mediatag');
editor.addMenuItem('open', {
label: Messages.open,
icon: 'iframe',
command: 'openMT',
group: 'mediatag'
});
editor.addMenuItem('share', {
label: Messages.share,
icon: 'link',
command: 'shareMT',
group: 'mediatag'
});
editor.addMenuItem('importMediatag', { editor.addMenuItem('importMediatag', {
label: Messages.import, label: Messages.import,
icon: 'save', icon: 'save',
command: 'importMediatag', command: 'importMediatag',
group: 'mediatag' group: 'mediatag'
}); });
editor.addMenuItem('download', {
label: Messages.download,
icon: 'save',
command: 'downloadMT',
group: 'mediatag'
});
editor.addMenuItem('mediatag', { editor.addMenuItem('mediatag', {
label: Messages.options, label: Messages.options,
icon: 'image', icon: 'image',
@ -76,6 +118,9 @@
targetWidget = element; targetWidget = element;
return { return {
mediatag: CKEDITOR.TRISTATE_OFF, mediatag: CKEDITOR.TRISTATE_OFF,
open: CKEDITOR.TRISTATE_OFF,
share: CKEDITOR.TRISTATE_OFF,
download: CKEDITOR.TRISTATE_OFF,
importMediatag: CKEDITOR.TRISTATE_OFF, importMediatag: CKEDITOR.TRISTATE_OFF,
}; };
} }

@ -52,10 +52,10 @@ define([
: Share.getShareModal; : Share.getShareModal;
f(common, { f(common, {
origin: priv.origin, origin: priv.origin,
pathname: priv.pathname, pathname: data.pathname || priv.pathname,
password: priv.password, password: data.hashes ? '' : priv.password,
isTemplate: priv.isTemplate, isTemplate: data.hashes ? false : priv.isTemplate,
hashes: priv.hashes, hashes: data.hashes || priv.hashes,
common: common, common: common,
title: data.title, title: data.title,
versionHash: data.versionHash, versionHash: data.versionHash,
@ -64,8 +64,8 @@ define([
hideIframe(); hideIframe();
}, },
fileData: { fileData: {
hash: priv.hashes.fileHash, hash: (data.hashes && data.hashes.fileHash) || priv.hashes.fileHash,
password: priv.password password: data.hashes ? '' : priv.password
} }
}, function (e, modal) { }, function (e, modal) {
if (e) { console.error(e); } if (e) { console.error(e); }

@ -74,6 +74,10 @@
margin-right: 100%; margin-right: 100%;
} }
} }
& > .fa {
align-self: center;
margin-right: -16px;
}
} }
.cp-settings-info-block { .cp-settings-info-block {
[type="text"] { [type="text"] {

@ -51,7 +51,7 @@ define([
'cp-settings-info-block', 'cp-settings-info-block',
'cp-settings-displayname', 'cp-settings-displayname',
'cp-settings-language-selector', 'cp-settings-language-selector',
'cp-settings-resettips', 'cp-settings-mediatag-size',
'cp-settings-change-password', 'cp-settings-change-password',
'cp-settings-delete' 'cp-settings-delete'
], ],
@ -62,6 +62,7 @@ define([
'cp-settings-userfeedback', 'cp-settings-userfeedback',
], ],
'drive': [ 'drive': [
'cp-settings-resettips',
'cp-settings-drive-duplicate', 'cp-settings-drive-duplicate',
'cp-settings-thumbnails', 'cp-settings-thumbnails',
'cp-settings-drive-backup', 'cp-settings-drive-backup',
@ -576,6 +577,59 @@ define([
cb(form); cb(form);
}, true); }, true);
Messages.settings_mediatagSizeTitle = "Autodownload size in MegaBytes (MB)"; // XXX
Messages.settings_mediatagSizeHint = 'Maximum size for automatically loading media elements (images, videos, pdf) embedded into the pads. Elements bigger than the specified size can be loaded manually. Use "-1" to always load the media elements automatically.'; // XXX
makeBlock('mediatag-size', function(cb) {
var $inputBlock = $('<div>', {
'class': 'cp-sidebarlayout-input-block',
});
var spinner;
var $input = $('<input>', {
'min': -1,
'max': 1000,
type: 'number',
}).appendTo($inputBlock);
var oldVal;
var todo = function () {
var val = parseInt($input.val());
if (val === oldVal) { return; }
if (typeof(val) !== 'number') { return UI.warn(Messages.error); }
spinner.spin();
common.setAttribute(['general', 'mediatag-size'], val, function (err) {
if (err) {
spinner.hide();
console.error(err);
return UI.warn(Messages.error);
}
spinner.done();
UI.log(Messages.saved);
});
};
var $save = $(h('button.btn.btn-primary', Messages.settings_save)).appendTo($inputBlock);
spinner = UI.makeSpinner($inputBlock);
$save.click(todo);
$input.on('keyup', function(e) {
if (e.which === 13) { todo(); }
});
common.getAttribute(['general', 'mediatag-size'], function(e, val) {
if (e) { return void console.error(e); }
if (typeof(val) !== 'number') {
oldVal = 5;
$input.val(5);
} else {
oldVal = val;
$input.val(val);
}
});
cb($inputBlock);
}, true);
// Security // Security
makeBlock('safe-links', function(cb) { makeBlock('safe-links', function(cb) {

@ -397,6 +397,7 @@ define([
var fmConfig = { var fmConfig = {
body: $('body'), body: $('body'),
noStore: true, // Don't store attachments into our drive
onUploaded: function (ev, data) { onUploaded: function (ev, data) {
if (ev.callback) { if (ev.callback) {
ev.callback(data); ev.callback(data);

@ -331,10 +331,11 @@ define([
APP.FM.handleFile(blob); APP.FM.handleFile(blob);
}); });
}; };
var MAX_IMAGE_SIZE = 1 * 1024 * 1024; // 1 MB
var maxSizeStr = Messages._getKey('formattedMB', [Util.bytesToMegabytes(MAX_IMAGE_SIZE)]);
var addImageToCanvas = function (img) { var addImageToCanvas = function (img) {
// 1 MB maximum if (img.src && img.src.length > MAX_IMAGE_SIZE) {
if (img.src && img.src.length > 1 * 1024 * 1024) { UI.warn(Messages._getKey('upload_tooLargeBrief', [maxSizeStr])); // XXX update key
UI.warn(Messages.upload_tooLargeBrief);
return; return;
} }
var w = img.width; var w = img.width;
@ -356,8 +357,8 @@ define([
var file = e.target.files[0]; var file = e.target.files[0];
var reader = new FileReader(); var reader = new FileReader();
// 1 MB maximum // 1 MB maximum
if (file.size > 1 * 1024 * 1024) { if (file.size > MAX_IMAGE_SIZE) {
UI.warn(Messages.upload_tooLargeBrief); UI.warn(Messages._getKey('upload_tooLargeBrief', [maxSizeStr]));
return; return;
} }
reader.onload = function () { reader.onload = function () {

Loading…
Cancel
Save