Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// return function that'll construct the right view when called
return function () {
var el = require('./feeds')(sbot, screen, filter)
el.setLabel(label+': '+userId)
return el
}
}
return graphs[graph]()
}
if (!module.parent) {
var argv = require('minimist')(process.argv.slice(2))
var graph = argv._[0]
var userId = argv._[1]
if (['follows', 'followers', 'flags', 'flaggers'].indexOf(graph) === -1 || !require('ssb-ref').isFeed(userId)) {
console.error('Usage: graph.js [follows|followers|flags|flaggers] {feedid}')
process.exit(1)
}
require('./lib/app')(module.exports.bind(null, graph, userId))
}
pull.drain(function (contacts) {
if(!contacts) return
if (isFeed(contacts.from) && isFeed(contacts.to)) { // live data
handleBlockUnlock(contacts.from, contacts.to, contacts.value)
} else { // initial data
for (var from in contacts) {
var relations = contacts[from]
for (var to in relations)
handleBlockUnlock(from, to, relations[to])
}
}
})
)
isBlockedOpts: function (v, n) {
var err = this.get('object')(v, n)
if (err)
return err
// .source
if (v.source && !ref.isFeed(v.source))
return AttrType(n, 'source', 'feedId')
// .dest
if (v.dest && !ref.isFeed(v.dest))
return AttrType(n, 'dest', 'feedId')
},
//allow content to be string. (i.e. for encrypted messages)
//or object with type string
if(!v.content)
return MissingAttr(n, 'content', 'object|string')
else if(typeof v.content === 'string')
; //check if it's base64?
else if('object' === typeof v.content) {
if(!v.content.type || typeof v.content.type != 'string')
return MissingAttr(n, 'content.type', 'string')
}
else
return MissingAttr(n, 'content', 'object|string')
// .author
if (!ref.isFeed(v.author))
return MissingAttr(n, 'author', 'feedId')
// .sequence
if (typeof v.sequence != 'number')
return MissingAttr(n, 'sequence', 'number')
// .previous
if (v.sequence > 1 && !ref.isMsg(v.previous))
return MissingAttr(n, 'previous', 'msgId')
else if(v.sequence == 1 && v.previous != null)
return MissingAttr(n, 'previous', 'null')
// .timestamp
if (typeof v.timestamp != 'number')
return MissingAttr(n, 'timestamp', 'number')
db.box = function (opts, state) {
var content = opts.content
var recps = opts.content.recps
if (recps) {
const isNonEmptyArrayOfFeeds = isArray(recps) && recps.every(isFeed) && recps.length > 0
if (isFeed(recps) || isNonEmptyArrayOfFeeds) {
recps = opts.content.recps = [].concat(recps) // force to array
return box(opts.content, recps)
} else {
throw new Error(
'private message recipients must be valid feeds, '+
'was:' + JSON.stringify(recps)
)
}
}
return opts.content
}
db.addMap = function (fn) {
get: function (addr) {
if(ref.isFeed(addr)) return getPeer(addr)
else if(ref.isFeed(addr.key)) return getPeer(addr.key)
else throw new Error('must provide id:'+JSON.stringify(addr))
// return u.find(peers, function (a) {
// return (
// addr.port === a.port
// && addr.host === a.host
// && addr.key === a.key
// )
// })
},
connect: valid.async(function (addr, cb) {
function get(id, lookup) {
if (!ref.isFeed(id)) {
console.error("Contact state requires an id!", id);
throw id;
}
if (!cacheLoading) {
cacheLoading = true;
loadCache();
}
if (!lookup[id]) {
lookup[id] = Value({});
}
return lookup[id];
}
};
function toMultiserverAddress (address) {
if (isObject(address)) {
if (ref.isFeed(address.key)) {
address.key = address.key.match(feedIdRegex)[1]
}
var protocol = 'net'
if (address.host.endsWith('.onion')) { protocol = 'onion' }
return [protocol, address.host, address.port].join(':') + '~' + ['shs', toBase64(address.key)].join(':')
}
return address
}
content = ssbKeys.box(content, content.recps.map(function (e) {
return ref.isFeed(e) ? e : e.link
}))
else if(content.mentions)