Files: e3887a34e8e4f6b4cbc0d1d1b0e549b50157b48c / index.js
856 bytesRaw
1 | const inject = require('./inject') |
2 | |
3 | const methods = { |
4 | async: { |
5 | create: require('./async/fetch'), |
6 | }, |
7 | obs: { |
8 | get: require('./obs/get'), |
9 | }, |
10 | sync: { |
11 | isBlog: require('./sync/isBook'), |
12 | } |
13 | } |
14 | |
15 | // Note : if you don't like this export pattern, there's no reason we can't add different mappings !! |
16 | // e.g. book.validate.bookComment |
17 | |
18 | module.exports = function Blog (server, opts) { |
19 | if (!server.about) throw new Error('scuttle-book requires you to have the ssb-about plugin installed') |
20 | |
21 | return inject(server, methods) |
22 | } |
23 | |
24 | |
25 | // auto-inject the ssb-server to all methods to reduce repitition |
26 | function inject (server, methods) { |
27 | for (var key in methods) { |
28 | if (typeof methods[key] === 'function') { |
29 | methods[key] = methods[key](server) |
30 | |
31 | } |
32 | else { |
33 | methods[key] = inject(server, methods[key]) |
34 | } |
35 | } |
36 | |
37 | return methods |
38 | } |
39 | |
40 | |
41 |
Built with git-ssb-web