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