X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Fschedulers%2Fauto-follow-index-instances.ts;h=956ece749b8d54d87af690b0dbce53bd15046035;hb=0c302acb3c358b4d4d8dee45aed1de1108ea37ea;hp=d700a99f0b82257d630c3a1db7232f8aea7fb9ef;hpb=2ad9dcda240ee843c5e4a5b98cc94f7b2aab2c89;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/schedulers/auto-follow-index-instances.ts b/server/lib/schedulers/auto-follow-index-instances.ts index d700a99f0..956ece749 100644 --- a/server/lib/schedulers/auto-follow-index-instances.ts +++ b/server/lib/schedulers/auto-follow-index-instances.ts @@ -1,18 +1,18 @@ -import { logger } from '../../helpers/logger' -import { AbstractScheduler } from './abstract-scheduler' -import { INSTANCES_INDEX, SCHEDULER_INTERVALS_MS, SERVER_ACTOR_NAME } from '../../initializers/constants' -import { CONFIG } from '../../initializers/config' import { chunk } from 'lodash' -import { doRequest } from '@server/helpers/requests' -import { ActorFollowModel } from '@server/models/activitypub/actor-follow' +import { doJSONRequest } from '@server/helpers/requests' import { JobQueue } from '@server/lib/job-queue' -import { getServerActor } from '@server/helpers/utils' +import { ActorFollowModel } from '@server/models/actor/actor-follow' +import { getServerActor } from '@server/models/application/application' +import { logger } from '../../helpers/logger' +import { CONFIG } from '../../initializers/config' +import { SCHEDULER_INTERVALS_MS, SERVER_ACTOR_NAME } from '../../initializers/constants' +import { AbstractScheduler } from './abstract-scheduler' export class AutoFollowIndexInstances extends AbstractScheduler { private static instance: AbstractScheduler - protected schedulerIntervalMs = SCHEDULER_INTERVALS_MS.autoFollowIndexInstances + protected schedulerIntervalMs = SCHEDULER_INTERVALS_MS.AUTO_FOLLOW_INDEX_INSTANCES private lastCheck: Date @@ -34,14 +34,16 @@ export class AutoFollowIndexInstances extends AbstractScheduler { try { const serverActor = await getServerActor() - const uri = indexUrl + INSTANCES_INDEX.HOSTS_PATH - - const qs = { count: 1000 } - if (this.lastCheck) Object.assign(qs, { since: this.lastCheck.toISOString() }) + const searchParams = { count: 1000 } + if (this.lastCheck) Object.assign(searchParams, { since: this.lastCheck.toISOString() }) this.lastCheck = new Date() - const { body } = await doRequest({ uri, qs, json: true }) + const { body } = await doJSONRequest(indexUrl, { searchParams }) + if (!body.data || Array.isArray(body.data) === false) { + logger.error('Cannot auto follow instances of index %s. Please check the auto follow URL.', indexUrl, { body }) + return + } const hosts: string[] = body.data.map(o => o.host) const chunks = chunk(hosts, 20) @@ -57,7 +59,7 @@ export class AutoFollowIndexInstances extends AbstractScheduler { isAutoFollow: true } - JobQueue.Instance.createJob({ type: 'activitypub-follow', payload }) + JobQueue.Instance.createJobAsync({ type: 'activitypub-follow', payload }) } }