-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathget-all.js
29 lines (22 loc) · 852 Bytes
/
get-all.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const { promisify } = require('bluebird');
const { createClient } = require('lightrpc');
const client = createClient('https://api.steemit.com');
const sendAsync = promisify(client.send, { context: client });
const limit = 10;
async function getAll(tag, sortBy) {
const posts = [];
const result = await sendAsync(`get_discussions_by_${sortBy}`, [{ tag, limit }]);
posts.push(...result);
let received = 0;
do {
const startAuthor = posts[posts.length - 1].author;
const startPermlink = posts[posts.length - 1].permlink;
const moreResult = await sendAsync(`get_discussions_by_${sortBy}`, [
{ tag, limit, start_author: startAuthor, start_permlink: startPermlink },
]);
posts.push(...moreResult.slice(1));
received = moreResult.length;
} while (received === limit);
return posts;
}
module.exports = getAll;