Commit 42429c62406fd68f3e1e166a77c05433cf34801e
new blogs content are stored as blobs
Dominic Tarr committed on 12/6/2017, 11:37:24 PMParent: 2b1e0cfa2f8ffcddd87d0ea71797a535a1352003
Files changed
app/page/blogNew.js | changed |
message/html/compose.js | changed |
app/page/blogNew.js | ||
---|---|---|
@@ -1,7 +1,8 @@ | ||
1 | 1 | const nest = require('depnest') |
2 | 2 | const { h, Struct, Value } = require('mutant') |
3 | 3 | const addSuggest = require('suggest-box') |
4 | +const pull = require('pull-stream') | |
4 | 5 | |
5 | 6 | exports.gives = nest('app.page.blogNew') |
6 | 7 | |
7 | 8 | exports.needs = nest({ |
@@ -9,15 +10,16 @@ | ||
9 | 10 | 'channel.async.suggest': 'first', |
10 | 11 | 'history.sync.push': 'first', |
11 | 12 | 'message.html.compose': 'first', |
12 | 13 | 'translations.sync.strings': 'first', |
14 | + 'sbot.async.addBlob': 'first' | |
13 | 15 | }) |
14 | 16 | |
15 | 17 | exports.create = (api) => { |
16 | 18 | var contentHtmlObs |
17 | 19 | |
18 | 20 | return nest('app.page.blogNew', blogNew) |
19 | - | |
21 | + | |
20 | 22 | function blogNew (location) { |
21 | 23 | const strings = api.translations.sync.strings() |
22 | 24 | const getChannelSuggestions = api.channel.async.suggest() |
23 | 25 | |
@@ -27,16 +29,31 @@ | ||
27 | 29 | title: Value(), |
28 | 30 | }) |
29 | 31 | |
30 | 32 | const composer = api.message.html.compose( |
31 | - { meta, placeholder: strings.blogNew.actions.writeBlog, shrink: false }, | |
33 | + { | |
34 | + meta, | |
35 | + placeholder: strings.blogNew.actions.writeBlog, | |
36 | + shrink: false, | |
37 | + prepublish: function (content, cb) { | |
38 | + var stream = pull.values([content.text]) | |
39 | + delete content.text | |
40 | + api.sbot.async.addBlob(stream, function (err, hash) { | |
41 | + if(err) return cb(err) | |
42 | + if(!hash) throw new Error('missing hash') | |
43 | + content.blog = hash | |
44 | + cb(null, content) | |
45 | + }) | |
46 | + } | |
47 | + }, | |
32 | 48 | (err, msg) => api.history.sync.push(err ? err : msg) |
33 | 49 | ) |
34 | 50 | |
35 | 51 | const channelInput = h('input', { |
36 | 52 | 'ev-input': e => meta.channel.set(e.target.value), |
37 | 53 | placeholder: strings.channel |
38 | 54 | }) |
55 | + | |
39 | 56 | var page = h('Page -blogNew', [ |
40 | 57 | api.app.html.context(location), |
41 | 58 | h('div.content', [ |
42 | 59 | h('div.container', [ |
@@ -84,4 +101,5 @@ | ||
84 | 101 | |
85 | 102 | return page |
86 | 103 | } |
87 | 104 | } |
105 | + |
message/html/compose.js | ||
---|---|---|
@@ -22,9 +22,9 @@ | ||
22 | 22 | exports.create = function (api) { |
23 | 23 | return nest('message.html.compose', compose) |
24 | 24 | |
25 | 25 | function compose (options, cb) { |
26 | - var { | |
26 | + var { | |
27 | 27 | meta, // required |
28 | 28 | placeholder, |
29 | 29 | shrink = true, |
30 | 30 | canAttach = true, canPreview = true, |
@@ -151,21 +151,17 @@ | ||
151 | 151 | if (!content.channel) delete content.channel |
152 | 152 | if (!mentions.length) delete content.mentions |
153 | 153 | if (content.recps && content.recps.length === 0) delete content.recps |
154 | 154 | |
155 | - try { | |
156 | - if (typeof prepublish === 'function') { | |
157 | - content = prepublish(content) | |
158 | - } | |
159 | - } catch (err) { | |
160 | - publishBtn.disabled = false | |
161 | - handleErr(err) | |
155 | + if (typeof prepublish === 'function') { | |
156 | + prepublish(content, function (err, content) { | |
157 | + if(err) handleErr(err) | |
158 | + else api.message.async.publish(content, done) | |
159 | + }) | |
162 | 160 | } |
161 | + else | |
162 | + api.message.async.publish(content, done) | |
163 | 163 | |
164 | - // debugger | |
165 | - return api.message.async.publish(content, done) | |
166 | - // return api.message.html.confirm(content, done) | |
167 | - | |
168 | 164 | function done (err, msg) { |
169 | 165 | publishBtn.disabled = false |
170 | 166 | if (err) handleErr(err) |
171 | 167 | else if (msg) { |
@@ -175,11 +171,16 @@ | ||
175 | 171 | if (cb) cb(err, msg) |
176 | 172 | } |
177 | 173 | |
178 | 174 | function handleErr (err) { |
175 | + publishBtn.disabled = false | |
179 | 176 | if (cb) cb(err) |
180 | 177 | else throw err |
181 | 178 | } |
182 | 179 | } |
183 | 180 | } |
184 | 181 | } |
185 | 182 | |
183 | + | |
184 | + | |
185 | + | |
186 | + |
Built with git-ssb-web