aboutsummaryrefslogtreecommitdiff
path: root/lib/serve.js
diff options
context:
space:
mode:
authorcel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2017-10-14 17:59:46 -1000
committercel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2017-10-14 17:59:46 -1000
commit1b5f9989da716b8083b240036f0e56e9501e090d (patch)
tree9086309d28aa574fe6cd54d07c13a58577282114 /lib/serve.js
parent7cde48e22a5a07d8824832eceeed7c0d7ea5b742 (diff)
downloadpatchfoo-1b5f9989da716b8083b240036f0e56e9501e090d.tar.gz
patchfoo-1b5f9989da716b8083b240036f0e56e9501e090d.zip
Show estimated message size and warning if too large
Diffstat (limited to 'lib/serve.js')
-rw-r--r--lib/serve.js19
1 files changed, 18 insertions, 1 deletions
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'})