diff options
author | cel <cel@lOUVT+Phkvai9a/cCS/RKo+S9hnPAQdVixms/7ldpPA=.ed25519> | 2020-08-11 21:26:39 -0400 |
---|---|---|
committer | cel <cel@lOUVT+Phkvai9a/cCS/RKo+S9hnPAQdVixms/7ldpPA=.ed25519> | 2020-08-11 21:40:14 -0400 |
commit | 8667de56c81425100b274655b183def02e92725c (patch) | |
tree | 0df5de5e9e0161b0f2cb19f4fc9bb2073eb1f1c7 | |
parent | a1bdfaa7d8190ffc27ca4de93945c829f2d92c9d (diff) | |
download | patchfoo-8667de56c81425100b274655b183def02e92725c.tar.gz patchfoo-8667de56c81425100b274655b183def02e92725c.zip |
composer: show total size of linked blobs
-rw-r--r-- | lib/serve.js | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/lib/serve.js b/lib/serve.js index af57f4d..f09bd2f 100644 --- a/lib/serve.js +++ b/lib/serve.js @@ -4680,6 +4680,8 @@ Serve.prototype.composer = function (opts, cb) { var contentInput = h('input', {type: 'hidden', name: 'content'}) var warningsContainer = h('div') var sizeEl = h('span') + var blobsSizeEl = h('span') + var blobsSizeContainer = h('span') var content try { content = JSON.parse(data.text) } @@ -4712,13 +4714,16 @@ Serve.prototype.composer = function (opts, cb) { if (content.recps) msg.value.private = true var warnings = [] + var blobsSize = 0 u.toLinkArray(content.mentions).forEach(function (link) { + var isBlob = link.link[0] === '&' + if (isBlob && !isNaN(link.size)) blobsSize += link.size if (link.emoji && link.size >= 10e3) { warnings.push(h('li', 'emoji ', h('q', link.name), ' (', h('code', String(link.link).substr(0, 8) + '…'), ')' + ' is >10KB')) - } else if (link.link[0] === '&' && link.size >= 5242880) { + } else if (isBlob && link.size >= 5242880) { warnings.push(h('li', 'linked blob ', h('code', String(link.link).substr(0, 8) + '…'), @@ -4731,6 +4736,12 @@ Serve.prototype.composer = function (opts, cb) { sizeEl.innerHTML = self.app.render.formatSize(estSize) if (estSize > 8192) warnings.push(h('li', 'message is too long')) + if (blobsSize) blobsSizeContainer.appendChild(h('span', + ', ', + h('em', {title: 'total size of linked blobs'}, 'blobs:'), ' ', + self.app.render.formatSize(blobsSize) + )) + if (warnings.length) { warningsContainer.appendChild(h('div', h('em', 'warning:'))) warningsContainer.appendChild(h('ul.mentions', warnings)) @@ -4757,7 +4768,7 @@ Serve.prototype.composer = function (opts, cb) { opts.redirectToPublishedMsg ? h('input', {type: 'hidden', name: 'redirect_to_published_msg', value: '1'}) : '', warningsContainer, - h('div', h('em', 'draft:'), ' ', sizeEl), + h('div', h('em', 'draft:'), ' ', sizeEl, blobsSizeContainer), msgContainer, h('div.composer-actions', h('input', {type: 'submit', name: 'action', value: 'publish'}) |