From 5d6ebdfee6174b5f7670098205a3d6d427cd92af Mon Sep 17 00:00:00 2001 From: yflory Date: Thu, 26 Nov 2020 18:15:36 +0100 Subject: [PATCH] Make autodownload size for mediatags configurable --- .../src/less2/include/sidebar-layout.less | 2 +- www/common/inner/common-mediatag.js | 9 ++- www/common/media-tag.js | 3 +- www/common/sframe-common.js | 6 ++ www/file/inner.js | 3 - www/settings/app-settings.less | 4 ++ www/settings/inner.js | 56 ++++++++++++++++++- 7 files changed, 76 insertions(+), 7 deletions(-) diff --git a/customize.dist/src/less2/include/sidebar-layout.less b/customize.dist/src/less2/include/sidebar-layout.less index ace7350df..4273b0b9a 100644 --- a/customize.dist/src/less2/include/sidebar-layout.less +++ b/customize.dist/src/less2/include/sidebar-layout.less @@ -118,7 +118,7 @@ //border-radius: 0 0.25em 0.25em 0; //border: 1px solid #adadad; border-left: 0px; - height: @variables_input-height; + height: 40px; margin: 0 !important; } } diff --git a/www/common/inner/common-mediatag.js b/www/common/inner/common-mediatag.js index 741529de0..86900f5bb 100644 --- a/www/common/inner/common-mediatag.js +++ b/www/common/inner/common-mediatag.js @@ -17,11 +17,18 @@ define([ var Nacl = window.nacl; // 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) { MediaTag.setDefaultConfig('pdf', { 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 ) var avatars = {}; @@ -68,7 +75,7 @@ define([ childList: true, characterData: false }); - MediaTag($tag[0]).on('error', function (data) { + MediaTag($tag[0], {force: true}).on('error', function (data) { console.error(data); }); }; diff --git a/www/common/media-tag.js b/www/common/media-tag.js index 4318ca8f6..56e0f6bc6 100644 --- a/www/common/media-tag.js +++ b/www/common/media-tag.js @@ -566,7 +566,8 @@ 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) { if (err) { if (err === "XHR_ERROR 404") { diff --git a/www/common/sframe-common.js b/www/common/sframe-common.js index 7a00516a5..328bd70c8 100644 --- a/www/common/sframe-common.js +++ b/www/common/sframe-common.js @@ -809,6 +809,12 @@ define([ var privateData = ctx.metadataMgr.getPrivateData(); 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 { var feedback = privateData.feedbackAllowed; Feedback.init(feedback); diff --git a/www/file/inner.js b/www/file/inner.js index 137ca54b1..6cc129de5 100644 --- a/www/file/inner.js +++ b/www/file/inner.js @@ -39,9 +39,6 @@ define([ var Nacl = window.nacl; var APP = window.APP = {}; - MediaTag.setDefaultConfig('download', { - text: Messages.download_mt_button - }); var andThen = function (common) { var $appContainer = $('#cp-app-file-content'); diff --git a/www/settings/app-settings.less b/www/settings/app-settings.less index 1f0da1263..0ac3d10f2 100644 --- a/www/settings/app-settings.less +++ b/www/settings/app-settings.less @@ -74,6 +74,10 @@ margin-right: 100%; } } + & > .fa { + align-self: center; + margin-right: -16px; + } } .cp-settings-info-block { [type="text"] { diff --git a/www/settings/inner.js b/www/settings/inner.js index 8882f5861..9ff57aae7 100644 --- a/www/settings/inner.js +++ b/www/settings/inner.js @@ -51,7 +51,7 @@ define([ 'cp-settings-info-block', 'cp-settings-displayname', 'cp-settings-language-selector', - 'cp-settings-resettips', + 'cp-settings-mediatag-size', 'cp-settings-change-password', 'cp-settings-delete' ], @@ -62,6 +62,7 @@ define([ 'cp-settings-userfeedback', ], 'drive': [ + 'cp-settings-resettips', 'cp-settings-drive-duplicate', 'cp-settings-thumbnails', 'cp-settings-drive-backup', @@ -576,6 +577,59 @@ define([ cb(form); }, 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 = $('
', { + 'class': 'cp-sidebarlayout-input-block', + }); + + var spinner; + var $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 makeBlock('safe-links', function(cb) {