X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Factivitypub%2Fprocess%2Fprocess-update.ts;h=1bdf23d6ffbd3ff5b5fa85f06d37519b95a34407;hb=ec903c010ecc54ec2acad0bf2cf10e7fbf6a0fa2;hp=54a9234bb16c0740fd111caa1b40ff281adbb419;hpb=1735c825726edaa0af5035cb6cbb0cc0db502c6d;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/activitypub/process/process-update.ts b/server/lib/activitypub/process/process-update.ts index 54a9234bb..1bdf23d6f 100644 --- a/server/lib/activitypub/process/process-update.ts +++ b/server/lib/activitypub/process/process-update.ts @@ -2,11 +2,11 @@ import { ActivityUpdate, CacheFileObject, VideoTorrentObject } from '../../../.. import { ActivityPubActor } from '../../../../shared/models/activitypub/activitypub-actor' import { resetSequelizeInstance, retryTransactionWrapper } from '../../../helpers/database-utils' import { logger } from '../../../helpers/logger' -import { sequelizeTypescript } from '../../../initializers' +import { sequelizeTypescript } from '../../../initializers/database' import { AccountModel } from '../../../models/account/account' import { ActorModel } from '../../../models/activitypub/actor' import { VideoChannelModel } from '../../../models/video/video-channel' -import { fetchAvatarIfExists, updateActorAvatarInstance, updateActorInstance } from '../actor' +import { getAvatarInfoIfExists, updateActorAvatarInstance, updateActorInstance } from '../actor' import { getOrCreateVideoAndAccountAndChannel, getOrCreateVideoChannelFromVideoObject, updateVideoFromAP } from '../videos' import { sanitizeAndCheckVideoTorrentObject } from '../../../helpers/custom-validators/activitypub/videos' import { isCacheFileObjectValid } from '../../../helpers/custom-validators/activitypub/cache-file' @@ -14,8 +14,13 @@ import { createOrUpdateCacheFile } from '../cache-file' import { forwardVideoRelatedActivity } from '../send/utils' import { PlaylistObject } from '../../../../shared/models/activitypub/objects/playlist-object' import { createOrUpdateVideoPlaylist } from '../playlist' +import { APProcessorOptions } from '../../../types/activitypub-processor.model' +import { MActorSignature, MAccountIdActor } from '../../../types/models' +import { isRedundancyAccepted } from '@server/lib/redundancy' + +async function processUpdateActivity (options: APProcessorOptions) { + const { activity, byActor } = options -async function processUpdateActivity (activity: ActivityUpdate, byActor: ActorModel) { const objectType = activity.object.type if (objectType === 'Video') { @@ -49,7 +54,7 @@ export { // --------------------------------------------------------------------------- -async function processUpdateVideo (actor: ActorModel, activity: ActivityUpdate) { +async function processUpdateVideo (actor: MActorSignature, activity: ActivityUpdate) { const videoObject = activity.object as VideoTorrentObject if (sanitizeAndCheckVideoTorrentObject(videoObject) === false) { @@ -57,20 +62,25 @@ async function processUpdateVideo (actor: ActorModel, activity: ActivityUpdate) return undefined } - const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: videoObject.id, allowRefresh: false }) + const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: videoObject.id, allowRefresh: false, fetchType: 'all' }) const channelActor = await getOrCreateVideoChannelFromVideoObject(videoObject) + const account = actor.Account as MAccountIdActor + account.Actor = actor + const updateOptions = { video, videoObject, - account: actor.Account, + account, channel: channelActor.VideoChannel, overrideTo: activity.to } return updateVideoFromAP(updateOptions) } -async function processUpdateCacheFile (byActor: ActorModel, activity: ActivityUpdate) { +async function processUpdateCacheFile (byActor: MActorSignature, activity: ActivityUpdate) { + if (await isRedundancyAccepted(activity, byActor) !== true) return + const cacheFileObject = activity.object as CacheFileObject if (!isCacheFileObjectValid(cacheFileObject)) { @@ -95,13 +105,13 @@ async function processUpdateCacheFile (byActor: ActorModel, activity: ActivityUp async function processUpdateActor (actor: ActorModel, activity: ActivityUpdate) { const actorAttributesToUpdate = activity.object as ActivityPubActor - logger.debug('Updating remote account "%s".', actorAttributesToUpdate.uuid) + logger.debug('Updating remote account "%s".', actorAttributesToUpdate.url) let accountOrChannelInstance: AccountModel | VideoChannelModel let actorFieldsSave: object let accountOrChannelFieldsSave: object // Fetch icon? - const avatarName = await fetchAvatarIfExists(actorAttributesToUpdate) + const avatarInfo = await getAvatarInfoIfExists(actorAttributesToUpdate) try { await sequelizeTypescript.transaction(async t => { @@ -114,8 +124,10 @@ async function processUpdateActor (actor: ActorModel, activity: ActivityUpdate) await updateActorInstance(actor, actorAttributesToUpdate) - if (avatarName !== undefined) { - await updateActorAvatarInstance(actor, avatarName, t) + if (avatarInfo !== undefined) { + const avatarOptions = Object.assign({}, avatarInfo, { onDisk: false }) + + await updateActorAvatarInstance(actor, avatarOptions, t) } await actor.save({ transaction: t }) @@ -128,7 +140,7 @@ async function processUpdateActor (actor: ActorModel, activity: ActivityUpdate) await accountOrChannelInstance.save({ transaction: t }) }) - logger.info('Remote account with uuid %s updated', actorAttributesToUpdate.uuid) + logger.info('Remote account %s updated', actorAttributesToUpdate.url) } catch (err) { if (actor !== undefined && actorFieldsSave !== undefined) { resetSequelizeInstance(actor, actorFieldsSave) @@ -144,7 +156,7 @@ async function processUpdateActor (actor: ActorModel, activity: ActivityUpdate) } } -async function processUpdatePlaylist (byActor: ActorModel, activity: ActivityUpdate) { +async function processUpdatePlaylist (byActor: MActorSignature, activity: ActivityUpdate) { const playlistObject = activity.object as PlaylistObject const byAccount = byActor.Account