-async function createRates (ratesUrl: string[], video: VideoModel, rate: VideoRateType) {
- let rateCounts = 0
-
- await Bluebird.map(ratesUrl, async rateUrl => {
- try {
- // Fetch url
- const { body } = await doRequest({
- uri: rateUrl,
- json: true,
- activityPub: true
- })
- if (!body || !body.actor) throw new Error('Body or body actor is invalid')
-
- 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 [ , created ] = await AccountVideoRateModel
- .findOrCreate({
- where: {
- videoId: video.id,
- accountId: actor.Account.id
- },
- defaults: {
- videoId: video.id,
- accountId: actor.Account.id,
- type: rate,
- url: body.id
- }
- })
+function getLocalRateUrl (rateType: VideoRateType, actor: MActorUrl, video: MVideoId) {
+ return rateType === 'like'
+ ? getVideoLikeActivityPubUrlByLocalActor(actor, video)
+ : getVideoDislikeActivityPubUrlByLocalActor(actor, video)
+}