Files: c24946ad74bf65f4ff10b27c737cc02628f88c75 / backup / async / exportIdentity.js
938 bytesRaw
1 | const nest = require('depnest') |
2 | const path = require('path') |
3 | const fs = require('fs') |
4 | const os = require('os') |
5 | const homedir = os.homedir() |
6 | const ssbPath = `${homedir}/.ssb/` |
7 | const peersFile = path.join(homedir, ".ssb", "gossip.json") |
8 | const secretFile = path.join(homedir, ".ssb", "secret") |
9 | |
10 | |
11 | exports.gives = nest('backup.async.exportIdentity') |
12 | |
13 | exports.create = function (api) { |
14 | return nest('backup.async.exportIdentity', (password, filename, cb) => { |
15 | if ("undefined" == typeof filename) { |
16 | cb() |
17 | } else { |
18 | |
19 | console.log(`should export identity to file ${filename}`) |
20 | |
21 | let peers = JSON.parse(fs.readFileSync(peersFile)) |
22 | let secret = fs.readFileSync(secretFile, "utf8") |
23 | |
24 | |
25 | let data = { |
26 | exportDate: new Date(), |
27 | latestSequence: "", |
28 | peers: peers, |
29 | secret: secret |
30 | } |
31 | |
32 | fs.writeFileSync(filename, JSON.stringify(data), "utf8") |
33 | |
34 | cb() |
35 | } |
36 | return true |
37 | }) |
38 | } |
39 |
Built with git-ssb-web