Comparing version 6.2.3 to 6.3.0
63
cli.js
@@ -15,2 +15,23 @@ #!/usr/bin/env node | ||
var memdb = require('memdb') | ||
var cabalDns = require('cabal-dns')({ | ||
persistentCache: { | ||
read: async function (name, err) { | ||
if (name in config.cache) { | ||
var cache = config.cache[name] | ||
if (cache.expiresAt < Date.now()) { // if ttl has expired: warn, but keep using | ||
console.error(`${chalk.redBright('Note:')} the TTL for ${name} has expired`) | ||
} | ||
return cache.key | ||
} | ||
// dns record wasn't found online and wasn't in the cache | ||
throw err | ||
}, | ||
write: async function (name, key, ttl) { | ||
var expireOffset = +(new Date(ttl * 1000)) // convert to epoch time | ||
var expiredTime = Date.now() + expireOffset | ||
config.cache[name] = { key: key, expiresAt: expiredTime } | ||
saveConfig(configFilePath, config) | ||
} | ||
} | ||
}) | ||
@@ -77,3 +98,3 @@ var args = minimist(process.argv.slice(2)) | ||
if (!fs.existsSync(rootconfig)) { | ||
saveConfig(rootconfig, { cabals: [], aliases: {} }) | ||
saveConfig(rootconfig, { cabals: [], aliases: {}, cache: {} }) | ||
} | ||
@@ -87,2 +108,3 @@ | ||
if (!config.aliases) { config.aliases = {} } | ||
if (!config.cache) { config.cache = {} } | ||
cabalKeys = config.cabals | ||
@@ -164,7 +186,15 @@ } | ||
function createCabal (key) { | ||
key = key.replace('cabal://', '').replace('cbl://', '').replace('dat://', '').replace(/\//g, '') | ||
var storage = args.temp ? ram : archivesdir + key | ||
if (!args.temp) try { mkdirp.sync(path.join(archivesdir, key, 'views')) } catch (e) {} | ||
var db = args.temp ? memdb() : level(path.join(archivesdir, key, 'views')) | ||
return Cabal(storage, key, {db: db, maxFeeds: maxFeeds}) | ||
return cabalDns.resolveName(key).then(function (key) { | ||
key = key.replace('cabal://', '').replace('cbl://', '').replace('dat://', '').replace(/\//g, '') | ||
var storage = args.temp ? ram : archivesdir + key | ||
if (!args.temp) try { mkdirp.sync(path.join(archivesdir, key, 'views')) } catch (e) {} | ||
var db = args.temp ? memdb() : level(path.join(archivesdir, key, 'views')) | ||
return Cabal(storage, key, { db: db, maxFeeds: maxFeeds }) | ||
}).catch(function () { | ||
// try to get from local cache | ||
// if record was found, was the ttl within bounds? (i.e. does the key still have time to live) | ||
// wasn't any entry in the cache; assume record just wasn't found | ||
console.error(`${chalk.redBright('Record not found')}\nHave you created a file containing the cabal:// key at ${chalk.greenBright(key + '/.well-known/cabal')}?`) | ||
process.exit(1) | ||
}) | ||
} | ||
@@ -184,11 +214,14 @@ | ||
// join the specified list of cabals | ||
Promise.all(cabalKeys.map((key) => { | ||
var cabal = createCabal(key) | ||
return new Promise((resolve) => { | ||
cabal.ready(() => { | ||
resolve(cabal) | ||
Promise.all(cabalKeys.map(createCabal)).then(function (cabals) { | ||
var promisedCabals = cabals.map(function (cabal) { | ||
return new Promise((resolve) => { | ||
cabal.ready(() => { | ||
resolve(cabal) | ||
}) | ||
}) | ||
}) | ||
})).then((cabals) => { | ||
start(cabals) | ||
Promise.all(promisedCabals) | ||
.then((cabals) => { | ||
start(cabals) | ||
}) | ||
}) | ||
@@ -281,6 +314,6 @@ } else { | ||
function publishSingleMessage ({key, channel, message, messageType, timeout}) { | ||
function publishSingleMessage ({ key, channel, message, messageType, timeout }) { | ||
console.log(`Publishing message to channel - ${channel || 'default'}: ${message}`) | ||
var db = args.temp ? memdb() : level(path.join(archivesdir, key, 'views')) | ||
var cabal = Cabal(archivesdir + key, key, {db: db, maxFeeds: maxFeeds}) | ||
var cabal = Cabal(archivesdir + key, key, { db: db, maxFeeds: maxFeeds }) | ||
cabal.ready(() => { | ||
@@ -287,0 +320,0 @@ cabal.publish({ |
{ | ||
"name": "cabal-cli", | ||
"version": "6.2.3", | ||
"version": "6.3.0", | ||
"description": "p2p chat", | ||
@@ -11,2 +11,3 @@ "main": "index.js", | ||
"cabal-core": "^5.1.2", | ||
"cabal-dns": "^1.0.1", | ||
"chalk": "^2.4.1", | ||
@@ -23,3 +24,3 @@ "collect-stream": "^1.2.1", | ||
"mkdirp": "^0.5.1", | ||
"neat-input": "^1.9.0", | ||
"neat-input": "^1.10.0", | ||
"neat-log": "^3.1.0", | ||
@@ -26,0 +27,0 @@ "random-access-memory": "^3.1.1", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1184560
1182
20
+ Addedcabal-dns@^1.0.1
+ Addedcabal-dns@1.0.1(transitive)
+ Addedcall-me-maybe@1.0.2(transitive)
Updatedneat-input@^1.10.0