Make autodownload size for mediatags configurable

pull/1/head
yflory 4 years ago
parent 7448fa93df
commit 5d6ebdfee6

@ -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;
} }
} }

@ -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);
}); });
}; };

@ -566,7 +566,8 @@
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) {
if (err === "XHR_ERROR 404") { if (err === "XHR_ERROR 404") {

@ -809,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');

@ -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) {

Loading…
Cancel
Save