Commit 5285e716749369d47e938077f6d87389eb282ba9
initial file-picker
austinfrey committed on 4/12/2019, 5:02:46 AMParent: 90dfad001a91b412a745a9cad0dccf4a3ef49dc2
Files changed
bin.js | changed |
mvd/index.js | changed |
mvd/views.js | changed |
package.json | changed |
file-picker/index.js | added |
bin.js | ||
---|---|---|
@@ -9,8 +9,9 @@ | ||
9 | 9 … | const muxrpcli = require('muxrpcli') |
10 | 10 … | const {pull, values, once} = require('pull-stream') |
11 | 11 … | const toPull = require('stream-to-pull-stream') |
12 | 12 … | const webresolve = require('ssb-web-resolver') |
13 … | +const h = require('hyperscript') | |
13 | 14 … | |
14 | 15 … | var SEC = 1e3 |
15 | 16 … | var MIN = 60*SEC |
16 | 17 … | |
@@ -60,17 +61,17 @@ | ||
60 | 61 … | send.address = 'ws://100.115.92.2:8989~shs:VelntasZy86CuIihzSpkzPvIOYgyu3FO3NZww/UOirk=' |
61 | 62 … | |
62 | 63 … | var m = urlIdRegex.exec(req.url) |
63 | 64 … | |
64 | - function onError(err) { if (err) console.error('[viewer]', err) } | |
65 … | + function onError(err) { if (err) console.error('ERROR', err) } | |
65 | 66 … | |
66 | 67 … | if(req.url == '/') { |
67 | 68 … | var filePath = path.join(__dirname, 'localhost/build/index.html') |
68 | 69 … | |
69 | 70 … | return pull(file(filePath), toPull(res, onError)) |
70 | 71 … | } |
71 | 72 … | if(req.url == '/mvd') { |
72 | - var filePath = path.join(__dirname, 'build/index.html') | |
73 … | + var filePath = path.join(__dirname, 'mvd/build/index.html') | |
73 | 74 … | |
74 | 75 … | return pull(file(filePath), toPull(res, onError)) |
75 | 76 … | } |
76 | 77 … | if(req.url.startsWith('/web/')) { |
@@ -90,18 +91,49 @@ | ||
90 | 91 … | |
91 | 92 … | function serveWeb (req, res, url) { |
92 | 93 … | var self = this |
93 | 94 … | var id = decodeURIComponent(url.substr(1)) |
95 … | + var components = url.split('/') | |
94 | 96 … | |
95 | - var components = url.split('/') | |
96 | 97 … | if (components[0] === '') components.shift() |
97 | 98 … | if (components[0] === 'web') components.shift() |
99 … | + | |
98 | 100 … | components[0] = decodeURIComponent(components[0]) |
99 | 101 … | |
102 … | + var initId = components[0] | |
103 … | + var pathArray = [...components].slice(1) | |
104 … | + var restOfPath = pathArray[0] ? pathArray.join('/') + '/' : '' | |
105 … | + | |
100 | 106 … | webresolve(sbot, components, function (err, data) { |
101 | 107 … | if (err) return respond(res, 404, 'ERROR: ' + err) |
102 | 108 … | |
109 … | + if (data.slice(2, 7).toString() === 'links') { | |
110 … | + const dir = JSON.parse(data) | |
111 … | + const entries = Object.keys(dir.links).map(key => { | |
112 … | + const urlPath = '/web/' | |
113 … | + + encodeURIComponent(initId) | |
114 … | + + '/' | |
115 … | + + restOfPath | |
116 … | + + key | |
103 | 117 … | |
118 … | + return h('div', [ | |
119 … | + h('img', { | |
120 … | + src: (key.indexOf('.') > -1) | |
121 … | + ? '/img/emoji/page_with_curl.png' | |
122 … | + : '/img/emoji/file_folder.png', | |
123 … | + style: { | |
124 … | + width: '15px', | |
125 … | + height: 'auto' | |
126 … | + } | |
127 … | + }), | |
128 … | + h('a', {href: urlPath}, key) | |
129 … | + ]) | |
130 … | + }) | |
131 … | + | |
132 … | + var html = h('div', entries) | |
133 … | + | |
134 … | + return pull(once(html.outerHTML), toPull(res, onError)) | |
135 … | + } | |
104 | 136 … | return pull(once(data), toPull(res)) |
105 | 137 … | }) |
106 | 138 … | } |
107 | 139 … | }) |
mvd/index.js | ||
---|---|---|
@@ -54,9 +54,9 @@ | ||
54 | 54 … | h('li', h('a', {href: '#wall/' + id }, 'Wall')), |
55 | 55 … | h('li', h('a', {href: '#queue'}, 'Queue')), |
56 | 56 … | h('li', h('a', {href: '#key' }, 'Key')), |
57 | 57 … | h('li.right', h('a', {href: 'http://gitmx.com/#%NPNNvcnTMZUFZSWl/2Z4XX+YSdqsqOhyPacp+lgpQUw=.sha256'}, '?')), |
58 | - h('form.search', { | |
58 … | + h('form.search', { | |
59 | 59 … | onsubmit: function (e) { |
60 | 60 … | if (search.value[0] == '#') |
61 | 61 … | window.location.hash = '#' + search.value |
62 | 62 … | else |
mvd/views.js | ||
---|---|---|
@@ -512,9 +512,9 @@ | ||
512 | 512 … | } |
513 | 513 … | |
514 | 514 … | pull( |
515 | 515 … | createStream({ |
516 | - limit: 1000, | |
516 … | + limit: 1000, // this needs to be a high number for scrollign to work! | |
517 | 517 … | reverse: true, |
518 | 518 … | live: false, |
519 | 519 … | query: [{$filter: { value: { timestamp: { $gt: 0 }}}}] |
520 | 520 … | }), |
@@ -537,10 +537,9 @@ | ||
537 | 537 … | if (msg.value) { |
538 | 538 … | if (msg.value.timestamp > Date.now()) { |
539 | 539 … | return h('div.future') |
540 | 540 … | } else { |
541 | - var node = render(msg) | |
542 | - return node | |
541 … | + return render(msg) | |
543 | 542 … | } |
544 | 543 … | } |
545 | 544 … | }) |
546 | 545 … | ) |
@@ -656,9 +655,9 @@ | ||
656 | 655 … | function hash () { |
657 | 656 … | return window.location.hash.substring(1) |
658 | 657 … | } |
659 | 658 … | |
660 | -module.exports = function () { | |
659 … | +module.exports = function (mount) { | |
661 | 660 … | var src = hash() |
662 | 661 … | |
663 | 662 … | if (src.substring(52, 59) == '?unbox=') { |
664 | 663 … | privateMsg(src) |
package.json | ||
---|---|---|
@@ -4,36 +4,30 @@ | ||
4 | 4 … | "description": "minimum viable decent", |
5 | 5 … | "main": "index.js", |
6 | 6 … | "scripts": { |
7 | 7 … | "start": "node bin server", |
8 | - "decent": "node bin server --appname=decent", | |
9 | - "ssb": "node bin server --appname=ssb", | |
10 | - "testnet": "node bin server --appname=testnet", | |
11 | - "build:mvd": "node mvd/style.js && mkdir -p build && browserify mvd/index.js | indexhtmlify > build/index.html", | |
12 | - "build:localhost": "browserify localhost/index.js -t sheetify | indexhtmlify > localhost/build/index.html" | |
8 … | + "testnet": "ssb_appname=ssb_testnet node bin server", | |
9 … | + "build:mvd": "node mvd/style.js && mkdir -p mvd/build && browserify mvd/index.js | indexhtmlify > mvd/build/index.html", | |
10 … | + "build:localhost": "browserify localhost/index.js -t sheetify | indexhtmlify > localhost/build/index.html", | |
11 … | + "publish:mvd": "ssb-webify publish mvd/build" | |
13 | 12 … | }, |
14 | 13 … | "devDependencies": { |
15 | 14 … | "browserify": "^16.2.2", |
16 | 15 … | "indexhtmlify": "^1.3.1" |
17 | 16 … | }, |
18 | 17 … | "author": "Ev Bogue <ev@evbogue.com>", |
19 | 18 … | "license": "MIT", |
20 | 19 … | "dependencies": { |
21 | - "broadcast-stream": "^0.2.2", | |
22 | - "chloride": "^2.2.14", | |
23 | 20 … | "dataurl-": "^0.1.0", |
24 | 21 … | "deep-extend": "^0.6.0", |
25 | 22 … | "diff": "^3.5.0", |
26 | - "emoji-server": "^1.0.0", | |
27 | 23 … | "human-time": "0.0.1", |
28 | 24 … | "hyperfile": "^2.0.0", |
29 | 25 … | "hyperloadmore": "^1.1.0", |
30 | 26 … | "hyperscript": "^2.0.2", |
31 | 27 … | "hyperscroll": "^1.0.0", |
32 | 28 … | "inu-engine": "^1.0.0-pre.0", |
33 | - "multiblob-http": "^0.4.2", | |
34 | 29 … | "muxrpcli": "^1.1.0", |
35 | - "nanomorph": "^5.4.0", | |
36 | 30 … | "non-private-ip": "^1.4.3", |
37 | 31 … | "open": "^6.1.0", |
38 | 32 … | "os-homedir": "^1.0.2", |
39 | 33 … | "patch-package": "^6.1.0", |
file-picker/index.js | ||
---|---|---|
@@ -1,0 +1,32 @@ | ||
1 … | +const h = require('hyperscript') | |
2 … | + | |
3 … | +module.exports = function (err, data) { | |
4 … | + if (err) return respond(res, 404, 'ERROR: ' + err) | |
5 … | + | |
6 … | + if (data.slice(2, 7).toString() === 'links') { | |
7 … | + const dir = JSON.parse(data) | |
8 … | + const entries = Object.keys(dir.links).map(key => { | |
9 … | + const urlPath = '/web/' | |
10 … | + + encodeURIComponent(initId) | |
11 … | + + '/' | |
12 … | + + restOfPath | |
13 … | + + key | |
14 … | + | |
15 … | + return h('div', [ | |
16 … | + h('img', { | |
17 … | + src: '/img/emoji/file_folder.png', | |
18 … | + style: { | |
19 … | + width: '15px', | |
20 … | + height: 'auto' | |
21 … | + } | |
22 … | + }), | |
23 … | + h('a', {href: urlPath}, key) | |
24 … | + ]) | |
25 … | + }) | |
26 … | + | |
27 … | + var html = h('div', entries) | |
28 … | + | |
29 … | + return pull(once(html.outerHTML), toPull(res, onError)) | |
30 … | + } | |
31 … | + return pull(once(data), toPull(res)) | |
32 … | +} |
Built with git-ssb-web