aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2017-05-30 10:31:38 -1000
committercel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2017-05-30 10:46:41 -1000
commit04e050fadf375a002f0bb294bab795a4f9389e42 (patch)
tree8e606b19cbbab74a7d5d2e42413189b38da8ef85
parentcb3aa7e2332964780e817185c05d6f98870496d7 (diff)
downloadpatchfoo-04e050fadf375a002f0bb294bab795a4f9389e42.tar.gz
patchfoo-04e050fadf375a002f0bb294bab795a4f9389e42.zip
Show warning if blob or emoji is large
-rw-r--r--lib/serve.js23
-rw-r--r--lib/util.js4
2 files changed, 27 insertions, 0 deletions
diff --git a/lib/serve.js b/lib/serve.js
index 6aed742..1b1ab0a 100644
--- a/lib/serve.js
+++ b/lib/serve.js
@@ -2104,6 +2104,7 @@ Serve.prototype.composer = function (opts, cb) {
function preview(raw, cb) {
var msgContainer = h('table.ssb-msgs')
var contentInput = h('input', {type: 'hidden', name: 'content'})
+ var warningsContainer = h('div')
var content
try { content = JSON.parse(data.text) }
@@ -2123,6 +2124,27 @@ Serve.prototype.composer = function (opts, cb) {
}
}
if (content.recps) msg.value.private = true
+
+ var warnings = []
+ u.toLinkArray(content.mentions).forEach(function (link) {
+ 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 >= 10e6 && link.type) {
+ // if link.type is set, we probably just uploaded this blob
+ warnings.push(h('li',
+ 'attachment ',
+ h('code', String(link.link).substr(0, 8) + '…'),
+ ' is >10MB'))
+ }
+ })
+ if (warnings.length) {
+ warningsContainer.appendChild(h('div', h('em', 'warning:')))
+ warningsContainer.appendChild(h('ul.mentions', warnings))
+ }
+
pull(
pull.once(msg),
self.app.unboxMessages(),
@@ -2137,6 +2159,7 @@ Serve.prototype.composer = function (opts, cb) {
contentInput,
opts.redirectToPublishedMsg ? h('input', {type: 'hidden',
name: 'redirect_to_published_msg', value: '1'}) : '',
+ warningsContainer,
h('div', h('em', 'draft:')),
msgContainer,
h('div.composer-actions',
diff --git a/lib/util.js b/lib/util.js
index f8da640..a5f14f5 100644
--- a/lib/util.js
+++ b/lib/util.js
@@ -79,6 +79,10 @@ u.fromArray = function (arr) {
return Array.isArray(arr) && arr.length === 1 ? arr[0] : arr
}
+u.toLinkArray = function (x) {
+ return u.toArray(x).map(u.toLink).filter(u.linkDest)
+}
+
u.renderError = function(err) {
return h('div.error',
h('h3', err.name),