Skip to content

Instantly share code, notes, and snippets.

@nickwynja
Last active April 10, 2020 12:49
Show Gist options
  • Save nickwynja/26431e1c3a69164c6fe3cbd37339e5c1 to your computer and use it in GitHub Desktop.
Save nickwynja/26431e1c3a69164c6fe3cbd37339e5c1 to your computer and use it in GitHub Desktop.
Method to get blobs from recent posts
// @TODO: Get blobs somehow
const myFeedId = ssb.id;
const source = ssb.query.read(
configure({
query: [
{
$filter: {
value: {
timestamp: { $lte: Date.now() },
content: {
type: "post",
},
},
},
},
],
})
);
const mentions = await new Promise((resolve, reject) => {
pull(
source,
pull.filter(
(msg) =>
lodash.get(msg, "value.content.mentions", "false").length > 0 ? true : false
),
pull.take(maxMessages),
pull.map((msg) => {
return lodash.get(msg, "value.content.mentions");
}),
pull.collect((err, collectedMentions) => {
if (err) {
reject(err);
} else {
resolve(collectedMentions);
}
})
);
});
const blobsToWant = async () => {
var blobsArray = [];
mentions.forEach((m) => {
if (m !== undefined) {
m.forEach((blob) => {
if (blob.size) {
blobsArray.push(blob.link);
}
});
}
});
return blobsArray;
};
// @TODO: Do something to download(?) this
// list of blobs
debug("Something could be done with these blobs:");
debug(await blobsToWant());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment