- // Like
- if (likes > 0) await sendLikeToVideoFollowers(actor, video, t)
- // Dislike
- if (dislikes > 0) await sendCreateDislikeToVideoFollowers(actor, video, t)
+ const actorUrl = getAPId(body.actor)
+ if (checkUrlsSameHost(actorUrl, rateUrl) !== true) {
+ throw new Error(`Rate url ${rateUrl} has not the same host than actor url ${actorUrl}`)
+ }
+
+ if (checkUrlsSameHost(body.id, rateUrl) !== true) {
+ throw new Error(`Rate url ${rateUrl} host is different from the AP object id ${body.id}`)
+ }
+
+ const actor = await getOrCreateActorAndServerAndModel(actorUrl)
+
+ const entry = {
+ videoId: video.id,
+ accountId: actor.Account.id,
+ type: rate,
+ url: body.id
+ }
+
+ const created = await AccountVideoRateModel.upsert(entry)
+
+ if (created) rateCounts += 1
+ } catch (err) {
+ logger.warn('Cannot add rate %s.', rateUrl, { err })
+ }
+ }, { concurrency: CRAWL_REQUEST_CONCURRENCY })
+
+ logger.info('Adding %d %s to video %s.', rateCounts, rate, video.uuid)
+
+ // This is "likes" and "dislikes"
+ if (rateCounts !== 0) {
+ const field = rate === 'like' ? 'likes' : 'dislikes'
+ await video.increment(field, { by: rateCounts })
+ }
+
+ return