From 1b5f9989da716b8083b240036f0e56e9501e090d Mon Sep 17 00:00:00 2001 From: cel Date: Sat, 14 Oct 2017 17:59:46 -1000 Subject: Show estimated message size and warning if too large --- lib/serve.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'lib/serve.js') diff --git a/lib/serve.js b/lib/serve.js index 326c6cd..07cbbbb 100644 --- a/lib/serve.js +++ b/lib/serve.js @@ -2556,6 +2556,7 @@ Serve.prototype.composer = function (opts, cb) { var msgContainer = h('table.ssb-msgs') var contentInput = h('input', {type: 'hidden', name: 'content'}) var warningsContainer = h('div') + var sizeEl = h('span') var content try { content = JSON.parse(data.text) } @@ -2590,6 +2591,22 @@ Serve.prototype.composer = function (opts, cb) { ' is >10MB')) } }) + + var draftMsg = { + key: '%0000000000000000000000000000000000000000000=.sha256', + value: { + previous: '%0000000000000000000000000000000000000000000=.sha256', + author: '@0000000000000000000000000000000000000000000=.ed25519', + sequence: 1000, + timestamp: 1000000000000, + hash: 'sha256', + content: content + } + } + var estSize = JSON.stringify(draftMsg, null, 2).length + sizeEl.innerHTML = self.app.render.formatSize(estSize) + if (estSize > 8192) warnings.push(h('li', 'message is too long')) + if (warnings.length) { warningsContainer.appendChild(h('div', h('em', 'warning:'))) warningsContainer.appendChild(h('ul.mentions', warnings)) @@ -2613,7 +2630,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:')), + h('div', h('em', 'draft:'), ' ', sizeEl), msgContainer, h('div.composer-actions', h('input', {type: 'submit', name: 'action', value: 'publish'}) -- cgit v1.2.3