From 7bc29171456ffa91c7ec8dc77e892c7dca359989 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 11 Jan 2018 11:40:18 +0100 Subject: Add tests to handle down server --- server/lib/activitypub/process/process-accept.ts | 8 +++++--- server/lib/activitypub/process/process-create.ts | 4 ++-- .../activitypub-http-job-scheduler.ts | 1 - .../activitypub-http-unicast-handler.ts | 4 ++-- 4 files changed, 9 insertions(+), 8 deletions(-) (limited to 'server/lib') diff --git a/server/lib/activitypub/process/process-accept.ts b/server/lib/activitypub/process/process-accept.ts index b9d906ec9..551f09ea7 100644 --- a/server/lib/activitypub/process/process-accept.ts +++ b/server/lib/activitypub/process/process-accept.ts @@ -23,7 +23,9 @@ async function processAccept (actor: ActorModel, targetActor: ActorModel) { const follow = await ActorFollowModel.loadByActorAndTarget(actor.id, targetActor.id) if (!follow) throw new Error('Cannot find associated follow.') - follow.set('state', 'accepted') - await follow.save() - await addFetchOutboxJob(targetActor, undefined) + if (follow.state !== 'accepted') { + follow.set('state', 'accepted') + await follow.save() + await addFetchOutboxJob(targetActor, undefined) + } } diff --git a/server/lib/activitypub/process/process-create.ts b/server/lib/activitypub/process/process-create.ts index 08d61996a..442cd5c0b 100644 --- a/server/lib/activitypub/process/process-create.ts +++ b/server/lib/activitypub/process/process-create.ts @@ -147,8 +147,8 @@ async function processCreateView (byActor: ActorModel, activity: ActivityCreate) const { video } = await getOrCreateAccountAndVideoAndChannel(view.object) - const account = await ActorModel.loadByUrl(view.actor) - if (!account) throw new Error('Unknown account ' + view.actor) + const actor = await ActorModel.loadByUrl(view.actor) + if (!actor) throw new Error('Unknown actor ' + view.actor) await video.increment('views') diff --git a/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-job-scheduler.ts b/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-job-scheduler.ts index 884ede5a3..10423a7df 100644 --- a/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-job-scheduler.ts +++ b/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-job-scheduler.ts @@ -4,7 +4,6 @@ import { logger } from '../../../helpers/logger' import { getServerActor } from '../../../helpers/utils' import { ACTIVITY_PUB } from '../../../initializers' import { ActorModel } from '../../../models/activitypub/actor' -import { ActorFollowModel } from '../../../models/activitypub/actor-follow' import { JobHandler, JobScheduler } from '../job-scheduler' import * as activitypubHttpBroadcastHandler from './activitypub-http-broadcast-handler' diff --git a/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-unicast-handler.ts b/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-unicast-handler.ts index e02bd698e..deedf8402 100644 --- a/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-unicast-handler.ts +++ b/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-unicast-handler.ts @@ -19,11 +19,11 @@ async function process (payload: ActivityPubHttpPayload, jobId: number) { try { await doRequest(options) - await ActorFollowModel.updateActorFollowsScoreAndRemoveBadOnes([ uri ], [], undefined) + ActorFollowModel.updateActorFollowsScoreAndRemoveBadOnes([ uri ], [], undefined) } catch (err) { const isRetryingLater = await maybeRetryRequestLater(err, payload, uri) if (isRetryingLater === false) { - await ActorFollowModel.updateActorFollowsScoreAndRemoveBadOnes([], [ uri ], undefined) + ActorFollowModel.updateActorFollowsScoreAndRemoveBadOnes([], [ uri ], undefined) } throw err -- cgit v1.2.3