1 | var create = require('./create')
|
2 | var path = require('path')
|
3 | var Inject = require('./inject')
|
4 | var Set = require('./set')
|
5 | var Level = require('level')
|
6 |
|
7 | exports.manifest = {
|
8 | get: 'source',
|
9 | getSlice: 'source',
|
10 | add: 'sink',
|
11 | rm: 'async',
|
12 | ls: 'source',
|
13 | has: 'async',
|
14 | size: 'async',
|
15 | meta: 'async',
|
16 | want: 'async',
|
17 | push: 'async',
|
18 | changes: 'source',
|
19 | createWants: 'source',
|
20 | help: 'sync'
|
21 | }
|
22 |
|
23 | exports.name = 'blobs'
|
24 |
|
25 | exports.version = require('./package.json').version
|
26 |
|
27 | exports.permissions = {
|
28 | anonymous: { allow: ['has', 'get', 'getSlice', 'changes', 'createWants'] }
|
29 | }
|
30 |
|
31 | exports.init = function (sbot, config) {
|
32 | const level = Level(path.join(config.path, 'blobs_push'), { valueEncoding: 'json' })
|
33 |
|
34 | var blobs = Inject(
|
35 | create(path.join(config.path, 'blobs')),
|
36 | Set(level),
|
37 | sbot.id,
|
38 | config.blobs
|
39 | )
|
40 |
|
41 | sbot.on('rpc:connect', function (rpc) {
|
42 | if (rpc.id === sbot.id) return
|
43 | blobs._onConnect(rpc, rpc.id)
|
44 | })
|
45 |
|
46 | sbot.close.hook(function (fn, args) {
|
47 | level.close(() => fn(...args))
|
48 | })
|
49 |
|
50 | return blobs
|
51 | }
|