diff options
-rw-r--r-- | server/lib/activitypub/actor.ts | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/server/lib/activitypub/actor.ts b/server/lib/activitypub/actor.ts index 73406e248..63975021c 100644 --- a/server/lib/activitypub/actor.ts +++ b/server/lib/activitypub/actor.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import * as Bluebird from 'bluebird' | 1 | import * as Bluebird from 'bluebird' |
2 | import { Transaction } from 'sequelize' | 2 | import { Op, Transaction } from 'sequelize' |
3 | import { URL } from 'url' | 3 | import { URL } from 'url' |
4 | import { v4 as uuidv4 } from 'uuid' | 4 | import { v4 as uuidv4 } from 'uuid' |
5 | import { ActivityPubActor, ActivityPubActorType, ActivityPubOrderedCollection } from '../../../shared/models/activitypub' | 5 | import { ActivityPubActor, ActivityPubActorType, ActivityPubOrderedCollection } from '../../../shared/models/activitypub' |
@@ -384,14 +384,33 @@ function saveActorAndServerAndModelIfNotExist ( | |||
384 | 384 | ||
385 | // Force the actor creation, sometimes Sequelize skips the save() when it thinks the instance already exists | 385 | // Force the actor creation, sometimes Sequelize skips the save() when it thinks the instance already exists |
386 | // (which could be false in a retried query) | 386 | // (which could be false in a retried query) |
387 | const [ actorCreated ] = await ActorModel.findOrCreate<MActorFullActor>({ | 387 | const [ actorCreated, created ] = await ActorModel.findOrCreate<MActorFullActor>({ |
388 | defaults: actor.toJSON(), | 388 | defaults: actor.toJSON(), |
389 | where: { | 389 | where: { |
390 | url: actor.url | 390 | [Op.or]: [ |
391 | { | ||
392 | url: actor.url | ||
393 | }, | ||
394 | { | ||
395 | serverId: actor.serverId, | ||
396 | preferredUsername: actor.preferredUsername | ||
397 | } | ||
398 | ] | ||
391 | }, | 399 | }, |
392 | transaction: t | 400 | transaction: t |
393 | }) | 401 | }) |
394 | 402 | ||
403 | // Try to fix non HTTPS accounts of remote instances that fixed their URL afterwards | ||
404 | if (created !== true && actorCreated.url !== actor.url) { | ||
405 | // Only fix http://example.com/account/djidane to https://example.com/account/djidane | ||
406 | if (actorCreated.url.replace('http://', '') !== actor.url.replace('https://', '')) { | ||
407 | throw new Error(`Actor from DB with URL ${actorCreated.url} does not correspond to actor ${actor.url}`) | ||
408 | } | ||
409 | |||
410 | actorCreated.url = actor.url | ||
411 | await actorCreated.save({ transaction: t }) | ||
412 | } | ||
413 | |||
395 | if (actorCreated.type === 'Person' || actorCreated.type === 'Application') { | 414 | if (actorCreated.type === 'Person' || actorCreated.type === 'Application') { |
396 | actorCreated.Account = await saveAccount(actorCreated, result, t) as MAccountDefault | 415 | actorCreated.Account = await saveAccount(actorCreated, result, t) as MAccountDefault |
397 | actorCreated.Account.Actor = actorCreated | 416 | actorCreated.Account.Actor = actorCreated |