diff options
author | cel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519> | 2019-04-14 17:55:13 -1000 |
---|---|---|
committer | cel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519> | 2019-04-14 17:55:13 -1000 |
commit | 644220073961892fb5fbd673e8c6aee488ba0ad6 (patch) | |
tree | 293e12c64b4ee3e76e05fafb979d2263dd353507 /lib | |
parent | 47422c2f0b901f475d35e7b15cc1356617b2c7ea (diff) | |
download | patchfoo-644220073961892fb5fbd673e8c6aee488ba0ad6.tar.gz patchfoo-644220073961892fb5fbd673e8c6aee488ba0ad6.zip |
Allow overriding blob mention names in composer
Diffstat (limited to 'lib')
-rw-r--r-- | lib/serve.js | 62 |
1 files changed, 40 insertions, 22 deletions
diff --git a/lib/serve.js b/lib/serve.js index a965573..c2f7cca 100644 --- a/lib/serve.js +++ b/lib/serve.js @@ -3528,13 +3528,29 @@ Serve.prototype.composer = function (opts, cb) { if (!data.action && self.query.action) data.action = self.query.action var blobs = u.tryDecodeJSON(data.blobs) || {} - if (data.upload && typeof data.upload === 'object') { - blobs[data.upload.link] = { - type: data.upload.type, - size: data.upload.size, - key: data.upload.key, + var upload = data.upload + if (upload && typeof upload === 'object') { + data.upload = null + + var href = upload.link + (upload.key ? '?unbox=' + upload.key + '.boxs': '') + var blobType = String(upload.type).split('/')[0] + var blobExt = String(upload.name).split('.').pop() + var blobPrefix = blobPrefixesByType[blobType] || blobPrefixesByExt[blobExt] || '' + var isMedia = blobPrefix || blobType === 'image' + var blobName = blobPrefix + upload.name + + blobs[upload.link] = { + type: upload.type, + size: upload.size, + name: blobName, + key: upload.key, } + + data.text = (data.text ? data.text + '\n' : '') + + (isMedia ? '!' : '') + + '[' + blobName + '](' + href + ')' } + var channel = data.channel != null ? data.channel : opts.channel var formNames = {} @@ -3554,29 +3570,19 @@ Serve.prototype.composer = function (opts, cb) { if (upload) blobs[upload.link] = { type: upload.type, size: upload.size, + name: upload.name, } } var blobIds = u.toArray(data.blob_id) var blobTypes = u.toArray(data.blob_type) + var blobNames = u.toArray(data.blob_name) for (var i = 0; i < blobIds.length && i < blobTypes.length; i++) { var id = blobIds[i] var blob = blobs[id] || (blobs[id] = {}) blob.type = blobTypes[i] - } - - if (data.upload) { - var href = data.upload.link - + (data.upload.key ? '?unbox=' + data.upload.key + '.boxs': '') - // TODO: be able to change the content-type - var blobType = String(data.upload.type).split('/')[0] - var blobExt = String(data.upload.name).split('.').pop() - var blobPrefix = blobPrefixesByType[blobType] || blobPrefixesByExt[blobExt] || '' - var isMedia = blobPrefix || blobType === 'image' - data.text = (data.text ? data.text + '\n' : '') - + (isMedia ? '!' : '') - + '[' + blobPrefix + data.upload.name + '](' + href + ')' - data.upload = null + blob.nameOverride = data['blob_name_override_' + i] + blob.name = blobNames[i] } // get bare feed names @@ -3623,7 +3629,10 @@ Serve.prototype.composer = function (opts, cb) { }) blobMentions.forEach(function (mention) { var blob = blobs[mention.link] - if (blob) mention.type = blob.type + if (blob) { + mention.type = blob.type + if (blob.nameOverride) mention.name = blob.name + } }) // strip content other than names and feed ids from the recps field @@ -3694,14 +3703,21 @@ Serve.prototype.composer = function (opts, cb) { blobMentions.length > 0 ? [ h('div', h('em', 'blobs:')), h('ul.mentions', blobMentions.map(function (link, i) { + var link1 = blobs[link.link] || {} var linkHref = self.app.render.toUrl(link.link) return h('li', - h('a', {href: linkHref}, link.name || link.link), ': ', + h('a', {href: linkHref}, h('code', String(link.link).substr(0, 8) + '…')), ' ', h('input', {name: 'blob_id', type: 'hidden', value: link.link}), h('input', {name: 'blob_type', size: 24, value: link.type, placeholder: 'application/octet-stream', - title: 'blob mime-type'})) + title: 'blob mime-type'}), + h('input', {name: 'blob_name', size: 24, + value: link.name || '', placeholder: 'name', + title: 'blob name'}), ' ', + h('input', {name: 'blob_name_override_' + i, type: 'checkbox', + value: 1, checked: link1.nameOverride ? '1' : undefined, + title: 'override name in markdown'})) })) ] : '', h('table.ssb-msgs', @@ -3785,6 +3801,8 @@ Serve.prototype.composer = function (opts, cb) { mention.size = blob.size if (blob.type && blob.type !== 'application/octet-stream') mention.type = blob.type + if (blob.nameOverride) + mention.name = blob.name } else if (mention.link === '@') { // bare feed name var name = mention.name |