]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/activitypub/process/process-flag.ts
Manual approves followers only for the instance
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / process / process-flag.ts
index 1f8a80c140bb29758c718971d75a20ffda9696ad..e6e9084de2aa23edde37192b2b38e29d9fc1c062 100644 (file)
@@ -8,7 +8,7 @@ import { getOrCreateVideoAndAccountAndChannel } from '../videos'
 import { Notifier } from '../../notifier'
 import { getAPId } from '../../../helpers/activitypub'
 import { APProcessorOptions } from '../../../typings/activitypub-processor.model'
-import { SignatureActorModel } from '../../../typings/models'
+import { MActorSignature, MVideoAbuseVideo } from '../../../typings/models'
 
 async function processFlagActivity (options: APProcessorOptions<ActivityCreate | ActivityFlag>) {
   const { activity, byActor } = options
@@ -23,31 +23,39 @@ export {
 
 // ---------------------------------------------------------------------------
 
-async function processCreateVideoAbuse (activity: ActivityCreate | ActivityFlag, byActor: SignatureActorModel) {
+async function processCreateVideoAbuse (activity: ActivityCreate | ActivityFlag, byActor: MActorSignature) {
   const flag = activity.type === 'Flag' ? activity : (activity.object as VideoAbuseObject)
 
-  logger.debug('Reporting remote abuse for video %s.', getAPId(flag.object))
-
   const account = byActor.Account
   if (!account) throw new Error('Cannot create video abuse with the non account actor ' + byActor.url)
 
-  const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: flag.object })
+  const objects = Array.isArray(flag.object) ? flag.object : [ flag.object ]
 
-  const videoAbuse = await sequelizeTypescript.transaction(async t => {
-    const videoAbuseData = {
-      reporterAccountId: account.id,
-      reason: flag.content,
-      videoId: video.id,
-      state: VideoAbuseState.PENDING
-    }
+  for (const object of objects) {
+    try {
+      logger.debug('Reporting remote abuse for video %s.', getAPId(object))
+
+      const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: object })
 
-    const videoAbuseInstance = await VideoAbuseModel.create(videoAbuseData, { transaction: t })
-    videoAbuseInstance.Video = video
+      const videoAbuse = await sequelizeTypescript.transaction(async t => {
+        const videoAbuseData = {
+          reporterAccountId: account.id,
+          reason: flag.content,
+          videoId: video.id,
+          state: VideoAbuseState.PENDING
+        }
 
-    logger.info('Remote abuse for video uuid %s created', flag.object)
+        const videoAbuseInstance = await VideoAbuseModel.create(videoAbuseData, { transaction: t }) as MVideoAbuseVideo
+        videoAbuseInstance.Video = video
 
-    return videoAbuseInstance
-  })
+        logger.info('Remote abuse for video uuid %s created', flag.object)
 
-  Notifier.Instance.notifyOnNewVideoAbuse(videoAbuse)
+        return videoAbuseInstance
+      })
+
+      Notifier.Instance.notifyOnNewVideoAbuse(videoAbuse)
+    } catch (err) {
+      logger.debug('Cannot process report of %s. (Maybe not a video abuse).', getAPId(object), { err })
+    }
+  }
 }