git ssb

2+

mixmix / ticktack



Tree: 65cd9cb5b2fda2efbf0c714425830c59b81a884e

Files: 65cd9cb5b2fda2efbf0c714425830c59b81a884e / backup / async / exportIdentity.js

1297 bytesRaw
1const nest = require('depnest')
2const { onceTrue } = require('mutant')
3const path = require('path')
4const fs = require('fs')
5const os = require('os')
6const config = require('../../config').create().config.sync.load()
7const peersFile = path.join(config.path, "gossip.json")
8const secretFile = path.join(config.path, "secret")
9
10
11exports.gives = nest('backup.async.exportIdentity')
12
13
14exports.needs = nest({
15 'keys.sync.id': 'first',
16 'sbot.obs.connection': 'first'
17})
18
19exports.create = function (api) {
20 return nest('backup.async.exportIdentity', (password, filename, cb) => {
21 if ("undefined" == typeof filename) {
22 cb()
23 } else {
24
25 console.log(`should export identity to file ${filename}`)
26
27 let peers = JSON.parse(fs.readFileSync(peersFile))
28 let secret = fs.readFileSync(secretFile, "utf8")
29
30 onceTrue(api.sbot.obs.connection, sbot => {
31
32 let feedId = api.keys.sync.id()
33
34 sbot.latestSequence(feedId, (err, sequence) => {
35
36 if (err) throw err
37
38 let data = {
39 exportDate: new Date(),
40 latestSequence: sequence,
41 peers: peers,
42 secret: secret
43 }
44
45 fs.writeFileSync(filename, JSON.stringify(data), "utf8")
46
47 cb()
48 })
49 })
50 }
51 return true
52 })
53}
54

Built with git-ssb-web