mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-05 19:42:24 +02:00
Refractor and optimize AP collections
Only display urls in general object, and paginate video comments, shares, likes and dislikes
This commit is contained in:
parent
e251f170b0
commit
8fffe21a7b
14 changed files with 215 additions and 260 deletions
40
server/lib/activitypub/crawl.ts
Normal file
40
server/lib/activitypub/crawl.ts
Normal file
|
@ -0,0 +1,40 @@
|
|||
import { ACTIVITY_PUB, JOB_REQUEST_TIMEOUT } from '../../initializers'
|
||||
import { doRequest } from '../../helpers/requests'
|
||||
import { logger } from '../../helpers/logger'
|
||||
|
||||
async function crawlCollectionPage <T> (uri: string, handler: (items: T[]) => Promise<any>) {
|
||||
logger.info('Crawling ActivityPub data on %s.', uri)
|
||||
|
||||
const options = {
|
||||
method: 'GET',
|
||||
uri,
|
||||
json: true,
|
||||
activityPub: true,
|
||||
timeout: JOB_REQUEST_TIMEOUT
|
||||
}
|
||||
|
||||
const response = await doRequest(options)
|
||||
const firstBody = response.body
|
||||
|
||||
let limit = ACTIVITY_PUB.FETCH_PAGE_LIMIT
|
||||
let i = 0
|
||||
let nextLink = firstBody.first
|
||||
while (nextLink && i < limit) {
|
||||
options.uri = nextLink
|
||||
|
||||
const { body } = await doRequest(options)
|
||||
nextLink = body.next
|
||||
i++
|
||||
|
||||
if (Array.isArray(body.orderedItems)) {
|
||||
const items = body.orderedItems
|
||||
logger.info('Processing %i ActivityPub items for %s.', items.length, nextLink)
|
||||
|
||||
await handler(items)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export {
|
||||
crawlCollectionPage
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue