git ssb

0+

mixmix / scuttle-blog



Commit 85899d9c65af617c7746ff686142b1bf2e513f20

standard

mix irving committed on 2/16/2018, 10:56:41 PM
Parent: cd8ac2d0fc9c1f5e2e287e2a0f67c68c8b2e417d

Files changed

async/fetch.jschanged
async/get.jschanged
index.jschanged
isBlog.jschanged
lib/getMsgContent.jschanged
lib/inject.jschanged
obs/get.jschanged
schema/blog.jschanged
struct.jschanged
sync/isBlog.jschanged
tests/sync/isBlog.jschanged
async/fetch.jsView
@@ -3,16 +3,16 @@
33 // TODO take blog or blogKey?
44
55 module.exports = function (server) {
66 return function fetch (blog, cb) {
7- if (!isBlog(blog)) return cb(`Not a valid blog ${JSON.stringify(blog, null, 2)}`)
7 + if (!isBlog(blog)) return cb(new Error(`Not a valid blog ${JSON.stringify(blog, null, 2)}`))
88
99 server.blobs.want(getBlob(blog), (err, success) => {
1010 if (err) {
1111 if (cb) return cb(err)
1212 else throw err
1313 }
14-
14 +
1515 cb(null, success)
1616 })
1717 }
1818 }
@@ -22,5 +22,4 @@
2222 if (msg.value.content && msg.value.content.blog) return msg.value.content.blog
2323 // is just body of the message, 'msg content'
2424 else if (msg.blog) return msg.blog
2525 }
26-
async/get.jsView
@@ -26,5 +26,4 @@
2626 )
2727 })
2828 }
2929 }
30-
index.jsView
@@ -1,14 +1,14 @@
11 const methods = {
22 async: {
33 create: require('./async/fetch'),
4- get: require('./async/get'),
4 + get: require('./async/get')
55 },
66 obs: {
7- get: require('./obs/get'),
7 + get: require('./obs/get')
88 },
99 sync: {
10- isBlog: require('./sync/isBlog'),
10 + isBlog: require('./sync/isBlog')
1111 }
1212 }
1313
1414 // Note : if you don't like this export pattern, there's no reason we can't add different mappings !!
@@ -16,6 +16,4 @@
1616
1717 module.exports = function Blog (server, opts) {
1818 return require('./lib/inject')(server, methods)
1919 }
20-
21-
isBlog.jsView
@@ -1,2 +1,1 @@
11 module.exports = require('./sync/isBlog')()
2-
lib/getMsgContent.jsView
@@ -2,5 +2,4 @@
22 if (obj.value && obj.value.content) return obj.value.content
33 else if (obj.author && obj.timestamp && obj.content) return obj.content
44 else return obj
55 }
6-
lib/inject.jsView
@@ -1,11 +1,10 @@
11 const { map } = require('libnested')
2-const { Value, onceTrue, watch } = require('mutant')
2 +const { onceTrue, watch } = require('mutant')
33 const Struct = require('../struct')
44
55 // auto-inject the ssb-server to all methods to reduce repitition
66 module.exports = function inject (server, methods) {
7-
87 switch (typeof server) {
98 case 'object': // just a calssic ssb server
109 checkPlugins(server)
1110 return map(methods, (fn, path) => fn(server))
@@ -13,10 +12,9 @@
1312 case 'function': // hopefully an observeable which will contain an ssb server
1413 return injectObsServer(server, methods)
1514
1615 default:
17- throw new Error ('scuttle-blog expects an ssb server (or obs that contains one)')
18-
16 + throw new Error('scuttle-blog expects an ssb server (or obs that contains one)')
1917 }
2018 }
2119
2220 function injectObsServer (server, methods) {
@@ -34,12 +32,12 @@
3432
3533 // NOTE - both `obs` and `sync` methods will return observeables
3634 return function () {
3735 // var result = Value({})
38- var result = Struct({})
36 + var result = Struct({}) // WARNING - this shouldn't be copied for other apps, only works with obs.get method here. Probably breaks sync.isBlog
3937 onceTrue(
4038 server,
41- server => {
39 + server => {
4240 var res = fn(server).apply(null, arguments)
4341 watch(res, res => result.set(res))
4442 }
4543 )
@@ -53,7 +51,5 @@
5351 function checkPlugins (server) {
5452 PLUGIN_DEPS.forEach(p => {
5553 if (!server[p]) throw new Error(`scuttle-blog needs a scuttlebot server with the ${p} plugin installed`)
5654 })
57-
5855 }
59-
obs/get.jsView
@@ -1,5 +1,4 @@
1-const { Struct, Value, Array: MutantArray } = require('mutant')
21 const pull = require('pull-stream')
32 const fetch = require('../async/fetch')
43 const isBlog = require('../isBlog')
54 const Blog = require('../struct')
@@ -27,6 +26,4 @@
2726
2827 return obs
2928 }
3029 }
31-
32-
schema/blog.jsView
@@ -4,13 +4,12 @@
44 $schema: 'http://json-schema.org/schema#',
55 type: 'object',
66 required: ['type', 'title', 'blog'],
77 properties: {
8- type: {type: 'string', pattern: 'blog'},
9- title: {type: 'string'},
10- blog: {type: 'string', pattern: blobIdRegex},
11- summary: {type: 'string'},
8 + type: {type: 'string', pattern: 'blog'},
9 + title: {type: 'string'},
10 + blog: {type: 'string', pattern: blobIdRegex},
11 + summary: {type: 'string'},
1212 thumbnail: {type: 'string', pattern: blobIdRegex},
13- channel: {type: 'string'},
13 + channel: {type: 'string'}
1414 }
1515 }
16-
struct.jsView
@@ -13,5 +13,4 @@
1313 // sync: Value(false),
1414 errors: MutantArray()
1515 })
1616 }
17-
sync/isBlog.jsView
@@ -14,6 +14,4 @@
1414
1515 return result
1616 }
1717 }
18-
19-
tests/sync/isBlog.jsView
@@ -1,12 +1,10 @@
11 const test = require('tape')
2-const validator = require('is-my-json-valid')
32
43 const isBlog = require('../../sync/isBlog')()
54 // or const isBlog = require('../../isBlog')
65
76 test('isBlog / blog schema', t => {
8-
97 const notBlog = {
108 type: 'post',
119 title: 'An important idea',
1210 blog: '&sfoIYo0kKKGI+TJYnznVDSs3BM/HjMWdCPXirvj9BfE=.sha256'
@@ -34,44 +32,43 @@
3432 }
3533 t.notOk(isBlog(malformedBlog), 'invalidates malformed blog')
3634
3735 const actualBlog = {
38- "key": "%GKGFNHKeUVAVPNUapE41skF3ND3Etm76XO7Y7sVeTLI=.sha256",
39- "value": {
40- "previous": "%MxC4d1BHqtBiC+mC+BaaZOAZSg41nFGOdXDpJiU+tg4=.sha256",
41- "author": "@ye+QM09iPcDJD6YvQYjoQc7sLF/IFhmNbEqgdzQo3lQ=.ed25519",
42- "sequence": 13369,
43- "timestamp": 1518568914727,
44- "hash": "sha256",
45- "content": {
46- "type": "blog",
47- "channel": "cooperative",
48- "title": "Coop-source",
49- "summary": "a day in the life of open source (and cooperatives) ",
50- "mentions": [
36 + 'key': '%GKGFNHKeUVAVPNUapE41skF3ND3Etm76XO7Y7sVeTLI=.sha256',
37 + 'value': {
38 + 'previous': '%MxC4d1BHqtBiC+mC+BaaZOAZSg41nFGOdXDpJiU+tg4=.sha256',
39 + 'author': '@ye+QM09iPcDJD6YvQYjoQc7sLF/IFhmNbEqgdzQo3lQ=.ed25519',
40 + 'sequence': 13369,
41 + 'timestamp': 1518568914727,
42 + 'hash': 'sha256',
43 + 'content': {
44 + 'type': 'blog',
45 + 'channel': 'cooperative',
46 + 'title': 'Coop-source',
47 + 'summary': 'a day in the life of open source (and cooperatives) ',
48 + 'mentions': [
5149 {
52- "link": "&wpKZTZIifFeH0P0LY3Iztgzbj17VlKXIfQNjPnoas1g=.sha256",
53- "name": "at_mention.png"
50 + 'link': '&wpKZTZIifFeH0P0LY3Iztgzbj17VlKXIfQNjPnoas1g=.sha256',
51 + 'name': 'at_mention.png'
5452 },
5553 {
56- "link": "&3S7gQpN8ZznmLzstY9AZiWZaZXFG2UaxmeE9SuKU5jk=.sha256",
57- "name": "protoflip.png"
54 + 'link': '&3S7gQpN8ZznmLzstY9AZiWZaZXFG2UaxmeE9SuKU5jk=.sha256',
55 + 'name': 'protoflip.png'
5856 },
5957 {
60- "link": "&UgzlelvbBOTj6QGaTqi/PnfkjY8wUNSzUw37/yOxMLw=.sha256",
61- "name": "protozoa_logo.png"
58 + 'link': '&UgzlelvbBOTj6QGaTqi/PnfkjY8wUNSzUw37/yOxMLw=.sha256',
59 + 'name': 'protozoa_logo.png'
6260 }
6361 ],
64- "thumbnail": "&wpKZTZIifFeH0P0LY3Iztgzbj17VlKXIfQNjPnoas1g=.sha256",
65- "blog": "&+/mENZOe+RTSn9ZsTFG7Xw0dtv05YDUpIhazYQEj48w=.sha256"
62 + 'thumbnail': '&wpKZTZIifFeH0P0LY3Iztgzbj17VlKXIfQNjPnoas1g=.sha256',
63 + 'blog': '&+/mENZOe+RTSn9ZsTFG7Xw0dtv05YDUpIhazYQEj48w=.sha256'
6664 },
67- "signature": "1WEhVT42LCdNhuf5ogpcnJfJWbFTUily666pj1XDKS07hjEKGuwZTy/pYRcl/XJJIHMH9MiRkR6FIiOIa7t1DQ==.sig.ed25519"
65 + 'signature': '1WEhVT42LCdNhuf5ogpcnJfJWbFTUily666pj1XDKS07hjEKGuwZTy/pYRcl/XJJIHMH9MiRkR6FIiOIa7t1DQ==.sig.ed25519'
6866 },
69- "timestamp": 1518568915077,
70- "dest": "#cooperative",
71- "rts": 1518568914727
67 + 'timestamp': 1518568915077,
68 + 'dest': '#cooperative',
69 + 'rts': 1518568914727
7270 }
7371 t.ok(isBlog(actualBlog), 'validates a blog from ticktack')
7472
7573 t.end()
7674 })
77-

Built with git-ssb-web