git ssb

7+

dinoworm 🐛 / patchcore



Commit 6a1ec9be0f3c544079ea2f1f3ce62cb7c99790bc

add blob.html.input

Matt McKegg committed on 2/17/2017, 7:38:36 AM
Parent: e27e70352cba6473b977def38c6e840f5212fad4

Files changed

package.jsonchanged
blob.jsdeleted
blob/html/input.jsadded
blob/sync/url.jsadded
package.jsonView
@@ -36,8 +36,10 @@
3636 "pull-abortable": "^4.1.0",
3737 "pull-cat": "^1.1.11",
3838 "pull-reconnect": "0.0.3",
3939 "pull-stream": "^3.5.0",
40 + "simple-mime": "^0.1.0",
41 + "split-buffer": "^1.0.0",
4042 "ssb-avatar": "^0.2.0",
4143 "ssb-client": "^4.4.0",
4244 "ssb-config": "^2.2.0",
4345 "ssb-feed": "^2.3.0",
blob.jsView
@@ -1,9 +1,0 @@
1-const nest = require('depnest')
2-
3-exports.gives = nest('blob.sync.url')
4-
5-exports.create = function (api) {
6- return nest('blob.sync.url', function (id) {
7- return id
8- })
9-}
blob/html/input.jsView
@@ -1,0 +1,36 @@
1 +var h = require('mutant/h')
2 +var pull = require('pull-stream')
3 +var mime = require('simple-mime')('application/octect-stream')
4 +var split = require('split-buffer')
5 +var nest = require('depnest')
6 +
7 +module.exports = {
8 + needs: nest({
9 + 'sbot.async.addBlob': 'first'
10 + }),
11 + gives: nest('blob.html.input'),
12 + create: function (api) {
13 + return nest('blob.html.input', function FileInput (onAdded) {
14 + return h('input', { type: 'file',
15 + 'ev-change': function (ev) {
16 + var file = ev.target.files[0]
17 + if (!file) return
18 + var reader = new global.FileReader()
19 + reader.onload = function () {
20 + var stream = pull.values(split(new Buffer(reader.result), 64 * 1024))
21 + api.sbot.async.addBlob(stream, function (err, blob) {
22 + if (err) return console.error(err)
23 + onAdded({
24 + link: blob,
25 + name: file.name,
26 + size: reader.result.length || reader.result.byteLength,
27 + type: mime(file.name)
28 + })
29 + })
30 + }
31 + reader.readAsArrayBuffer(file)
32 + }
33 + })
34 + })
35 + }
36 +}
blob/sync/url.jsView
@@ -1,0 +1,9 @@
1 +const nest = require('depnest')
2 +
3 +exports.gives = nest('blob.sync.url')
4 +
5 +exports.create = function (api) {
6 + return nest('blob.sync.url', function (id) {
7 + return id
8 + })
9 +}

Built with git-ssb-web