1 import { ACTIVITY_PUB, JOB_REQUEST_TIMEOUT } from '../../initializers'
2 import { doRequest } from '../../helpers/requests'
3 import { logger } from '../../helpers/logger'
5 async function crawlCollectionPage <T> (uri: string, handler: (items: T[]) => Promise<any>) {
6 logger.info('Crawling ActivityPub data on %s.', uri)
13 timeout: JOB_REQUEST_TIMEOUT
16 const response = await doRequest(options)
17 const firstBody = response.body
19 let limit = ACTIVITY_PUB.FETCH_PAGE_LIMIT
21 let nextLink = firstBody.first
22 while (nextLink && i < limit) {
23 options.uri = nextLink
25 const { body } = await doRequest(options)
29 if (Array.isArray(body.orderedItems)) {
30 const items = body.orderedItems
31 logger.info('Processing %i ActivityPub items for %s.', items.length, nextLink)