UNPKG

1.05 kBJavaScriptView Raw
1var create = require('./create')
2var path = require('path')
3var Inject = require('./inject')
4var Set = require('./set')
5var Level = require('level')
6
7exports.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
23exports.name = 'blobs'
24
25exports.version = require('./package.json').version
26
27exports.permissions = {
28 anonymous: { allow: ['has', 'get', 'getSlice', 'changes', 'createWants'] }
29}
30
31exports.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}