X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Factivitypub%2Factor.ts;h=f802658cfe9d3b6c3509427964940f8c0b365deb;hb=cf59a2a0c367683ba35758419499bf6087c192ec;hp=5201bdeef392a2ed0c948495b56749f2a5f92877;hpb=0283eaac2a8e73006c66df3cf5bb9012e37450e5;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/activitypub/actor.ts b/server/lib/activitypub/actor.ts index 5201bdeef..f802658cf 100644 --- a/server/lib/activitypub/actor.ts +++ b/server/lib/activitypub/actor.ts @@ -38,7 +38,7 @@ import { } from '../../typings/models' // Set account keys, this could be long so process after the account creation and do not block the client -function setAsyncActorKeys (actor: MActor) { +function setAsyncActorKeys (actor: T) { return createPrivateAndPublicKeys() .then(({ publicKey, privateKey }) => { actor.publicKey = publicKey @@ -148,7 +148,7 @@ function buildActorInstance (type: ActivityPubActorType, url: string, preferredU sharedInboxUrl: WEBSERVER.URL + '/inbox', followersUrl: url + '/followers', followingUrl: url + '/following' - }) + }) as MActor } async function updateActorInstance (actorInstance: ActorModel, attributes: ActivityPubActor) { @@ -163,32 +163,38 @@ async function updateActorInstance (actorInstance: ActorModel, attributes: Activ actorInstance.followingCount = followingCount actorInstance.inboxUrl = attributes.inbox actorInstance.outboxUrl = attributes.outbox - actorInstance.sharedInboxUrl = attributes.endpoints.sharedInbox actorInstance.followersUrl = attributes.followers actorInstance.followingUrl = attributes.following + + if (attributes.endpoints && attributes.endpoints.sharedInbox) { + actorInstance.sharedInboxUrl = attributes.endpoints.sharedInbox + } } type AvatarInfo = { name: string, onDisk: boolean, fileUrl: string } async function updateActorAvatarInstance (actor: MActorDefault, info: AvatarInfo, t: Transaction) { - if (info.name !== undefined) { - if (actor.avatarId) { - try { - await actor.Avatar.destroy({ transaction: t }) - } catch (err) { - logger.error('Cannot remove old avatar of actor %s.', actor.url, { err }) - } - } + if (!info.name) return actor - const avatar = await AvatarModel.create({ - filename: info.name, - onDisk: info.onDisk, - fileUrl: info.fileUrl - }, { transaction: t }) + if (actor.Avatar) { + // Don't update the avatar if the filename did not change + if (actor.Avatar.fileUrl === info.fileUrl) return actor - actor.avatarId = avatar.id - actor.Avatar = avatar + try { + await actor.Avatar.destroy({ transaction: t }) + } catch (err) { + logger.error('Cannot remove old avatar of actor %s.', actor.url, { err }) + } } + const avatar = await AvatarModel.create({ + filename: info.name, + onDisk: info.onDisk, + fileUrl: info.fileUrl + }, { transaction: t }) + + actor.avatarId = avatar.id + actor.Avatar = avatar + return actor } @@ -437,9 +443,12 @@ async function fetchRemoteActor (actorUrl: string): Promise<{ statusCode?: numbe followingCount: followingCount, inboxUrl: actorJSON.inbox, outboxUrl: actorJSON.outbox, - sharedInboxUrl: actorJSON.endpoints.sharedInbox, followersUrl: actorJSON.followers, - followingUrl: actorJSON.following + followingUrl: actorJSON.following, + + sharedInboxUrl: actorJSON.endpoints && actorJSON.endpoints.sharedInbox + ? actorJSON.endpoints.sharedInbox + : null }) const avatarInfo = await getAvatarInfoIfExists(actorJSON)