+import { isRedundancyAccepted } from '@server/lib/redundancy'
+import { ActorImageType } from '@shared/models'
import { ActivityUpdate, CacheFileObject, VideoObject } from '../../../../shared/models/activitypub'
import { ActivityPubActor } from '../../../../shared/models/activitypub/activitypub-actor'
+import { PlaylistObject } from '../../../../shared/models/activitypub/objects/playlist-object'
+import { isCacheFileObjectValid } from '../../../helpers/custom-validators/activitypub/cache-file'
+import { sanitizeAndCheckVideoTorrentObject } from '../../../helpers/custom-validators/activitypub/videos'
import { resetSequelizeInstance, retryTransactionWrapper } from '../../../helpers/database-utils'
import { logger } from '../../../helpers/logger'
import { sequelizeTypescript } from '../../../initializers/database'
import { AccountModel } from '../../../models/account/account'
-import { ActorModel } from '../../../models/activitypub/actor'
+import { ActorModel } from '../../../models/actor/actor'
import { VideoChannelModel } from '../../../models/video/video-channel'
+import { APProcessorOptions } from '../../../types/activitypub-processor.model'
+import { MActorSignature } from '../../../types/models'
import { getImageInfoIfExists, updateActorImageInstance, 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'
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'
-import { ActorImageType } from '@shared/models'
+import { forwardVideoRelatedActivity } from '../send/utils'
+import { APVideoUpdater, getOrCreateVideoAndAccountAndChannel } from '../videos'
async function processUpdateActivity (options: APProcessorOptions<ActivityUpdate>) {
const { activity, byActor } = options
const objectType = activity.object.type
if (objectType === 'Video') {
- return retryTransactionWrapper(processUpdateVideo, byActor, activity)
+ return retryTransactionWrapper(processUpdateVideo, activity)
}
if (objectType === 'Person' || objectType === 'Application' || objectType === 'Group') {
// ---------------------------------------------------------------------------
-async function processUpdateVideo (actor: MActorSignature, activity: ActivityUpdate) {
+async function processUpdateVideo (activity: ActivityUpdate) {
const videoObject = activity.object as VideoObject
if (sanitizeAndCheckVideoTorrentObject(videoObject) === false) {
// We did not have this video, it has been created so no need to update
if (created) return
- // Load new channel
- const channelActor = await getOrCreateVideoChannelFromVideoObject(videoObject)
-
- const account = actor.Account as MAccountIdActor
- account.Actor = actor
-
- const updateOptions = {
- video,
- videoObject,
- account,
- channel: channelActor.VideoChannel,
- overrideTo: activity.to
- }
- return updateVideoFromAP(updateOptions)
+ const updater = new APVideoUpdater(videoObject, video)
+ return updater.update(activity.to)
}
async function processUpdateCacheFile (byActor: MActorSignature, activity: ActivityUpdate) {
await updateActorInstance(actor, actorAttributesToUpdate)
- for (const imageInfo of [ avatarInfo, bannerInfo ]) {
- if (!imageInfo) continue
-
- const imageOptions = Object.assign({}, imageInfo, { onDisk: false })
-
- await updateActorImageInstance(actor, imageOptions, t)
- }
+ await updateActorImageInstance(actor, ActorImageType.AVATAR, avatarInfo, t)
+ await updateActorImageInstance(actor, ActorImageType.BANNER, bannerInfo, t)
await actor.save({ transaction: t })