aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-12-03 15:03:37 +0100
committerChocobozzz <me@florianbigard.com>2020-12-03 15:21:16 +0100
commit5147a6d945dcac2f15e85acd7db88d41d8bdc768 (patch)
treea4183495bc8580219628d877bd1401e8b667cc97 /server
parentb2dd58a8084fed3d3169be80ed34ada888189132 (diff)
downloadPeerTube-5147a6d945dcac2f15e85acd7db88d41d8bdc768.tar.gz
PeerTube-5147a6d945dcac2f15e85acd7db88d41d8bdc768.tar.zst
PeerTube-5147a6d945dcac2f15e85acd7db88d41d8bdc768.zip
Try to fix non HTTPS remote accounts
Diffstat (limited to 'server')
-rw-r--r--server/lib/activitypub/actor.ts25
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 @@
1import * as Bluebird from 'bluebird' 1import * as Bluebird from 'bluebird'
2import { Transaction } from 'sequelize' 2import { Op, Transaction } from 'sequelize'
3import { URL } from 'url' 3import { URL } from 'url'
4import { v4 as uuidv4 } from 'uuid' 4import { v4 as uuidv4 } from 'uuid'
5import { ActivityPubActor, ActivityPubActorType, ActivityPubOrderedCollection } from '../../../shared/models/activitypub' 5import { 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