From 8667de56c81425100b274655b183def02e92725c Mon Sep 17 00:00:00 2001 From: cel Date: Tue, 11 Aug 2020 21:26:39 -0400 Subject: composer: show total size of linked blobs --- lib/serve.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'lib/serve.js') 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'}) -- cgit v1.2.3