Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
module.exports = function unpackLink (link) {
const index = link.indexOf('?')
const blobId = link.substring(0, index)
const blobKey = link.substring(index + 1)
assert(((index > 0) && (blobKey.length)), 'Blob not encrypted')
// TODO: test for well formed blob key
assert((isBlobId(blobId)), 'attachment contains invalid blob reference')
return { blobId, blobKey }
}
publishAbout(content: AboutContent, cb: Callback) {
if (content.image && !Ref.isBlobId(content.image[0])) {
ssb.blobsUtils.addFromPath(
content.image,
(err: any, hash: string) => {
if (err) return console.error(err);
content.image = hash;
ssb.publish(content, (err2: any, msg: any) => {
if (err2) console.error(err2);
if (cb) cb(err2, msg);
});
},
);
} else {
ssb.publish(content, (err: any, msg: any) => {
if (err) console.error(err);
if (cb) cb(err, msg);
});
case "%":
if (!isMsgId(id)) {
console.error(`intercept url should been a msg but it is not: ${id}`);
return false;
}
window.location.hash = "thread/" + encodeURIComponent(id);
break;
case "@":
if (!isFeedId(id)) {
console.error(`intercept url should been a feed but it is not: ${id}`);
return false;
}
window.location.hash = "feed/" + encodeURIComponent(id);
break;
case "&":
if (!isBlobId(id)) {
console.error(`intercept url should been a blob but it is not: ${id}`);
return false;
}
window.location = "http://localhost:8989/blobs/get/" + id;
break;
}
if (id.indexOf("javascript:") === 0) {
return h("h1", "stop trying to inject JS here");
}
return h("p", `loading ${id}...`);
};
sbotP.then(sbot => {
if (content.image && !Ref.isBlobId(content.image[0])) {
sbot.blobsFromPath.add(
content.image,
(err: any, hash: string) => {
if (err) return console.error(err);
content.image = hash;
sbot.publish(content, (err2: any, msg: any) => {
if (err2) console.error(err2);
if (cb) cb(err2, msg);
});
},
);
} else {
sbot.publish(content, (err: any, msg: any) => {
if (err) console.error(err);
if (cb) cb(err, msg);
});
const links = traverse(content).reduce(function (acc, x) {
if (this.isLeaf) {
if (isMsgId(x) || isBlobId(x) || isFeedId(x)) {
if (!['revisionRoot', 'revisionBranch'].includes(this.path[0])) {
acc.push([this.path.join('.'), x])
}
}
}
return acc
}, [])