mirror of
https://github.com/alexbosworth/balanceofsatoshis.git
synced 2026-08-13 12:33:37 +02:00
support full path to storage directory
This commit is contained in:
parent
81dfcfb3c2
commit
73867048bb
15 changed files with 36 additions and 60 deletions
|
|
@ -1,14 +1,13 @@
|
|||
const {homedir} = require('os');
|
||||
const {join} = require('path');
|
||||
|
||||
const asyncAuto = require('async/auto');
|
||||
const {returnResult} = require('asyncjs-util');
|
||||
|
||||
const {home} = require('../storage');
|
||||
const {homePath} = require('../storage');
|
||||
const flatten = arr => [].concat(...arr);
|
||||
const {isArray} = Array;
|
||||
const {parse} = JSON;
|
||||
const tagFilePath = () => join(...[homedir(), home(), 'tags.json']);
|
||||
const tagFilePath = () => join(...[homePath({}), 'tags.json']);
|
||||
const uniq = arr => Array.from(new Set(arr));
|
||||
|
||||
/** Get icons for public keys from tags
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ const {getSavedCredentials} = require('./../nodes');
|
|||
const getSocket = require('./get_socket');
|
||||
const {noSpendPerms} = require('./constants');
|
||||
const {permissionEntities} = require('./constants');
|
||||
const {home} = require('../storage');
|
||||
const {homePath} = require('../storage');
|
||||
|
||||
const config = 'config.json';
|
||||
const defaultLndDirPath = process.env.BOS_DEFAULT_LND_PATH;
|
||||
|
|
@ -67,7 +67,7 @@ module.exports = (args, cbk) => {
|
|||
return cbk(null, defaultNodeName);
|
||||
}
|
||||
|
||||
const path = join(...[homedir(), home(), config]);
|
||||
const path = join(...[homePath({}), config]);
|
||||
|
||||
return fs.getFile(path, (err, res) => {
|
||||
// Exit early on errors, there is no config found
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ const {randomBytes} = require('crypto');
|
|||
const asyncAuto = require('async/auto');
|
||||
const {returnResult} = require('asyncjs-util');
|
||||
|
||||
const {home} = require('../storage');
|
||||
const {homePath} = require('../storage');
|
||||
|
||||
const defaultTagsFile = {tags: []};
|
||||
const {isArray} = Array;
|
||||
|
|
@ -16,7 +16,7 @@ const makeId = () => randomBytes(32).toString('hex');
|
|||
const makeTag = (alias, id) => ({alias, id});
|
||||
const {parse} = JSON;
|
||||
const stringify = obj => JSON.stringify(obj, null, 2);
|
||||
const tagFilePath = () => join(...[homedir(), home(), 'tags.json']);
|
||||
const tagFilePath = () => join(...[homePath({}), 'tags.json']);
|
||||
const uniq = arr => Array.from(new Set(arr));
|
||||
|
||||
/** Adjust tags
|
||||
|
|
@ -82,7 +82,7 @@ module.exports = (args, cbk) => {
|
|||
|
||||
// Register the home directory
|
||||
registerHomeDir: ['validate', ({}, cbk) => {
|
||||
return args.fs.makeDirectory(join(...[homedir(), home()]), err => {
|
||||
return args.fs.makeDirectory(join(...[homePath({})]), err => {
|
||||
// Ignore errors, the directory may already be there
|
||||
return cbk();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ const {join} = require('path');
|
|||
const asyncAuto = require('async/auto');
|
||||
const {returnResult} = require('asyncjs-util');
|
||||
|
||||
const {home} = require('../storage');
|
||||
const {homePath} = require('../storage');
|
||||
|
||||
const credentialsFileName = 'credentials.json';
|
||||
|
||||
|
|
@ -38,7 +38,7 @@ module.exports = ({fs, node}, cbk) => {
|
|||
|
||||
// Remove credentials file
|
||||
removeCredentials: ['validate', ({}, cbk) => {
|
||||
const path = join(...[homedir(), home(), node, credentialsFileName]);
|
||||
const path = join(...[homePath({}), node, credentialsFileName]);
|
||||
|
||||
return fs.removeFile(path, err => {
|
||||
if (!!err) {
|
||||
|
|
@ -51,7 +51,7 @@ module.exports = ({fs, node}, cbk) => {
|
|||
|
||||
// Remove credentials directory
|
||||
removeDirectory: ['removeCredentials', ({}, cbk) => {
|
||||
const path = join(...[homedir(), home(), node]);
|
||||
const path = join(...[homePath({}), node]);
|
||||
|
||||
return fs.removeDirectory(path, err => {
|
||||
if (!!err) {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ const {join} = require('path');
|
|||
const asyncAuto = require('async/auto');
|
||||
const {returnResult} = require('asyncjs-util');
|
||||
|
||||
const {home} = require('../storage');
|
||||
const {homePath} = require('../storage');
|
||||
|
||||
|
||||
const credentials = 'credentials.json';
|
||||
|
|
@ -54,7 +54,7 @@ module.exports = ({fs, node}, cbk) => {
|
|||
|
||||
// Get the credentials file
|
||||
getFile: ['validate', ({}, cbk) => {
|
||||
const path = join(...[homedir(), home(), node, credentials]);
|
||||
const path = join(...[homePath({}), node, credentials]);
|
||||
|
||||
return fs.getFile(path, (err, res) => {
|
||||
// Exit early on errors, there is no credential found
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ const {getWalletInfo} = require('ln-service');
|
|||
const {returnResult} = require('asyncjs-util');
|
||||
|
||||
const getSavedCredentials = require('./get_saved_credentials');
|
||||
const {home} = require('../storage');
|
||||
const {homePath} = require('../storage');
|
||||
|
||||
/** Get a list of saved nodes
|
||||
|
||||
|
|
@ -59,7 +59,7 @@ module.exports = ({fs, network}, cbk) => {
|
|||
|
||||
// Data directory
|
||||
dataDir: ['validate', ({}, cbk) => {
|
||||
return cbk(null, join(...[homedir(), home()]));
|
||||
return cbk(null, join(...[homePath({})]));
|
||||
}],
|
||||
|
||||
// Check that the data directory exists
|
||||
|
|
@ -81,7 +81,7 @@ module.exports = ({fs, network}, cbk) => {
|
|||
getDirs: ['checkDataDir', 'dataDir', ({dataDir}, cbk) => {
|
||||
return fs.getDirectoryFiles(dataDir, (err, files) => {
|
||||
return asyncFilter(files, (file, cbk) => {
|
||||
const path = join(...[homedir(), home(), file]);
|
||||
const path = join(...[homePath({}), file]);
|
||||
|
||||
return fs.getFileStatus(path, (err, res) => {
|
||||
if (!!err) {
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ const deleteNodeCredentials = require('./delete_node_credentials');
|
|||
const encryptSavedMacaroons = require('./encrypt_saved_macaroons');
|
||||
const getSavedCredentials = require('./get_saved_credentials');
|
||||
const getSavedNodes = require('./get_saved_nodes');
|
||||
const {home} = require('../storage');
|
||||
const {homePath} = require('../storage');
|
||||
const registerNode = require('./register_node');
|
||||
|
||||
const {isArray} = Array;
|
||||
|
|
@ -96,7 +96,7 @@ module.exports = (args, cbk) => {
|
|||
|
||||
// Make sure the home directory is there
|
||||
registerHomeDir: ['validate', ({}, cbk) => {
|
||||
return args.fs.makeDirectory(join(...[homedir(), home()]), err => {
|
||||
return args.fs.makeDirectory(join(...[homePath({})]), err => {
|
||||
// Ignore errors, the directory may already be there
|
||||
return cbk();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ const {homedir} = require('os');
|
|||
const asyncAuto = require('async/auto');
|
||||
const {returnResult} = require('asyncjs-util');
|
||||
|
||||
const {home} = require('../storage');
|
||||
const {homePath} = require('../storage');
|
||||
|
||||
const credentials = 'credentials.json';
|
||||
const {isArray} = Array;
|
||||
|
|
@ -61,7 +61,7 @@ module.exports = (args, cbk) => {
|
|||
|
||||
// Make sure the node directory is there
|
||||
registerDirectory: ['validate', ({}, cbk) => {
|
||||
const nodeDirectory = join(...[homedir(), home(), args.node]);
|
||||
const nodeDirectory = join(...[homePath({}), args.node]);
|
||||
|
||||
return args.fs.makeDirectory(nodeDirectory, err => {
|
||||
// Ignore errors, the directory may already be there
|
||||
|
|
@ -79,7 +79,7 @@ module.exports = (args, cbk) => {
|
|||
socket: args.socket,
|
||||
});
|
||||
|
||||
const path = join(...[homedir(), home(), args.node, credentials]);
|
||||
const path = join(...[homePath({}), args.node, credentials]);
|
||||
|
||||
return args.fs.writeFile(path, file, err => {
|
||||
if (!!err) {
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ const {returnResult} = require('asyncjs-util');
|
|||
const sanitize = require('sanitize-filename');
|
||||
|
||||
const {derAsPem} = require('./../encryption');
|
||||
const {home} = require('../storage');
|
||||
const {homePath} = require('../storage');
|
||||
const putSavedCredentials = require('./put_saved_credentials');
|
||||
|
||||
const credentialsFileName = 'credentials.json';
|
||||
|
|
@ -62,7 +62,7 @@ module.exports = ({ask, cryptography, fs, logger, node}, cbk) => {
|
|||
|
||||
// Make sure the home directory is there
|
||||
registerHomeDirectory: ['validate', ({}, cbk) => {
|
||||
return fs.makeDirectory(join(...[homedir(), home()]), err => {
|
||||
return fs.makeDirectory(join(...[homePath({})]), err => {
|
||||
// Ignore errors, the directory may already be there
|
||||
return cbk();
|
||||
});
|
||||
|
|
@ -295,7 +295,7 @@ module.exports = ({ask, cryptography, fs, logger, node}, cbk) => {
|
|||
'nodeName',
|
||||
'registerHomeDirectory', ({nodeName}, cbk) =>
|
||||
{
|
||||
return fs.makeDirectory(join(...[homedir(), home(), nodeName]), err => {
|
||||
return fs.makeDirectory(join(...[homePath({}), nodeName]), err => {
|
||||
// Ignore errors, the directory may already be there
|
||||
return cbk();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,12 +0,0 @@
|
|||
const home = '.bos';
|
||||
|
||||
/** Get the name of the home directory
|
||||
@returns
|
||||
{
|
||||
home: <Home directory name String>
|
||||
}
|
||||
*/
|
||||
module.exports = () => {
|
||||
|
||||
return process.env.BOS_DIRECTORY || home;
|
||||
};
|
||||
|
|
@ -1,24 +1,14 @@
|
|||
const {homedir} = require('os');
|
||||
const {join} = require('path');
|
||||
|
||||
const home = require('./home');
|
||||
|
||||
/** Get the path to the home directory
|
||||
|
||||
{
|
||||
fs: {
|
||||
homeDirectory: () => <Home Directory String>
|
||||
}
|
||||
}
|
||||
const home = join(...[homedir(), '.bos']);
|
||||
|
||||
/** Get the path of the bos storage directory
|
||||
@returns
|
||||
{
|
||||
path: <Path To Home Directory String>
|
||||
home: <Home directory path String>
|
||||
}
|
||||
*/
|
||||
module.exports = ({fs}) => {
|
||||
if (!fs) {
|
||||
throw new Error('ExpectedFsToDeriveHomePath');
|
||||
}
|
||||
|
||||
return {path: join(...[fs.homeDirectory(), home()])};
|
||||
module.exports = ({}) => {
|
||||
return process.env.BOS_DIRECTORY || home;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
const homePath = require('./home_path');
|
||||
const home = require('./home');
|
||||
|
||||
module.exports = {home, homePath};
|
||||
module.exports = {homePath};
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ const {routeFromChannels} = require('ln-service');
|
|||
const {findTagMatch} = require('./../peers');
|
||||
const {formatFeeRate} = require('./../display');
|
||||
const {getIgnores} = require('./../routing');
|
||||
const {home} = require('../storage');
|
||||
const {homePath} = require('../storage');
|
||||
const {parseAmount} = require('./../display');
|
||||
const {probeDestination} = require('./../network');
|
||||
const {sortBy} = require('./../arrays');
|
||||
|
|
@ -59,7 +59,7 @@ const pubKeyHexLength = 66;
|
|||
const rateDivisor = 1e6;
|
||||
const sample = a => !!a.length ? a[Math.floor(Math.random()*a.length)] : null;
|
||||
const sumOf = arr => arr.reduce((sum, n) => sum + n);
|
||||
const tagFilePath = () => join(...[homedir(), home(), 'tags.json']);
|
||||
const tagFilePath = () => join(...[homePath({}), 'tags.json']);
|
||||
const times = 6;
|
||||
const tokAsBigTok = tokens => !tokens ? undefined : (tokens / 1e8).toFixed(8);
|
||||
const topOf = arr => arr.slice(0, Math.ceil(arr.length / 2));
|
||||
|
|
|
|||
|
|
@ -4,12 +4,12 @@ const {join} = require('path');
|
|||
const asyncAuto = require('async/auto');
|
||||
const {returnResult} = require('asyncjs-util');
|
||||
|
||||
const {home} = require('../storage');
|
||||
const {homePath} = require('../storage');
|
||||
|
||||
const defaultTags = {tags: []};
|
||||
const {isArray} = Array;
|
||||
const {parse} = JSON;
|
||||
const tagFilePath = () => join(...[homedir(), home(), 'tags.json']);
|
||||
const tagFilePath = () => join(...[homePath({}), 'tags.json']);
|
||||
|
||||
/** Get tagged nodes
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ const inquirer = require('inquirer');
|
|||
const {returnResult} = require('asyncjs-util');
|
||||
|
||||
const getSocksProxy = require('./get_socks_proxy');
|
||||
const {home} = require('../storage');
|
||||
const {homePath} = require('../storage');
|
||||
const interaction = require('./interaction');
|
||||
|
||||
const botKeyFile = 'telegram_bot_api_key';
|
||||
|
|
@ -54,7 +54,7 @@ module.exports = ({fs, proxy}, cbk) => {
|
|||
}],
|
||||
|
||||
// Home directory path
|
||||
path: ['validate', ({}, cbk) => cbk(null, join(...[homedir(), home()]))],
|
||||
path: ['validate', ({}, cbk) => cbk(null, join(...[homePath({})]))],
|
||||
|
||||
// Ask for an API key
|
||||
apiKey: ['path', ({path}, cbk) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue