]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/job-queue/handlers/activitypub-cleaner.ts
Fix server lint
[github/Chocobozzz/PeerTube.git] / server / lib / job-queue / handlers / activitypub-cleaner.ts
index 509dd1cb5159a95d2a3934fdb497aee426516428..a25f00b0a8491dad5ead3ac7013940d00a0e4a56 100644 (file)
@@ -1,6 +1,5 @@
 import { map } from 'bluebird'
-import { Job } from 'bull'
-import { checkUrlsSameHost } from '@server/helpers/activitypub'
+import { Job } from 'bullmq'
 import {
   isAnnounceActivityValid,
   isDislikeActivityValid,
@@ -9,6 +8,7 @@ import {
 import { sanitizeAndCheckVideoCommentObject } from '@server/helpers/custom-validators/activitypub/video-comments'
 import { doJSONRequest, PeerTubeRequestError } from '@server/helpers/requests'
 import { AP_CLEANER } from '@server/initializers/constants'
+import { checkUrlsSameHost } from '@server/lib/activitypub/url'
 import { Redis } from '@server/lib/redis'
 import { VideoModel } from '@server/models/video/video'
 import { VideoCommentModel } from '@server/models/video/video-comment'
@@ -29,12 +29,15 @@ async function processActivityPubCleaner (_job: Job) {
     const { bodyValidator, deleter, updater } = rateOptionsFactory()
 
     await map(rateUrls, async rateUrl => {
+      // TODO: remove when https://github.com/mastodon/mastodon/issues/13571 is fixed
+      if (rateUrl.includes('#')) return
+
       const result = await updateObjectIfNeeded({ url: rateUrl, bodyValidator, updater, deleter })
 
       if (result?.status === 'deleted') {
         const { videoId, type } = result.data
 
-        await VideoModel.updateRatesOf(videoId, type, undefined)
+        await VideoModel.syncLocalRates(videoId, type, undefined)
       }
     }, { concurrency: AP_CLEANER.CONCURRENCY })
   }
@@ -85,7 +88,7 @@ async function updateObjectIfNeeded <T> (options: {
     const { body } = await doJSONRequest<any>(url, { activityPub: true })
 
     // If not same id, check same host and update
-    if (!body || !body.id || !bodyValidator(body)) throw new Error(`Body or body id of ${url} is invalid`)
+    if (!body?.id || !bodyValidator(body)) throw new Error(`Body or body id of ${url} is invalid`)
 
     if (body.type === 'Tombstone') {
       return on404OrTombstone()