From de94ac86a211dec657332d964693857ec235ce40 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 20 Nov 2020 11:21:08 +0100 Subject: Fix incorrect IDs in AP federation --- server/lib/activitypub/process/process-dislike.ts | 16 ++-- server/lib/activitypub/process/process-follow.ts | 16 ++-- server/lib/activitypub/process/process-like.ts | 13 ++-- server/lib/activitypub/send/send-accept.ts | 11 ++- server/lib/activitypub/send/send-dislike.ts | 4 +- server/lib/activitypub/send/send-flag.ts | 4 +- server/lib/activitypub/send/send-follow.ts | 8 +- server/lib/activitypub/send/send-like.ts | 4 +- server/lib/activitypub/send/send-reject.ts | 11 ++- server/lib/activitypub/send/send-undo.ts | 30 ++++---- server/lib/activitypub/send/send-view.ts | 10 +-- server/lib/activitypub/share.ts | 6 +- server/lib/activitypub/url.ts | 93 ++++++++++++----------- server/lib/activitypub/video-rates.ts | 10 +-- 14 files changed, 118 insertions(+), 118 deletions(-) (limited to 'server/lib/activitypub') diff --git a/server/lib/activitypub/process/process-dislike.ts b/server/lib/activitypub/process/process-dislike.ts index 0cd204501..635c8bfcc 100644 --- a/server/lib/activitypub/process/process-dislike.ts +++ b/server/lib/activitypub/process/process-dislike.ts @@ -3,11 +3,10 @@ import { DislikeObject } from '../../../../shared/models/activitypub/objects' import { retryTransactionWrapper } from '../../../helpers/database-utils' import { sequelizeTypescript } from '../../../initializers/database' import { AccountVideoRateModel } from '../../../models/account/account-video-rate' -import { getOrCreateVideoAndAccountAndChannel } from '../videos' -import { forwardVideoRelatedActivity } from '../send/utils' -import { getVideoDislikeActivityPubUrl } from '../url' import { APProcessorOptions } from '../../../types/activitypub-processor.model' import { MActorSignature } from '../../../types/models' +import { forwardVideoRelatedActivity } from '../send/utils' +import { getOrCreateVideoAndAccountAndChannel } from '../videos' async function processDislikeActivity (options: APProcessorOptions) { const { activity, byActor } = options @@ -23,7 +22,10 @@ export { // --------------------------------------------------------------------------- async function processDislike (activity: ActivityCreate | ActivityDislike, byActor: MActorSignature) { - const dislikeObject = activity.type === 'Dislike' ? activity.object : (activity.object as DislikeObject).object + const dislikeObject = activity.type === 'Dislike' + ? activity.object + : (activity.object as DislikeObject).object + const byAccount = byActor.Account if (!byAccount) throw new Error('Cannot create dislike with the non account actor ' + byActor.url) @@ -31,9 +33,7 @@ async function processDislike (activity: ActivityCreate | ActivityDislike, byAct const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: dislikeObject }) return sequelizeTypescript.transaction(async t => { - const url = getVideoDislikeActivityPubUrl(byActor, video) - - const existingRate = await AccountVideoRateModel.loadByAccountAndVideoOrUrl(byAccount.id, video.id, url) + const existingRate = await AccountVideoRateModel.loadByAccountAndVideoOrUrl(byAccount.id, video.id, activity.id) if (existingRate && existingRate.type === 'dislike') return await video.increment('dislikes', { transaction: t }) @@ -46,7 +46,7 @@ async function processDislike (activity: ActivityCreate | ActivityDislike, byAct rate.type = 'dislike' rate.videoId = video.id rate.accountId = byAccount.id - rate.url = url + rate.url = activity.id await rate.save({ transaction: t }) diff --git a/server/lib/activitypub/process/process-follow.ts b/server/lib/activitypub/process/process-follow.ts index 7eb7e828d..076ad9cf4 100644 --- a/server/lib/activitypub/process/process-follow.ts +++ b/server/lib/activitypub/process/process-follow.ts @@ -15,9 +15,11 @@ import { getServerActor } from '@server/models/application/application' async function processFollowActivity (options: APProcessorOptions) { const { activity, byActor } = options - const activityObject = getAPId(activity.object) - return retryTransactionWrapper(processFollow, byActor, activityObject) + const activityId = activity.id + const objectId = getAPId(activity.object) + + return retryTransactionWrapper(processFollow, byActor, activityId, objectId) } // --------------------------------------------------------------------------- @@ -28,7 +30,7 @@ export { // --------------------------------------------------------------------------- -async function processFollow (byActor: MActorSignature, targetActorURL: string) { +async function processFollow (byActor: MActorSignature, activityId: string, targetActorURL: string) { const { actorFollow, created, isFollowingInstance, targetActor } = await sequelizeTypescript.transaction(async t => { const targetActor = await ActorModel.loadByUrlAndPopulateAccountAndChannel(targetActorURL, t) @@ -41,7 +43,7 @@ async function processFollow (byActor: MActorSignature, targetActorURL: string) if (isFollowingInstance && CONFIG.FOLLOWERS.INSTANCE.ENABLED === false) { logger.info('Rejecting %s because instance followers are disabled.', targetActor.url) - await sendReject(byActor, targetActor) + await sendReject(activityId, byActor, targetActor) return { actorFollow: undefined as MActorFollowActors } } @@ -54,7 +56,11 @@ async function processFollow (byActor: MActorSignature, targetActorURL: string) defaults: { actorId: byActor.id, targetActorId: targetActor.id, - state: CONFIG.FOLLOWERS.INSTANCE.MANUAL_APPROVAL ? 'pending' : 'accepted' + url: activityId, + + state: CONFIG.FOLLOWERS.INSTANCE.MANUAL_APPROVAL + ? 'pending' + : 'accepted' }, transaction: t }) diff --git a/server/lib/activitypub/process/process-like.ts b/server/lib/activitypub/process/process-like.ts index b800a5618..6acc097b1 100644 --- a/server/lib/activitypub/process/process-like.ts +++ b/server/lib/activitypub/process/process-like.ts @@ -1,13 +1,12 @@ import { ActivityLike } from '../../../../shared/models/activitypub' +import { getAPId } from '../../../helpers/activitypub' import { retryTransactionWrapper } from '../../../helpers/database-utils' import { sequelizeTypescript } from '../../../initializers/database' import { AccountVideoRateModel } from '../../../models/account/account-video-rate' -import { forwardVideoRelatedActivity } from '../send/utils' -import { getOrCreateVideoAndAccountAndChannel } from '../videos' -import { getVideoLikeActivityPubUrl } from '../url' -import { getAPId } from '../../../helpers/activitypub' import { APProcessorOptions } from '../../../types/activitypub-processor.model' import { MActorSignature } from '../../../types/models' +import { forwardVideoRelatedActivity } from '../send/utils' +import { getOrCreateVideoAndAccountAndChannel } from '../videos' async function processLikeActivity (options: APProcessorOptions) { const { activity, byActor } = options @@ -31,9 +30,7 @@ async function processLikeVideo (byActor: MActorSignature, activity: ActivityLik const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: videoUrl }) return sequelizeTypescript.transaction(async t => { - const url = getVideoLikeActivityPubUrl(byActor, video) - - const existingRate = await AccountVideoRateModel.loadByAccountAndVideoOrUrl(byAccount.id, video.id, url) + const existingRate = await AccountVideoRateModel.loadByAccountAndVideoOrUrl(byAccount.id, video.id, activity.id) if (existingRate && existingRate.type === 'like') return if (existingRate && existingRate.type === 'dislike') { @@ -46,7 +43,7 @@ async function processLikeVideo (byActor: MActorSignature, activity: ActivityLik rate.type = 'like' rate.videoId = video.id rate.accountId = byAccount.id - rate.url = url + rate.url = activity.id await rate.save({ transaction: t }) diff --git a/server/lib/activitypub/send/send-accept.ts b/server/lib/activitypub/send/send-accept.ts index 50e192bdd..bb387e2c0 100644 --- a/server/lib/activitypub/send/send-accept.ts +++ b/server/lib/activitypub/send/send-accept.ts @@ -1,9 +1,9 @@ import { ActivityAccept, ActivityFollow } from '../../../../shared/models/activitypub' -import { getActorFollowAcceptActivityPubUrl, getActorFollowActivityPubUrl } from '../url' -import { unicastTo } from './utils' -import { buildFollowActivity } from './send-follow' import { logger } from '../../../helpers/logger' import { MActor, MActorFollowActors } from '../../../types/models' +import { getLocalActorFollowAcceptActivityPubUrl } from '../url' +import { buildFollowActivity } from './send-follow' +import { unicastTo } from './utils' function sendAccept (actorFollow: MActorFollowActors) { const follower = actorFollow.ActorFollower @@ -16,10 +16,9 @@ function sendAccept (actorFollow: MActorFollowActors) { logger.info('Creating job to accept follower %s.', follower.url) - const followUrl = getActorFollowActivityPubUrl(follower, me) - const followData = buildFollowActivity(followUrl, follower, me) + const followData = buildFollowActivity(actorFollow.url, follower, me) - const url = getActorFollowAcceptActivityPubUrl(actorFollow) + const url = getLocalActorFollowAcceptActivityPubUrl(actorFollow) const data = buildAcceptActivity(url, me, followData) return unicastTo(data, me, follower.inboxUrl) diff --git a/server/lib/activitypub/send/send-dislike.ts b/server/lib/activitypub/send/send-dislike.ts index 1bb7dc937..274230535 100644 --- a/server/lib/activitypub/send/send-dislike.ts +++ b/server/lib/activitypub/send/send-dislike.ts @@ -1,5 +1,5 @@ import { Transaction } from 'sequelize' -import { getVideoDislikeActivityPubUrl } from '../url' +import { getVideoDislikeActivityPubUrlByLocalActor } from '../url' import { logger } from '../../../helpers/logger' import { ActivityAudience, ActivityDislike } from '../../../../shared/models/activitypub' import { sendVideoRelatedActivity } from './utils' @@ -10,7 +10,7 @@ function sendDislike (byActor: MActor, video: MVideoAccountLight, t: Transaction logger.info('Creating job to dislike %s.', video.url) const activityBuilder = (audience: ActivityAudience) => { - const url = getVideoDislikeActivityPubUrl(byActor, video) + const url = getVideoDislikeActivityPubUrlByLocalActor(byActor, video) return buildDislikeActivity(url, byActor, video, audience) } diff --git a/server/lib/activitypub/send/send-flag.ts b/server/lib/activitypub/send/send-flag.ts index 821637ec8..b0483b5a0 100644 --- a/server/lib/activitypub/send/send-flag.ts +++ b/server/lib/activitypub/send/send-flag.ts @@ -3,13 +3,13 @@ import { ActivityAudience, ActivityFlag } from '../../../../shared/models/activi import { logger } from '../../../helpers/logger' import { MAbuseAP, MAccountLight, MActor } from '../../../types/models' import { audiencify, getAudience } from '../audience' -import { getAbuseActivityPubUrl } from '../url' +import { getLocalAbuseActivityPubUrl } from '../url' import { unicastTo } from './utils' function sendAbuse (byActor: MActor, abuse: MAbuseAP, flaggedAccount: MAccountLight, t: Transaction) { if (!flaggedAccount.Actor.serverId) return // Local user - const url = getAbuseActivityPubUrl(abuse) + const url = getLocalAbuseActivityPubUrl(abuse) logger.info('Creating job to send abuse %s.', url) diff --git a/server/lib/activitypub/send/send-follow.ts b/server/lib/activitypub/send/send-follow.ts index 08f1d83f9..9219640dd 100644 --- a/server/lib/activitypub/send/send-follow.ts +++ b/server/lib/activitypub/send/send-follow.ts @@ -1,9 +1,8 @@ +import { Transaction } from 'sequelize' import { ActivityFollow } from '../../../../shared/models/activitypub' -import { getActorFollowActivityPubUrl } from '../url' -import { unicastTo } from './utils' import { logger } from '../../../helpers/logger' -import { Transaction } from 'sequelize' import { MActor, MActorFollowActors } from '../../../types/models' +import { unicastTo } from './utils' function sendFollow (actorFollow: MActorFollowActors, t: Transaction) { const me = actorFollow.ActorFollower @@ -14,8 +13,7 @@ function sendFollow (actorFollow: MActorFollowActors, t: Transaction) { logger.info('Creating job to send follow request to %s.', following.url) - const url = getActorFollowActivityPubUrl(me, following) - const data = buildFollowActivity(url, me, following) + const data = buildFollowActivity(actorFollow.url, me, following) t.afterCommit(() => unicastTo(data, me, following.inboxUrl)) } diff --git a/server/lib/activitypub/send/send-like.ts b/server/lib/activitypub/send/send-like.ts index 29fcfc404..ed6dfcf56 100644 --- a/server/lib/activitypub/send/send-like.ts +++ b/server/lib/activitypub/send/send-like.ts @@ -1,6 +1,6 @@ import { Transaction } from 'sequelize' import { ActivityAudience, ActivityLike } from '../../../../shared/models/activitypub' -import { getVideoLikeActivityPubUrl } from '../url' +import { getVideoLikeActivityPubUrlByLocalActor } from '../url' import { sendVideoRelatedActivity } from './utils' import { audiencify, getAudience } from '../audience' import { logger } from '../../../helpers/logger' @@ -10,7 +10,7 @@ function sendLike (byActor: MActor, video: MVideoAccountLight, t: Transaction) { logger.info('Creating job to like %s.', video.url) const activityBuilder = (audience: ActivityAudience) => { - const url = getVideoLikeActivityPubUrl(byActor, video) + const url = getVideoLikeActivityPubUrlByLocalActor(byActor, video) return buildLikeActivity(url, byActor, video, audience) } diff --git a/server/lib/activitypub/send/send-reject.ts b/server/lib/activitypub/send/send-reject.ts index befbcb8da..8d74a7848 100644 --- a/server/lib/activitypub/send/send-reject.ts +++ b/server/lib/activitypub/send/send-reject.ts @@ -1,11 +1,11 @@ import { ActivityFollow, ActivityReject } from '../../../../shared/models/activitypub' -import { getActorFollowActivityPubUrl, getActorFollowRejectActivityPubUrl } from '../url' -import { unicastTo } from './utils' -import { buildFollowActivity } from './send-follow' import { logger } from '../../../helpers/logger' import { MActor } from '../../../types/models' +import { getLocalActorFollowRejectActivityPubUrl } from '../url' +import { buildFollowActivity } from './send-follow' +import { unicastTo } from './utils' -function sendReject (follower: MActor, following: MActor) { +function sendReject (followUrl: string, follower: MActor, following: MActor) { if (!follower.serverId) { // This should never happen logger.warn('Do not sending reject to local follower.') return @@ -13,10 +13,9 @@ function sendReject (follower: MActor, following: MActor) { logger.info('Creating job to reject follower %s.', follower.url) - const followUrl = getActorFollowActivityPubUrl(follower, following) const followData = buildFollowActivity(followUrl, follower, following) - const url = getActorFollowRejectActivityPubUrl(follower, following) + const url = getLocalActorFollowRejectActivityPubUrl(follower, following) const data = buildRejectActivity(url, following, followData) return unicastTo(data, following, follower.inboxUrl) diff --git a/server/lib/activitypub/send/send-undo.ts b/server/lib/activitypub/send/send-undo.ts index 6ed343300..352c158fd 100644 --- a/server/lib/activitypub/send/send-undo.ts +++ b/server/lib/activitypub/send/send-undo.ts @@ -8,18 +8,11 @@ import { ActivityLike, ActivityUndo } from '../../../../shared/models/activitypub' -import { VideoModel } from '../../../models/video/video' -import { getActorFollowActivityPubUrl, getUndoActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoLikeActivityPubUrl } from '../url' -import { broadcastToFollowers, sendVideoRelatedActivity, unicastTo } from './utils' -import { audiencify, getAudience } from '../audience' -import { buildCreateActivity } from './send-create' -import { buildFollowActivity } from './send-follow' -import { buildLikeActivity } from './send-like' -import { buildAnnounceWithVideoAudience } from './send-announce' import { logger } from '../../../helpers/logger' -import { buildDislikeActivity } from './send-dislike' +import { VideoModel } from '../../../models/video/video' import { - MActor, MActorAudience, + MActor, + MActorAudience, MActorFollowActors, MActorLight, MVideo, @@ -27,6 +20,14 @@ import { MVideoRedundancyVideo, MVideoShare } from '../../../types/models' +import { audiencify, getAudience } from '../audience' +import { getUndoActivityPubUrl, getVideoDislikeActivityPubUrlByLocalActor, getVideoLikeActivityPubUrlByLocalActor } from '../url' +import { buildAnnounceWithVideoAudience } from './send-announce' +import { buildCreateActivity } from './send-create' +import { buildDislikeActivity } from './send-dislike' +import { buildFollowActivity } from './send-follow' +import { buildLikeActivity } from './send-like' +import { broadcastToFollowers, sendVideoRelatedActivity, unicastTo } from './utils' function sendUndoFollow (actorFollow: MActorFollowActors, t: Transaction) { const me = actorFollow.ActorFollower @@ -37,10 +38,9 @@ function sendUndoFollow (actorFollow: MActorFollowActors, t: Transaction) { logger.info('Creating job to send an unfollow request to %s.', following.url) - const followUrl = getActorFollowActivityPubUrl(me, following) - const undoUrl = getUndoActivityPubUrl(followUrl) + const undoUrl = getUndoActivityPubUrl(actorFollow.url) - const followActivity = buildFollowActivity(followUrl, me, following) + const followActivity = buildFollowActivity(actorFollow.url, me, following) const undoActivity = undoActivityData(undoUrl, me, followActivity) t.afterCommit(() => unicastTo(undoActivity, me, following.inboxUrl)) @@ -61,7 +61,7 @@ async function sendUndoAnnounce (byActor: MActorLight, videoShare: MVideoShare, async function sendUndoLike (byActor: MActor, video: MVideoAccountLight, t: Transaction) { logger.info('Creating job to undo a like of video %s.', video.url) - const likeUrl = getVideoLikeActivityPubUrl(byActor, video) + const likeUrl = getVideoLikeActivityPubUrlByLocalActor(byActor, video) const likeActivity = buildLikeActivity(likeUrl, byActor, video) return sendUndoVideoRelatedActivity({ byActor, video, url: likeUrl, activity: likeActivity, transaction: t }) @@ -70,7 +70,7 @@ async function sendUndoLike (byActor: MActor, video: MVideoAccountLight, t: Tran async function sendUndoDislike (byActor: MActor, video: MVideoAccountLight, t: Transaction) { logger.info('Creating job to undo a dislike of video %s.', video.url) - const dislikeUrl = getVideoDislikeActivityPubUrl(byActor, video) + const dislikeUrl = getVideoDislikeActivityPubUrlByLocalActor(byActor, video) const dislikeActivity = buildDislikeActivity(dislikeUrl, byActor, video) return sendUndoVideoRelatedActivity({ byActor, video, url: dislikeUrl, activity: dislikeActivity, transaction: t }) diff --git a/server/lib/activitypub/send/send-view.ts b/server/lib/activitypub/send/send-view.ts index 3358188a2..9254dc7c5 100644 --- a/server/lib/activitypub/send/send-view.ts +++ b/server/lib/activitypub/send/send-view.ts @@ -1,17 +1,17 @@ import { Transaction } from 'sequelize' +import { MActorAudience, MVideoImmutable, MVideoUrl } from '@server/types/models' import { ActivityAudience, ActivityView } from '../../../../shared/models/activitypub' +import { logger } from '../../../helpers/logger' import { ActorModel } from '../../../models/activitypub/actor' -import { getVideoLikeActivityPubUrl } from '../url' -import { sendVideoRelatedActivity } from './utils' import { audiencify, getAudience } from '../audience' -import { logger } from '../../../helpers/logger' -import { MActorAudience, MVideoImmutable, MVideoUrl } from '@server/types/models' +import { getLocalVideoViewActivityPubUrl } from '../url' +import { sendVideoRelatedActivity } from './utils' async function sendView (byActor: ActorModel, video: MVideoImmutable, t: Transaction) { logger.info('Creating job to send view of %s.', video.url) const activityBuilder = (audience: ActivityAudience) => { - const url = getVideoLikeActivityPubUrl(byActor, video) + const url = getLocalVideoViewActivityPubUrl(byActor, video) return buildViewActivity(url, byActor, video, audience) } diff --git a/server/lib/activitypub/share.ts b/server/lib/activitypub/share.ts index 5e426f5db..1f8a8f3c4 100644 --- a/server/lib/activitypub/share.ts +++ b/server/lib/activitypub/share.ts @@ -1,7 +1,7 @@ import { Transaction } from 'sequelize' import { VideoShareModel } from '../../models/video/video-share' import { sendUndoAnnounce, sendVideoAnnounce } from './send' -import { getVideoAnnounceActivityPubUrl } from './url' +import { getLocalVideoAnnounceActivityPubUrl } from './url' import * as Bluebird from 'bluebird' import { doRequest } from '../../helpers/requests' import { getOrCreateActorAndServerAndModel } from './actor' @@ -74,7 +74,7 @@ export { async function shareByServer (video: MVideo, t: Transaction) { const serverActor = await getServerActor() - const serverShareUrl = getVideoAnnounceActivityPubUrl(serverActor, video) + const serverShareUrl = getLocalVideoAnnounceActivityPubUrl(serverActor, video) const [ serverShare ] = await VideoShareModel.findOrCreate({ defaults: { actorId: serverActor.id, @@ -91,7 +91,7 @@ async function shareByServer (video: MVideo, t: Transaction) { } async function shareByVideoChannel (video: MVideoAccountLight, t: Transaction) { - const videoChannelShareUrl = getVideoAnnounceActivityPubUrl(video.VideoChannel.Actor, video) + const videoChannelShareUrl = getLocalVideoAnnounceActivityPubUrl(video.VideoChannel.Actor, video) const [ videoChannelShare ] = await VideoShareModel.findOrCreate({ defaults: { actorId: video.VideoChannel.actorId, diff --git a/server/lib/activitypub/url.ts b/server/lib/activitypub/url.ts index 58030be2c..ad6a1d1fd 100644 --- a/server/lib/activitypub/url.ts +++ b/server/lib/activitypub/url.ts @@ -1,102 +1,102 @@ import { WEBSERVER } from '../../initializers/constants' import { + MAbuseId, MActor, MActorFollowActors, MActorId, MActorUrl, MCommentId, MVideoId, + MVideoPlaylistElement, MVideoUrl, - MVideoUUID, - MAbuseId, - MVideoPlaylistElement + MVideoUUID } from '../../types/models' -import { MVideoPlaylist, MVideoPlaylistUUID } from '../../types/models/video/video-playlist' import { MVideoFileVideoUUID } from '../../types/models/video/video-file' +import { MVideoPlaylist, MVideoPlaylistUUID } from '../../types/models/video/video-playlist' import { MStreamingPlaylist } from '../../types/models/video/video-streaming-playlist' -function getVideoActivityPubUrl (video: MVideoUUID) { +function getLocalVideoActivityPubUrl (video: MVideoUUID) { return WEBSERVER.URL + '/videos/watch/' + video.uuid } -function getVideoPlaylistActivityPubUrl (videoPlaylist: MVideoPlaylist) { +function getLocalVideoPlaylistActivityPubUrl (videoPlaylist: MVideoPlaylist) { return WEBSERVER.URL + '/video-playlists/' + videoPlaylist.uuid } -function getVideoPlaylistElementActivityPubUrl (videoPlaylist: MVideoPlaylistUUID, videoPlaylistElement: MVideoPlaylistElement) { +function getLocalVideoPlaylistElementActivityPubUrl (videoPlaylist: MVideoPlaylistUUID, videoPlaylistElement: MVideoPlaylistElement) { return WEBSERVER.URL + '/video-playlists/' + videoPlaylist.uuid + '/videos/' + videoPlaylistElement.id } -function getVideoCacheFileActivityPubUrl (videoFile: MVideoFileVideoUUID) { +function getLocalVideoCacheFileActivityPubUrl (videoFile: MVideoFileVideoUUID) { const suffixFPS = videoFile.fps && videoFile.fps !== -1 ? '-' + videoFile.fps : '' return `${WEBSERVER.URL}/redundancy/videos/${videoFile.Video.uuid}/${videoFile.resolution}${suffixFPS}` } -function getVideoCacheStreamingPlaylistActivityPubUrl (video: MVideoUUID, playlist: MStreamingPlaylist) { +function getLocalVideoCacheStreamingPlaylistActivityPubUrl (video: MVideoUUID, playlist: MStreamingPlaylist) { return `${WEBSERVER.URL}/redundancy/streaming-playlists/${playlist.getStringType()}/${video.uuid}` } -function getVideoCommentActivityPubUrl (video: MVideoUUID, videoComment: MCommentId) { +function getLocalVideoCommentActivityPubUrl (video: MVideoUUID, videoComment: MCommentId) { return WEBSERVER.URL + '/videos/watch/' + video.uuid + '/comments/' + videoComment.id } -function getVideoChannelActivityPubUrl (videoChannelName: string) { +function getLocalVideoChannelActivityPubUrl (videoChannelName: string) { return WEBSERVER.URL + '/video-channels/' + videoChannelName } -function getAccountActivityPubUrl (accountName: string) { +function getLocalAccountActivityPubUrl (accountName: string) { return WEBSERVER.URL + '/accounts/' + accountName } -function getAbuseActivityPubUrl (abuse: MAbuseId) { +function getLocalAbuseActivityPubUrl (abuse: MAbuseId) { return WEBSERVER.URL + '/admin/abuses/' + abuse.id } -function getVideoViewActivityPubUrl (byActor: MActorUrl, video: MVideoId) { +function getLocalVideoViewActivityPubUrl (byActor: MActorUrl, video: MVideoId) { return byActor.url + '/views/videos/' + video.id + '/' + new Date().toISOString() } -function getVideoLikeActivityPubUrl (byActor: MActorUrl, video: MVideoId) { +function getVideoLikeActivityPubUrlByLocalActor (byActor: MActorUrl, video: MVideoId) { return byActor.url + '/likes/' + video.id } -function getVideoDislikeActivityPubUrl (byActor: MActorUrl, video: MVideoId) { +function getVideoDislikeActivityPubUrlByLocalActor (byActor: MActorUrl, video: MVideoId) { return byActor.url + '/dislikes/' + video.id } -function getVideoSharesActivityPubUrl (video: MVideoUrl) { +function getLocalVideoSharesActivityPubUrl (video: MVideoUrl) { return video.url + '/announces' } -function getVideoCommentsActivityPubUrl (video: MVideoUrl) { +function getLocalVideoCommentsActivityPubUrl (video: MVideoUrl) { return video.url + '/comments' } -function getVideoLikesActivityPubUrl (video: MVideoUrl) { +function getLocalVideoLikesActivityPubUrl (video: MVideoUrl) { return video.url + '/likes' } -function getVideoDislikesActivityPubUrl (video: MVideoUrl) { +function getLocalVideoDislikesActivityPubUrl (video: MVideoUrl) { return video.url + '/dislikes' } -function getActorFollowActivityPubUrl (follower: MActor, following: MActorId) { +function getLocalActorFollowActivityPubUrl (follower: MActor, following: MActorId) { return follower.url + '/follows/' + following.id } -function getActorFollowAcceptActivityPubUrl (actorFollow: MActorFollowActors) { +function getLocalActorFollowAcceptActivityPubUrl (actorFollow: MActorFollowActors) { const follower = actorFollow.ActorFollower const me = actorFollow.ActorFollowing - return follower.url + '/accepts/follows/' + me.id + return WEBSERVER.URL + '/accepts/follows/' + follower.id + '/' + me.id } -function getActorFollowRejectActivityPubUrl (follower: MActorUrl, following: MActorId) { - return follower.url + '/rejects/follows/' + following.id +function getLocalActorFollowRejectActivityPubUrl (follower: MActorId, following: MActorId) { + return WEBSERVER.URL + '/rejects/follows/' + follower.id + '/' + following.id } -function getVideoAnnounceActivityPubUrl (byActor: MActorId, video: MVideoUrl) { +function getLocalVideoAnnounceActivityPubUrl (byActor: MActorId, video: MVideoUrl) { return video.url + '/announces/' + byActor.id } @@ -113,27 +113,28 @@ function getUndoActivityPubUrl (originalUrl: string) { } export { - getVideoActivityPubUrl, - getVideoPlaylistElementActivityPubUrl, - getVideoPlaylistActivityPubUrl, - getVideoCacheStreamingPlaylistActivityPubUrl, - getVideoChannelActivityPubUrl, - getAccountActivityPubUrl, - getAbuseActivityPubUrl, - getActorFollowActivityPubUrl, - getActorFollowAcceptActivityPubUrl, - getVideoAnnounceActivityPubUrl, + getLocalVideoActivityPubUrl, + getLocalVideoPlaylistActivityPubUrl, + getLocalVideoPlaylistElementActivityPubUrl, + getLocalVideoCacheFileActivityPubUrl, + getLocalVideoCacheStreamingPlaylistActivityPubUrl, + getLocalVideoCommentActivityPubUrl, + getLocalVideoChannelActivityPubUrl, + getLocalAccountActivityPubUrl, + getLocalAbuseActivityPubUrl, + getLocalActorFollowActivityPubUrl, + getLocalActorFollowAcceptActivityPubUrl, + getLocalVideoAnnounceActivityPubUrl, getUpdateActivityPubUrl, getUndoActivityPubUrl, - getVideoViewActivityPubUrl, - getVideoLikeActivityPubUrl, - getVideoDislikeActivityPubUrl, - getActorFollowRejectActivityPubUrl, - getVideoCommentActivityPubUrl, + getVideoLikeActivityPubUrlByLocalActor, + getLocalVideoViewActivityPubUrl, + getVideoDislikeActivityPubUrlByLocalActor, + getLocalActorFollowRejectActivityPubUrl, getDeleteActivityPubUrl, - getVideoSharesActivityPubUrl, - getVideoCommentsActivityPubUrl, - getVideoLikesActivityPubUrl, - getVideoDislikesActivityPubUrl, - getVideoCacheFileActivityPubUrl + getLocalVideoSharesActivityPubUrl, + getLocalVideoCommentsActivityPubUrl, + getLocalVideoLikesActivityPubUrl, + getLocalVideoDislikesActivityPubUrl, + } diff --git a/server/lib/activitypub/video-rates.ts b/server/lib/activitypub/video-rates.ts index e09e5d9ec..581a2bca1 100644 --- a/server/lib/activitypub/video-rates.ts +++ b/server/lib/activitypub/video-rates.ts @@ -8,7 +8,7 @@ import { logger } from '../../helpers/logger' import { CRAWL_REQUEST_CONCURRENCY } from '../../initializers/constants' import { doRequest } from '../../helpers/requests' import { checkUrlsSameHost, getAPId } from '../../helpers/activitypub' -import { getVideoDislikeActivityPubUrl, getVideoLikeActivityPubUrl } from './url' +import { getVideoDislikeActivityPubUrlByLocalActor, getVideoLikeActivityPubUrlByLocalActor } from './url' import { sendDislike } from './send/send-dislike' import { MAccountActor, MActorUrl, MVideo, MVideoAccountLight, MVideoId } from '../../types/models' @@ -82,14 +82,14 @@ async function sendVideoRateChange ( if (dislikes > 0) await sendDislike(actor, video, t) } -function getRateUrl (rateType: VideoRateType, actor: MActorUrl, video: MVideoId) { +function getLocalRateUrl (rateType: VideoRateType, actor: MActorUrl, video: MVideoId) { return rateType === 'like' - ? getVideoLikeActivityPubUrl(actor, video) - : getVideoDislikeActivityPubUrl(actor, video) + ? getVideoLikeActivityPubUrlByLocalActor(actor, video) + : getVideoDislikeActivityPubUrlByLocalActor(actor, video) } export { - getRateUrl, + getLocalRateUrl, createRates, sendVideoRateChange } -- cgit v1.2.3