diff options
Diffstat (limited to 'server/lib')
20 files changed, 151 insertions, 148 deletions
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' | |||
3 | import { retryTransactionWrapper } from '../../../helpers/database-utils' | 3 | import { retryTransactionWrapper } from '../../../helpers/database-utils' |
4 | import { sequelizeTypescript } from '../../../initializers/database' | 4 | import { sequelizeTypescript } from '../../../initializers/database' |
5 | import { AccountVideoRateModel } from '../../../models/account/account-video-rate' | 5 | import { AccountVideoRateModel } from '../../../models/account/account-video-rate' |
6 | import { getOrCreateVideoAndAccountAndChannel } from '../videos' | ||
7 | import { forwardVideoRelatedActivity } from '../send/utils' | ||
8 | import { getVideoDislikeActivityPubUrl } from '../url' | ||
9 | import { APProcessorOptions } from '../../../types/activitypub-processor.model' | 6 | import { APProcessorOptions } from '../../../types/activitypub-processor.model' |
10 | import { MActorSignature } from '../../../types/models' | 7 | import { MActorSignature } from '../../../types/models' |
8 | import { forwardVideoRelatedActivity } from '../send/utils' | ||
9 | import { getOrCreateVideoAndAccountAndChannel } from '../videos' | ||
11 | 10 | ||
12 | async function processDislikeActivity (options: APProcessorOptions<ActivityCreate | ActivityDislike>) { | 11 | async function processDislikeActivity (options: APProcessorOptions<ActivityCreate | ActivityDislike>) { |
13 | const { activity, byActor } = options | 12 | const { activity, byActor } = options |
@@ -23,7 +22,10 @@ export { | |||
23 | // --------------------------------------------------------------------------- | 22 | // --------------------------------------------------------------------------- |
24 | 23 | ||
25 | async function processDislike (activity: ActivityCreate | ActivityDislike, byActor: MActorSignature) { | 24 | async function processDislike (activity: ActivityCreate | ActivityDislike, byActor: MActorSignature) { |
26 | const dislikeObject = activity.type === 'Dislike' ? activity.object : (activity.object as DislikeObject).object | 25 | const dislikeObject = activity.type === 'Dislike' |
26 | ? activity.object | ||
27 | : (activity.object as DislikeObject).object | ||
28 | |||
27 | const byAccount = byActor.Account | 29 | const byAccount = byActor.Account |
28 | 30 | ||
29 | if (!byAccount) throw new Error('Cannot create dislike with the non account actor ' + byActor.url) | 31 | 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 | |||
31 | const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: dislikeObject }) | 33 | const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: dislikeObject }) |
32 | 34 | ||
33 | return sequelizeTypescript.transaction(async t => { | 35 | return sequelizeTypescript.transaction(async t => { |
34 | const url = getVideoDislikeActivityPubUrl(byActor, video) | 36 | const existingRate = await AccountVideoRateModel.loadByAccountAndVideoOrUrl(byAccount.id, video.id, activity.id) |
35 | |||
36 | const existingRate = await AccountVideoRateModel.loadByAccountAndVideoOrUrl(byAccount.id, video.id, url) | ||
37 | if (existingRate && existingRate.type === 'dislike') return | 37 | if (existingRate && existingRate.type === 'dislike') return |
38 | 38 | ||
39 | await video.increment('dislikes', { transaction: t }) | 39 | await video.increment('dislikes', { transaction: t }) |
@@ -46,7 +46,7 @@ async function processDislike (activity: ActivityCreate | ActivityDislike, byAct | |||
46 | rate.type = 'dislike' | 46 | rate.type = 'dislike' |
47 | rate.videoId = video.id | 47 | rate.videoId = video.id |
48 | rate.accountId = byAccount.id | 48 | rate.accountId = byAccount.id |
49 | rate.url = url | 49 | rate.url = activity.id |
50 | 50 | ||
51 | await rate.save({ transaction: t }) | 51 | await rate.save({ transaction: t }) |
52 | 52 | ||
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' | |||
15 | 15 | ||
16 | async function processFollowActivity (options: APProcessorOptions<ActivityFollow>) { | 16 | async function processFollowActivity (options: APProcessorOptions<ActivityFollow>) { |
17 | const { activity, byActor } = options | 17 | const { activity, byActor } = options |
18 | const activityObject = getAPId(activity.object) | ||
19 | 18 | ||
20 | return retryTransactionWrapper(processFollow, byActor, activityObject) | 19 | const activityId = activity.id |
20 | const objectId = getAPId(activity.object) | ||
21 | |||
22 | return retryTransactionWrapper(processFollow, byActor, activityId, objectId) | ||
21 | } | 23 | } |
22 | 24 | ||
23 | // --------------------------------------------------------------------------- | 25 | // --------------------------------------------------------------------------- |
@@ -28,7 +30,7 @@ export { | |||
28 | 30 | ||
29 | // --------------------------------------------------------------------------- | 31 | // --------------------------------------------------------------------------- |
30 | 32 | ||
31 | async function processFollow (byActor: MActorSignature, targetActorURL: string) { | 33 | async function processFollow (byActor: MActorSignature, activityId: string, targetActorURL: string) { |
32 | const { actorFollow, created, isFollowingInstance, targetActor } = await sequelizeTypescript.transaction(async t => { | 34 | const { actorFollow, created, isFollowingInstance, targetActor } = await sequelizeTypescript.transaction(async t => { |
33 | const targetActor = await ActorModel.loadByUrlAndPopulateAccountAndChannel(targetActorURL, t) | 35 | const targetActor = await ActorModel.loadByUrlAndPopulateAccountAndChannel(targetActorURL, t) |
34 | 36 | ||
@@ -41,7 +43,7 @@ async function processFollow (byActor: MActorSignature, targetActorURL: string) | |||
41 | if (isFollowingInstance && CONFIG.FOLLOWERS.INSTANCE.ENABLED === false) { | 43 | if (isFollowingInstance && CONFIG.FOLLOWERS.INSTANCE.ENABLED === false) { |
42 | logger.info('Rejecting %s because instance followers are disabled.', targetActor.url) | 44 | logger.info('Rejecting %s because instance followers are disabled.', targetActor.url) |
43 | 45 | ||
44 | await sendReject(byActor, targetActor) | 46 | await sendReject(activityId, byActor, targetActor) |
45 | 47 | ||
46 | return { actorFollow: undefined as MActorFollowActors } | 48 | return { actorFollow: undefined as MActorFollowActors } |
47 | } | 49 | } |
@@ -54,7 +56,11 @@ async function processFollow (byActor: MActorSignature, targetActorURL: string) | |||
54 | defaults: { | 56 | defaults: { |
55 | actorId: byActor.id, | 57 | actorId: byActor.id, |
56 | targetActorId: targetActor.id, | 58 | targetActorId: targetActor.id, |
57 | state: CONFIG.FOLLOWERS.INSTANCE.MANUAL_APPROVAL ? 'pending' : 'accepted' | 59 | url: activityId, |
60 | |||
61 | state: CONFIG.FOLLOWERS.INSTANCE.MANUAL_APPROVAL | ||
62 | ? 'pending' | ||
63 | : 'accepted' | ||
58 | }, | 64 | }, |
59 | transaction: t | 65 | transaction: t |
60 | }) | 66 | }) |
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 @@ | |||
1 | import { ActivityLike } from '../../../../shared/models/activitypub' | 1 | import { ActivityLike } from '../../../../shared/models/activitypub' |
2 | import { getAPId } from '../../../helpers/activitypub' | ||
2 | import { retryTransactionWrapper } from '../../../helpers/database-utils' | 3 | import { retryTransactionWrapper } from '../../../helpers/database-utils' |
3 | import { sequelizeTypescript } from '../../../initializers/database' | 4 | import { sequelizeTypescript } from '../../../initializers/database' |
4 | import { AccountVideoRateModel } from '../../../models/account/account-video-rate' | 5 | import { AccountVideoRateModel } from '../../../models/account/account-video-rate' |
5 | import { forwardVideoRelatedActivity } from '../send/utils' | ||
6 | import { getOrCreateVideoAndAccountAndChannel } from '../videos' | ||
7 | import { getVideoLikeActivityPubUrl } from '../url' | ||
8 | import { getAPId } from '../../../helpers/activitypub' | ||
9 | import { APProcessorOptions } from '../../../types/activitypub-processor.model' | 6 | import { APProcessorOptions } from '../../../types/activitypub-processor.model' |
10 | import { MActorSignature } from '../../../types/models' | 7 | import { MActorSignature } from '../../../types/models' |
8 | import { forwardVideoRelatedActivity } from '../send/utils' | ||
9 | import { getOrCreateVideoAndAccountAndChannel } from '../videos' | ||
11 | 10 | ||
12 | async function processLikeActivity (options: APProcessorOptions<ActivityLike>) { | 11 | async function processLikeActivity (options: APProcessorOptions<ActivityLike>) { |
13 | const { activity, byActor } = options | 12 | const { activity, byActor } = options |
@@ -31,9 +30,7 @@ async function processLikeVideo (byActor: MActorSignature, activity: ActivityLik | |||
31 | const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: videoUrl }) | 30 | const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: videoUrl }) |
32 | 31 | ||
33 | return sequelizeTypescript.transaction(async t => { | 32 | return sequelizeTypescript.transaction(async t => { |
34 | const url = getVideoLikeActivityPubUrl(byActor, video) | 33 | const existingRate = await AccountVideoRateModel.loadByAccountAndVideoOrUrl(byAccount.id, video.id, activity.id) |
35 | |||
36 | const existingRate = await AccountVideoRateModel.loadByAccountAndVideoOrUrl(byAccount.id, video.id, url) | ||
37 | if (existingRate && existingRate.type === 'like') return | 34 | if (existingRate && existingRate.type === 'like') return |
38 | 35 | ||
39 | if (existingRate && existingRate.type === 'dislike') { | 36 | if (existingRate && existingRate.type === 'dislike') { |
@@ -46,7 +43,7 @@ async function processLikeVideo (byActor: MActorSignature, activity: ActivityLik | |||
46 | rate.type = 'like' | 43 | rate.type = 'like' |
47 | rate.videoId = video.id | 44 | rate.videoId = video.id |
48 | rate.accountId = byAccount.id | 45 | rate.accountId = byAccount.id |
49 | rate.url = url | 46 | rate.url = activity.id |
50 | 47 | ||
51 | await rate.save({ transaction: t }) | 48 | await rate.save({ transaction: t }) |
52 | 49 | ||
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 @@ | |||
1 | import { ActivityAccept, ActivityFollow } from '../../../../shared/models/activitypub' | 1 | import { ActivityAccept, ActivityFollow } from '../../../../shared/models/activitypub' |
2 | import { getActorFollowAcceptActivityPubUrl, getActorFollowActivityPubUrl } from '../url' | ||
3 | import { unicastTo } from './utils' | ||
4 | import { buildFollowActivity } from './send-follow' | ||
5 | import { logger } from '../../../helpers/logger' | 2 | import { logger } from '../../../helpers/logger' |
6 | import { MActor, MActorFollowActors } from '../../../types/models' | 3 | import { MActor, MActorFollowActors } from '../../../types/models' |
4 | import { getLocalActorFollowAcceptActivityPubUrl } from '../url' | ||
5 | import { buildFollowActivity } from './send-follow' | ||
6 | import { unicastTo } from './utils' | ||
7 | 7 | ||
8 | function sendAccept (actorFollow: MActorFollowActors) { | 8 | function sendAccept (actorFollow: MActorFollowActors) { |
9 | const follower = actorFollow.ActorFollower | 9 | const follower = actorFollow.ActorFollower |
@@ -16,10 +16,9 @@ function sendAccept (actorFollow: MActorFollowActors) { | |||
16 | 16 | ||
17 | logger.info('Creating job to accept follower %s.', follower.url) | 17 | logger.info('Creating job to accept follower %s.', follower.url) |
18 | 18 | ||
19 | const followUrl = getActorFollowActivityPubUrl(follower, me) | 19 | const followData = buildFollowActivity(actorFollow.url, follower, me) |
20 | const followData = buildFollowActivity(followUrl, follower, me) | ||
21 | 20 | ||
22 | const url = getActorFollowAcceptActivityPubUrl(actorFollow) | 21 | const url = getLocalActorFollowAcceptActivityPubUrl(actorFollow) |
23 | const data = buildAcceptActivity(url, me, followData) | 22 | const data = buildAcceptActivity(url, me, followData) |
24 | 23 | ||
25 | return unicastTo(data, me, follower.inboxUrl) | 24 | 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 @@ | |||
1 | import { Transaction } from 'sequelize' | 1 | import { Transaction } from 'sequelize' |
2 | import { getVideoDislikeActivityPubUrl } from '../url' | 2 | import { getVideoDislikeActivityPubUrlByLocalActor } from '../url' |
3 | import { logger } from '../../../helpers/logger' | 3 | import { logger } from '../../../helpers/logger' |
4 | import { ActivityAudience, ActivityDislike } from '../../../../shared/models/activitypub' | 4 | import { ActivityAudience, ActivityDislike } from '../../../../shared/models/activitypub' |
5 | import { sendVideoRelatedActivity } from './utils' | 5 | import { sendVideoRelatedActivity } from './utils' |
@@ -10,7 +10,7 @@ function sendDislike (byActor: MActor, video: MVideoAccountLight, t: Transaction | |||
10 | logger.info('Creating job to dislike %s.', video.url) | 10 | logger.info('Creating job to dislike %s.', video.url) |
11 | 11 | ||
12 | const activityBuilder = (audience: ActivityAudience) => { | 12 | const activityBuilder = (audience: ActivityAudience) => { |
13 | const url = getVideoDislikeActivityPubUrl(byActor, video) | 13 | const url = getVideoDislikeActivityPubUrlByLocalActor(byActor, video) |
14 | 14 | ||
15 | return buildDislikeActivity(url, byActor, video, audience) | 15 | return buildDislikeActivity(url, byActor, video, audience) |
16 | } | 16 | } |
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 | |||
3 | import { logger } from '../../../helpers/logger' | 3 | import { logger } from '../../../helpers/logger' |
4 | import { MAbuseAP, MAccountLight, MActor } from '../../../types/models' | 4 | import { MAbuseAP, MAccountLight, MActor } from '../../../types/models' |
5 | import { audiencify, getAudience } from '../audience' | 5 | import { audiencify, getAudience } from '../audience' |
6 | import { getAbuseActivityPubUrl } from '../url' | 6 | import { getLocalAbuseActivityPubUrl } from '../url' |
7 | import { unicastTo } from './utils' | 7 | import { unicastTo } from './utils' |
8 | 8 | ||
9 | function sendAbuse (byActor: MActor, abuse: MAbuseAP, flaggedAccount: MAccountLight, t: Transaction) { | 9 | function sendAbuse (byActor: MActor, abuse: MAbuseAP, flaggedAccount: MAccountLight, t: Transaction) { |
10 | if (!flaggedAccount.Actor.serverId) return // Local user | 10 | if (!flaggedAccount.Actor.serverId) return // Local user |
11 | 11 | ||
12 | const url = getAbuseActivityPubUrl(abuse) | 12 | const url = getLocalAbuseActivityPubUrl(abuse) |
13 | 13 | ||
14 | logger.info('Creating job to send abuse %s.', url) | 14 | logger.info('Creating job to send abuse %s.', url) |
15 | 15 | ||
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 @@ | |||
1 | import { Transaction } from 'sequelize' | ||
1 | import { ActivityFollow } from '../../../../shared/models/activitypub' | 2 | import { ActivityFollow } from '../../../../shared/models/activitypub' |
2 | import { getActorFollowActivityPubUrl } from '../url' | ||
3 | import { unicastTo } from './utils' | ||
4 | import { logger } from '../../../helpers/logger' | 3 | import { logger } from '../../../helpers/logger' |
5 | import { Transaction } from 'sequelize' | ||
6 | import { MActor, MActorFollowActors } from '../../../types/models' | 4 | import { MActor, MActorFollowActors } from '../../../types/models' |
5 | import { unicastTo } from './utils' | ||
7 | 6 | ||
8 | function sendFollow (actorFollow: MActorFollowActors, t: Transaction) { | 7 | function sendFollow (actorFollow: MActorFollowActors, t: Transaction) { |
9 | const me = actorFollow.ActorFollower | 8 | const me = actorFollow.ActorFollower |
@@ -14,8 +13,7 @@ function sendFollow (actorFollow: MActorFollowActors, t: Transaction) { | |||
14 | 13 | ||
15 | logger.info('Creating job to send follow request to %s.', following.url) | 14 | logger.info('Creating job to send follow request to %s.', following.url) |
16 | 15 | ||
17 | const url = getActorFollowActivityPubUrl(me, following) | 16 | const data = buildFollowActivity(actorFollow.url, me, following) |
18 | const data = buildFollowActivity(url, me, following) | ||
19 | 17 | ||
20 | t.afterCommit(() => unicastTo(data, me, following.inboxUrl)) | 18 | t.afterCommit(() => unicastTo(data, me, following.inboxUrl)) |
21 | } | 19 | } |
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 @@ | |||
1 | import { Transaction } from 'sequelize' | 1 | import { Transaction } from 'sequelize' |
2 | import { ActivityAudience, ActivityLike } from '../../../../shared/models/activitypub' | 2 | import { ActivityAudience, ActivityLike } from '../../../../shared/models/activitypub' |
3 | import { getVideoLikeActivityPubUrl } from '../url' | 3 | import { getVideoLikeActivityPubUrlByLocalActor } from '../url' |
4 | import { sendVideoRelatedActivity } from './utils' | 4 | import { sendVideoRelatedActivity } from './utils' |
5 | import { audiencify, getAudience } from '../audience' | 5 | import { audiencify, getAudience } from '../audience' |
6 | import { logger } from '../../../helpers/logger' | 6 | import { logger } from '../../../helpers/logger' |
@@ -10,7 +10,7 @@ function sendLike (byActor: MActor, video: MVideoAccountLight, t: Transaction) { | |||
10 | logger.info('Creating job to like %s.', video.url) | 10 | logger.info('Creating job to like %s.', video.url) |
11 | 11 | ||
12 | const activityBuilder = (audience: ActivityAudience) => { | 12 | const activityBuilder = (audience: ActivityAudience) => { |
13 | const url = getVideoLikeActivityPubUrl(byActor, video) | 13 | const url = getVideoLikeActivityPubUrlByLocalActor(byActor, video) |
14 | 14 | ||
15 | return buildLikeActivity(url, byActor, video, audience) | 15 | return buildLikeActivity(url, byActor, video, audience) |
16 | } | 16 | } |
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 @@ | |||
1 | import { ActivityFollow, ActivityReject } from '../../../../shared/models/activitypub' | 1 | import { ActivityFollow, ActivityReject } from '../../../../shared/models/activitypub' |
2 | import { getActorFollowActivityPubUrl, getActorFollowRejectActivityPubUrl } from '../url' | ||
3 | import { unicastTo } from './utils' | ||
4 | import { buildFollowActivity } from './send-follow' | ||
5 | import { logger } from '../../../helpers/logger' | 2 | import { logger } from '../../../helpers/logger' |
6 | import { MActor } from '../../../types/models' | 3 | import { MActor } from '../../../types/models' |
4 | import { getLocalActorFollowRejectActivityPubUrl } from '../url' | ||
5 | import { buildFollowActivity } from './send-follow' | ||
6 | import { unicastTo } from './utils' | ||
7 | 7 | ||
8 | function sendReject (follower: MActor, following: MActor) { | 8 | function sendReject (followUrl: string, follower: MActor, following: MActor) { |
9 | if (!follower.serverId) { // This should never happen | 9 | if (!follower.serverId) { // This should never happen |
10 | logger.warn('Do not sending reject to local follower.') | 10 | logger.warn('Do not sending reject to local follower.') |
11 | return | 11 | return |
@@ -13,10 +13,9 @@ function sendReject (follower: MActor, following: MActor) { | |||
13 | 13 | ||
14 | logger.info('Creating job to reject follower %s.', follower.url) | 14 | logger.info('Creating job to reject follower %s.', follower.url) |
15 | 15 | ||
16 | const followUrl = getActorFollowActivityPubUrl(follower, following) | ||
17 | const followData = buildFollowActivity(followUrl, follower, following) | 16 | const followData = buildFollowActivity(followUrl, follower, following) |
18 | 17 | ||
19 | const url = getActorFollowRejectActivityPubUrl(follower, following) | 18 | const url = getLocalActorFollowRejectActivityPubUrl(follower, following) |
20 | const data = buildRejectActivity(url, following, followData) | 19 | const data = buildRejectActivity(url, following, followData) |
21 | 20 | ||
22 | return unicastTo(data, following, follower.inboxUrl) | 21 | 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 { | |||
8 | ActivityLike, | 8 | ActivityLike, |
9 | ActivityUndo | 9 | ActivityUndo |
10 | } from '../../../../shared/models/activitypub' | 10 | } from '../../../../shared/models/activitypub' |
11 | import { VideoModel } from '../../../models/video/video' | ||
12 | import { getActorFollowActivityPubUrl, getUndoActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoLikeActivityPubUrl } from '../url' | ||
13 | import { broadcastToFollowers, sendVideoRelatedActivity, unicastTo } from './utils' | ||
14 | import { audiencify, getAudience } from '../audience' | ||
15 | import { buildCreateActivity } from './send-create' | ||
16 | import { buildFollowActivity } from './send-follow' | ||
17 | import { buildLikeActivity } from './send-like' | ||
18 | import { buildAnnounceWithVideoAudience } from './send-announce' | ||
19 | import { logger } from '../../../helpers/logger' | 11 | import { logger } from '../../../helpers/logger' |
20 | import { buildDislikeActivity } from './send-dislike' | 12 | import { VideoModel } from '../../../models/video/video' |
21 | import { | 13 | import { |
22 | MActor, MActorAudience, | 14 | MActor, |
15 | MActorAudience, | ||
23 | MActorFollowActors, | 16 | MActorFollowActors, |
24 | MActorLight, | 17 | MActorLight, |
25 | MVideo, | 18 | MVideo, |
@@ -27,6 +20,14 @@ import { | |||
27 | MVideoRedundancyVideo, | 20 | MVideoRedundancyVideo, |
28 | MVideoShare | 21 | MVideoShare |
29 | } from '../../../types/models' | 22 | } from '../../../types/models' |
23 | import { audiencify, getAudience } from '../audience' | ||
24 | import { getUndoActivityPubUrl, getVideoDislikeActivityPubUrlByLocalActor, getVideoLikeActivityPubUrlByLocalActor } from '../url' | ||
25 | import { buildAnnounceWithVideoAudience } from './send-announce' | ||
26 | import { buildCreateActivity } from './send-create' | ||
27 | import { buildDislikeActivity } from './send-dislike' | ||
28 | import { buildFollowActivity } from './send-follow' | ||
29 | import { buildLikeActivity } from './send-like' | ||
30 | import { broadcastToFollowers, sendVideoRelatedActivity, unicastTo } from './utils' | ||
30 | 31 | ||
31 | function sendUndoFollow (actorFollow: MActorFollowActors, t: Transaction) { | 32 | function sendUndoFollow (actorFollow: MActorFollowActors, t: Transaction) { |
32 | const me = actorFollow.ActorFollower | 33 | const me = actorFollow.ActorFollower |
@@ -37,10 +38,9 @@ function sendUndoFollow (actorFollow: MActorFollowActors, t: Transaction) { | |||
37 | 38 | ||
38 | logger.info('Creating job to send an unfollow request to %s.', following.url) | 39 | logger.info('Creating job to send an unfollow request to %s.', following.url) |
39 | 40 | ||
40 | const followUrl = getActorFollowActivityPubUrl(me, following) | 41 | const undoUrl = getUndoActivityPubUrl(actorFollow.url) |
41 | const undoUrl = getUndoActivityPubUrl(followUrl) | ||
42 | 42 | ||
43 | const followActivity = buildFollowActivity(followUrl, me, following) | 43 | const followActivity = buildFollowActivity(actorFollow.url, me, following) |
44 | const undoActivity = undoActivityData(undoUrl, me, followActivity) | 44 | const undoActivity = undoActivityData(undoUrl, me, followActivity) |
45 | 45 | ||
46 | t.afterCommit(() => unicastTo(undoActivity, me, following.inboxUrl)) | 46 | t.afterCommit(() => unicastTo(undoActivity, me, following.inboxUrl)) |
@@ -61,7 +61,7 @@ async function sendUndoAnnounce (byActor: MActorLight, videoShare: MVideoShare, | |||
61 | async function sendUndoLike (byActor: MActor, video: MVideoAccountLight, t: Transaction) { | 61 | async function sendUndoLike (byActor: MActor, video: MVideoAccountLight, t: Transaction) { |
62 | logger.info('Creating job to undo a like of video %s.', video.url) | 62 | logger.info('Creating job to undo a like of video %s.', video.url) |
63 | 63 | ||
64 | const likeUrl = getVideoLikeActivityPubUrl(byActor, video) | 64 | const likeUrl = getVideoLikeActivityPubUrlByLocalActor(byActor, video) |
65 | const likeActivity = buildLikeActivity(likeUrl, byActor, video) | 65 | const likeActivity = buildLikeActivity(likeUrl, byActor, video) |
66 | 66 | ||
67 | return sendUndoVideoRelatedActivity({ byActor, video, url: likeUrl, activity: likeActivity, transaction: t }) | 67 | return sendUndoVideoRelatedActivity({ byActor, video, url: likeUrl, activity: likeActivity, transaction: t }) |
@@ -70,7 +70,7 @@ async function sendUndoLike (byActor: MActor, video: MVideoAccountLight, t: Tran | |||
70 | async function sendUndoDislike (byActor: MActor, video: MVideoAccountLight, t: Transaction) { | 70 | async function sendUndoDislike (byActor: MActor, video: MVideoAccountLight, t: Transaction) { |
71 | logger.info('Creating job to undo a dislike of video %s.', video.url) | 71 | logger.info('Creating job to undo a dislike of video %s.', video.url) |
72 | 72 | ||
73 | const dislikeUrl = getVideoDislikeActivityPubUrl(byActor, video) | 73 | const dislikeUrl = getVideoDislikeActivityPubUrlByLocalActor(byActor, video) |
74 | const dislikeActivity = buildDislikeActivity(dislikeUrl, byActor, video) | 74 | const dislikeActivity = buildDislikeActivity(dislikeUrl, byActor, video) |
75 | 75 | ||
76 | return sendUndoVideoRelatedActivity({ byActor, video, url: dislikeUrl, activity: dislikeActivity, transaction: t }) | 76 | 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 @@ | |||
1 | import { Transaction } from 'sequelize' | 1 | import { Transaction } from 'sequelize' |
2 | import { MActorAudience, MVideoImmutable, MVideoUrl } from '@server/types/models' | ||
2 | import { ActivityAudience, ActivityView } from '../../../../shared/models/activitypub' | 3 | import { ActivityAudience, ActivityView } from '../../../../shared/models/activitypub' |
4 | import { logger } from '../../../helpers/logger' | ||
3 | import { ActorModel } from '../../../models/activitypub/actor' | 5 | import { ActorModel } from '../../../models/activitypub/actor' |
4 | import { getVideoLikeActivityPubUrl } from '../url' | ||
5 | import { sendVideoRelatedActivity } from './utils' | ||
6 | import { audiencify, getAudience } from '../audience' | 6 | import { audiencify, getAudience } from '../audience' |
7 | import { logger } from '../../../helpers/logger' | 7 | import { getLocalVideoViewActivityPubUrl } from '../url' |
8 | import { MActorAudience, MVideoImmutable, MVideoUrl } from '@server/types/models' | 8 | import { sendVideoRelatedActivity } from './utils' |
9 | 9 | ||
10 | async function sendView (byActor: ActorModel, video: MVideoImmutable, t: Transaction) { | 10 | async function sendView (byActor: ActorModel, video: MVideoImmutable, t: Transaction) { |
11 | logger.info('Creating job to send view of %s.', video.url) | 11 | logger.info('Creating job to send view of %s.', video.url) |
12 | 12 | ||
13 | const activityBuilder = (audience: ActivityAudience) => { | 13 | const activityBuilder = (audience: ActivityAudience) => { |
14 | const url = getVideoLikeActivityPubUrl(byActor, video) | 14 | const url = getLocalVideoViewActivityPubUrl(byActor, video) |
15 | 15 | ||
16 | return buildViewActivity(url, byActor, video, audience) | 16 | return buildViewActivity(url, byActor, video, audience) |
17 | } | 17 | } |
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 @@ | |||
1 | import { Transaction } from 'sequelize' | 1 | import { Transaction } from 'sequelize' |
2 | import { VideoShareModel } from '../../models/video/video-share' | 2 | import { VideoShareModel } from '../../models/video/video-share' |
3 | import { sendUndoAnnounce, sendVideoAnnounce } from './send' | 3 | import { sendUndoAnnounce, sendVideoAnnounce } from './send' |
4 | import { getVideoAnnounceActivityPubUrl } from './url' | 4 | import { getLocalVideoAnnounceActivityPubUrl } from './url' |
5 | import * as Bluebird from 'bluebird' | 5 | import * as Bluebird from 'bluebird' |
6 | import { doRequest } from '../../helpers/requests' | 6 | import { doRequest } from '../../helpers/requests' |
7 | import { getOrCreateActorAndServerAndModel } from './actor' | 7 | import { getOrCreateActorAndServerAndModel } from './actor' |
@@ -74,7 +74,7 @@ export { | |||
74 | async function shareByServer (video: MVideo, t: Transaction) { | 74 | async function shareByServer (video: MVideo, t: Transaction) { |
75 | const serverActor = await getServerActor() | 75 | const serverActor = await getServerActor() |
76 | 76 | ||
77 | const serverShareUrl = getVideoAnnounceActivityPubUrl(serverActor, video) | 77 | const serverShareUrl = getLocalVideoAnnounceActivityPubUrl(serverActor, video) |
78 | const [ serverShare ] = await VideoShareModel.findOrCreate({ | 78 | const [ serverShare ] = await VideoShareModel.findOrCreate({ |
79 | defaults: { | 79 | defaults: { |
80 | actorId: serverActor.id, | 80 | actorId: serverActor.id, |
@@ -91,7 +91,7 @@ async function shareByServer (video: MVideo, t: Transaction) { | |||
91 | } | 91 | } |
92 | 92 | ||
93 | async function shareByVideoChannel (video: MVideoAccountLight, t: Transaction) { | 93 | async function shareByVideoChannel (video: MVideoAccountLight, t: Transaction) { |
94 | const videoChannelShareUrl = getVideoAnnounceActivityPubUrl(video.VideoChannel.Actor, video) | 94 | const videoChannelShareUrl = getLocalVideoAnnounceActivityPubUrl(video.VideoChannel.Actor, video) |
95 | const [ videoChannelShare ] = await VideoShareModel.findOrCreate({ | 95 | const [ videoChannelShare ] = await VideoShareModel.findOrCreate({ |
96 | defaults: { | 96 | defaults: { |
97 | actorId: video.VideoChannel.actorId, | 97 | 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 @@ | |||
1 | import { WEBSERVER } from '../../initializers/constants' | 1 | import { WEBSERVER } from '../../initializers/constants' |
2 | import { | 2 | import { |
3 | MAbuseId, | ||
3 | MActor, | 4 | MActor, |
4 | MActorFollowActors, | 5 | MActorFollowActors, |
5 | MActorId, | 6 | MActorId, |
6 | MActorUrl, | 7 | MActorUrl, |
7 | MCommentId, | 8 | MCommentId, |
8 | MVideoId, | 9 | MVideoId, |
10 | MVideoPlaylistElement, | ||
9 | MVideoUrl, | 11 | MVideoUrl, |
10 | MVideoUUID, | 12 | MVideoUUID |
11 | MAbuseId, | ||
12 | MVideoPlaylistElement | ||
13 | } from '../../types/models' | 13 | } from '../../types/models' |
14 | import { MVideoPlaylist, MVideoPlaylistUUID } from '../../types/models/video/video-playlist' | ||
15 | import { MVideoFileVideoUUID } from '../../types/models/video/video-file' | 14 | import { MVideoFileVideoUUID } from '../../types/models/video/video-file' |
15 | import { MVideoPlaylist, MVideoPlaylistUUID } from '../../types/models/video/video-playlist' | ||
16 | import { MStreamingPlaylist } from '../../types/models/video/video-streaming-playlist' | 16 | import { MStreamingPlaylist } from '../../types/models/video/video-streaming-playlist' |
17 | 17 | ||
18 | function getVideoActivityPubUrl (video: MVideoUUID) { | 18 | function getLocalVideoActivityPubUrl (video: MVideoUUID) { |
19 | return WEBSERVER.URL + '/videos/watch/' + video.uuid | 19 | return WEBSERVER.URL + '/videos/watch/' + video.uuid |
20 | } | 20 | } |
21 | 21 | ||
22 | function getVideoPlaylistActivityPubUrl (videoPlaylist: MVideoPlaylist) { | 22 | function getLocalVideoPlaylistActivityPubUrl (videoPlaylist: MVideoPlaylist) { |
23 | return WEBSERVER.URL + '/video-playlists/' + videoPlaylist.uuid | 23 | return WEBSERVER.URL + '/video-playlists/' + videoPlaylist.uuid |
24 | } | 24 | } |
25 | 25 | ||
26 | function getVideoPlaylistElementActivityPubUrl (videoPlaylist: MVideoPlaylistUUID, videoPlaylistElement: MVideoPlaylistElement) { | 26 | function getLocalVideoPlaylistElementActivityPubUrl (videoPlaylist: MVideoPlaylistUUID, videoPlaylistElement: MVideoPlaylistElement) { |
27 | return WEBSERVER.URL + '/video-playlists/' + videoPlaylist.uuid + '/videos/' + videoPlaylistElement.id | 27 | return WEBSERVER.URL + '/video-playlists/' + videoPlaylist.uuid + '/videos/' + videoPlaylistElement.id |
28 | } | 28 | } |
29 | 29 | ||
30 | function getVideoCacheFileActivityPubUrl (videoFile: MVideoFileVideoUUID) { | 30 | function getLocalVideoCacheFileActivityPubUrl (videoFile: MVideoFileVideoUUID) { |
31 | const suffixFPS = videoFile.fps && videoFile.fps !== -1 ? '-' + videoFile.fps : '' | 31 | const suffixFPS = videoFile.fps && videoFile.fps !== -1 ? '-' + videoFile.fps : '' |
32 | 32 | ||
33 | return `${WEBSERVER.URL}/redundancy/videos/${videoFile.Video.uuid}/${videoFile.resolution}${suffixFPS}` | 33 | return `${WEBSERVER.URL}/redundancy/videos/${videoFile.Video.uuid}/${videoFile.resolution}${suffixFPS}` |
34 | } | 34 | } |
35 | 35 | ||
36 | function getVideoCacheStreamingPlaylistActivityPubUrl (video: MVideoUUID, playlist: MStreamingPlaylist) { | 36 | function getLocalVideoCacheStreamingPlaylistActivityPubUrl (video: MVideoUUID, playlist: MStreamingPlaylist) { |
37 | return `${WEBSERVER.URL}/redundancy/streaming-playlists/${playlist.getStringType()}/${video.uuid}` | 37 | return `${WEBSERVER.URL}/redundancy/streaming-playlists/${playlist.getStringType()}/${video.uuid}` |
38 | } | 38 | } |
39 | 39 | ||
40 | function getVideoCommentActivityPubUrl (video: MVideoUUID, videoComment: MCommentId) { | 40 | function getLocalVideoCommentActivityPubUrl (video: MVideoUUID, videoComment: MCommentId) { |
41 | return WEBSERVER.URL + '/videos/watch/' + video.uuid + '/comments/' + videoComment.id | 41 | return WEBSERVER.URL + '/videos/watch/' + video.uuid + '/comments/' + videoComment.id |
42 | } | 42 | } |
43 | 43 | ||
44 | function getVideoChannelActivityPubUrl (videoChannelName: string) { | 44 | function getLocalVideoChannelActivityPubUrl (videoChannelName: string) { |
45 | return WEBSERVER.URL + '/video-channels/' + videoChannelName | 45 | return WEBSERVER.URL + '/video-channels/' + videoChannelName |
46 | } | 46 | } |
47 | 47 | ||
48 | function getAccountActivityPubUrl (accountName: string) { | 48 | function getLocalAccountActivityPubUrl (accountName: string) { |
49 | return WEBSERVER.URL + '/accounts/' + accountName | 49 | return WEBSERVER.URL + '/accounts/' + accountName |
50 | } | 50 | } |
51 | 51 | ||
52 | function getAbuseActivityPubUrl (abuse: MAbuseId) { | 52 | function getLocalAbuseActivityPubUrl (abuse: MAbuseId) { |
53 | return WEBSERVER.URL + '/admin/abuses/' + abuse.id | 53 | return WEBSERVER.URL + '/admin/abuses/' + abuse.id |
54 | } | 54 | } |
55 | 55 | ||
56 | function getVideoViewActivityPubUrl (byActor: MActorUrl, video: MVideoId) { | 56 | function getLocalVideoViewActivityPubUrl (byActor: MActorUrl, video: MVideoId) { |
57 | return byActor.url + '/views/videos/' + video.id + '/' + new Date().toISOString() | 57 | return byActor.url + '/views/videos/' + video.id + '/' + new Date().toISOString() |
58 | } | 58 | } |
59 | 59 | ||
60 | function getVideoLikeActivityPubUrl (byActor: MActorUrl, video: MVideoId) { | 60 | function getVideoLikeActivityPubUrlByLocalActor (byActor: MActorUrl, video: MVideoId) { |
61 | return byActor.url + '/likes/' + video.id | 61 | return byActor.url + '/likes/' + video.id |
62 | } | 62 | } |
63 | 63 | ||
64 | function getVideoDislikeActivityPubUrl (byActor: MActorUrl, video: MVideoId) { | 64 | function getVideoDislikeActivityPubUrlByLocalActor (byActor: MActorUrl, video: MVideoId) { |
65 | return byActor.url + '/dislikes/' + video.id | 65 | return byActor.url + '/dislikes/' + video.id |
66 | } | 66 | } |
67 | 67 | ||
68 | function getVideoSharesActivityPubUrl (video: MVideoUrl) { | 68 | function getLocalVideoSharesActivityPubUrl (video: MVideoUrl) { |
69 | return video.url + '/announces' | 69 | return video.url + '/announces' |
70 | } | 70 | } |
71 | 71 | ||
72 | function getVideoCommentsActivityPubUrl (video: MVideoUrl) { | 72 | function getLocalVideoCommentsActivityPubUrl (video: MVideoUrl) { |
73 | return video.url + '/comments' | 73 | return video.url + '/comments' |
74 | } | 74 | } |
75 | 75 | ||
76 | function getVideoLikesActivityPubUrl (video: MVideoUrl) { | 76 | function getLocalVideoLikesActivityPubUrl (video: MVideoUrl) { |
77 | return video.url + '/likes' | 77 | return video.url + '/likes' |
78 | } | 78 | } |
79 | 79 | ||
80 | function getVideoDislikesActivityPubUrl (video: MVideoUrl) { | 80 | function getLocalVideoDislikesActivityPubUrl (video: MVideoUrl) { |
81 | return video.url + '/dislikes' | 81 | return video.url + '/dislikes' |
82 | } | 82 | } |
83 | 83 | ||
84 | function getActorFollowActivityPubUrl (follower: MActor, following: MActorId) { | 84 | function getLocalActorFollowActivityPubUrl (follower: MActor, following: MActorId) { |
85 | return follower.url + '/follows/' + following.id | 85 | return follower.url + '/follows/' + following.id |
86 | } | 86 | } |
87 | 87 | ||
88 | function getActorFollowAcceptActivityPubUrl (actorFollow: MActorFollowActors) { | 88 | function getLocalActorFollowAcceptActivityPubUrl (actorFollow: MActorFollowActors) { |
89 | const follower = actorFollow.ActorFollower | 89 | const follower = actorFollow.ActorFollower |
90 | const me = actorFollow.ActorFollowing | 90 | const me = actorFollow.ActorFollowing |
91 | 91 | ||
92 | return follower.url + '/accepts/follows/' + me.id | 92 | return WEBSERVER.URL + '/accepts/follows/' + follower.id + '/' + me.id |
93 | } | 93 | } |
94 | 94 | ||
95 | function getActorFollowRejectActivityPubUrl (follower: MActorUrl, following: MActorId) { | 95 | function getLocalActorFollowRejectActivityPubUrl (follower: MActorId, following: MActorId) { |
96 | return follower.url + '/rejects/follows/' + following.id | 96 | return WEBSERVER.URL + '/rejects/follows/' + follower.id + '/' + following.id |
97 | } | 97 | } |
98 | 98 | ||
99 | function getVideoAnnounceActivityPubUrl (byActor: MActorId, video: MVideoUrl) { | 99 | function getLocalVideoAnnounceActivityPubUrl (byActor: MActorId, video: MVideoUrl) { |
100 | return video.url + '/announces/' + byActor.id | 100 | return video.url + '/announces/' + byActor.id |
101 | } | 101 | } |
102 | 102 | ||
@@ -113,27 +113,28 @@ function getUndoActivityPubUrl (originalUrl: string) { | |||
113 | } | 113 | } |
114 | 114 | ||
115 | export { | 115 | export { |
116 | getVideoActivityPubUrl, | 116 | getLocalVideoActivityPubUrl, |
117 | getVideoPlaylistElementActivityPubUrl, | 117 | getLocalVideoPlaylistActivityPubUrl, |
118 | getVideoPlaylistActivityPubUrl, | 118 | getLocalVideoPlaylistElementActivityPubUrl, |
119 | getVideoCacheStreamingPlaylistActivityPubUrl, | 119 | getLocalVideoCacheFileActivityPubUrl, |
120 | getVideoChannelActivityPubUrl, | 120 | getLocalVideoCacheStreamingPlaylistActivityPubUrl, |
121 | getAccountActivityPubUrl, | 121 | getLocalVideoCommentActivityPubUrl, |
122 | getAbuseActivityPubUrl, | 122 | getLocalVideoChannelActivityPubUrl, |
123 | getActorFollowActivityPubUrl, | 123 | getLocalAccountActivityPubUrl, |
124 | getActorFollowAcceptActivityPubUrl, | 124 | getLocalAbuseActivityPubUrl, |
125 | getVideoAnnounceActivityPubUrl, | 125 | getLocalActorFollowActivityPubUrl, |
126 | getLocalActorFollowAcceptActivityPubUrl, | ||
127 | getLocalVideoAnnounceActivityPubUrl, | ||
126 | getUpdateActivityPubUrl, | 128 | getUpdateActivityPubUrl, |
127 | getUndoActivityPubUrl, | 129 | getUndoActivityPubUrl, |
128 | getVideoViewActivityPubUrl, | 130 | getVideoLikeActivityPubUrlByLocalActor, |
129 | getVideoLikeActivityPubUrl, | 131 | getLocalVideoViewActivityPubUrl, |
130 | getVideoDislikeActivityPubUrl, | 132 | getVideoDislikeActivityPubUrlByLocalActor, |
131 | getActorFollowRejectActivityPubUrl, | 133 | getLocalActorFollowRejectActivityPubUrl, |
132 | getVideoCommentActivityPubUrl, | ||
133 | getDeleteActivityPubUrl, | 134 | getDeleteActivityPubUrl, |
134 | getVideoSharesActivityPubUrl, | 135 | getLocalVideoSharesActivityPubUrl, |
135 | getVideoCommentsActivityPubUrl, | 136 | getLocalVideoCommentsActivityPubUrl, |
136 | getVideoLikesActivityPubUrl, | 137 | getLocalVideoLikesActivityPubUrl, |
137 | getVideoDislikesActivityPubUrl, | 138 | getLocalVideoDislikesActivityPubUrl, |
138 | getVideoCacheFileActivityPubUrl | 139 | |
139 | } | 140 | } |
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' | |||
8 | import { CRAWL_REQUEST_CONCURRENCY } from '../../initializers/constants' | 8 | import { CRAWL_REQUEST_CONCURRENCY } from '../../initializers/constants' |
9 | import { doRequest } from '../../helpers/requests' | 9 | import { doRequest } from '../../helpers/requests' |
10 | import { checkUrlsSameHost, getAPId } from '../../helpers/activitypub' | 10 | import { checkUrlsSameHost, getAPId } from '../../helpers/activitypub' |
11 | import { getVideoDislikeActivityPubUrl, getVideoLikeActivityPubUrl } from './url' | 11 | import { getVideoDislikeActivityPubUrlByLocalActor, getVideoLikeActivityPubUrlByLocalActor } from './url' |
12 | import { sendDislike } from './send/send-dislike' | 12 | import { sendDislike } from './send/send-dislike' |
13 | import { MAccountActor, MActorUrl, MVideo, MVideoAccountLight, MVideoId } from '../../types/models' | 13 | import { MAccountActor, MActorUrl, MVideo, MVideoAccountLight, MVideoId } from '../../types/models' |
14 | 14 | ||
@@ -82,14 +82,14 @@ async function sendVideoRateChange ( | |||
82 | if (dislikes > 0) await sendDislike(actor, video, t) | 82 | if (dislikes > 0) await sendDislike(actor, video, t) |
83 | } | 83 | } |
84 | 84 | ||
85 | function getRateUrl (rateType: VideoRateType, actor: MActorUrl, video: MVideoId) { | 85 | function getLocalRateUrl (rateType: VideoRateType, actor: MActorUrl, video: MVideoId) { |
86 | return rateType === 'like' | 86 | return rateType === 'like' |
87 | ? getVideoLikeActivityPubUrl(actor, video) | 87 | ? getVideoLikeActivityPubUrlByLocalActor(actor, video) |
88 | : getVideoDislikeActivityPubUrl(actor, video) | 88 | : getVideoDislikeActivityPubUrlByLocalActor(actor, video) |
89 | } | 89 | } |
90 | 90 | ||
91 | export { | 91 | export { |
92 | getRateUrl, | 92 | getLocalRateUrl, |
93 | createRates, | 93 | createRates, |
94 | sendVideoRateChange | 94 | sendVideoRateChange |
95 | } | 95 | } |
diff --git a/server/lib/job-queue/handlers/activitypub-follow.ts b/server/lib/job-queue/handlers/activitypub-follow.ts index 7a4f85f8b..82c95be80 100644 --- a/server/lib/job-queue/handlers/activitypub-follow.ts +++ b/server/lib/job-queue/handlers/activitypub-follow.ts | |||
@@ -12,6 +12,7 @@ import { Notifier } from '../../notifier' | |||
12 | import { sequelizeTypescript } from '../../../initializers/database' | 12 | import { sequelizeTypescript } from '../../../initializers/database' |
13 | import { MActor, MActorFollowActors, MActorFull } from '../../../types/models' | 13 | import { MActor, MActorFollowActors, MActorFull } from '../../../types/models' |
14 | import { ActivitypubFollowPayload } from '@shared/models' | 14 | import { ActivitypubFollowPayload } from '@shared/models' |
15 | import { getLocalActorFollowActivityPubUrl } from '@server/lib/activitypub/url' | ||
15 | 16 | ||
16 | async function processActivityPubFollow (job: Bull.Job) { | 17 | async function processActivityPubFollow (job: Bull.Job) { |
17 | const payload = job.data as ActivitypubFollowPayload | 18 | const payload = job.data as ActivitypubFollowPayload |
@@ -61,6 +62,7 @@ async function follow (fromActor: MActor, targetActor: MActorFull, isAutoFollow | |||
61 | }, | 62 | }, |
62 | defaults: { | 63 | defaults: { |
63 | state, | 64 | state, |
65 | url: getLocalActorFollowActivityPubUrl(fromActor, targetActor), | ||
64 | actorId: fromActor.id, | 66 | actorId: fromActor.id, |
65 | targetActorId: targetActor.id | 67 | targetActorId: targetActor.id |
66 | }, | 68 | }, |
diff --git a/server/lib/schedulers/videos-redundancy-scheduler.ts b/server/lib/schedulers/videos-redundancy-scheduler.ts index 54d9a9894..82005a2c8 100644 --- a/server/lib/schedulers/videos-redundancy-scheduler.ts +++ b/server/lib/schedulers/videos-redundancy-scheduler.ts | |||
@@ -1,19 +1,10 @@ | |||
1 | import { AbstractScheduler } from './abstract-scheduler' | ||
2 | import { HLS_REDUNDANCY_DIRECTORY, REDUNDANCY, VIDEO_IMPORT_TIMEOUT, WEBSERVER } from '../../initializers/constants' | ||
3 | import { logger } from '../../helpers/logger' | ||
4 | import { VideosRedundancyStrategy } from '../../../shared/models/redundancy' | ||
5 | import { VideoRedundancyModel } from '../../models/redundancy/video-redundancy' | ||
6 | import { downloadWebTorrentVideo, generateMagnetUri } from '../../helpers/webtorrent' | ||
7 | import { join } from 'path' | ||
8 | import { move } from 'fs-extra' | 1 | import { move } from 'fs-extra' |
9 | import { sendCreateCacheFile, sendUpdateCacheFile } from '../activitypub/send' | 2 | import { join } from 'path' |
10 | import { getVideoCacheFileActivityPubUrl, getVideoCacheStreamingPlaylistActivityPubUrl } from '../activitypub/url' | 3 | import { getServerActor } from '@server/models/application/application' |
11 | import { removeVideoRedundancy } from '../redundancy' | 4 | import { VideoModel } from '@server/models/video/video' |
12 | import { getOrCreateVideoAndAccountAndChannel } from '../activitypub/videos' | ||
13 | import { downloadPlaylistSegments } from '../hls' | ||
14 | import { CONFIG } from '../../initializers/config' | ||
15 | import { | 5 | import { |
16 | MStreamingPlaylist, MStreamingPlaylistFiles, | 6 | MStreamingPlaylist, |
7 | MStreamingPlaylistFiles, | ||
17 | MStreamingPlaylistVideo, | 8 | MStreamingPlaylistVideo, |
18 | MVideoAccountLight, | 9 | MVideoAccountLight, |
19 | MVideoFile, | 10 | MVideoFile, |
@@ -23,9 +14,19 @@ import { | |||
23 | MVideoRedundancyVideo, | 14 | MVideoRedundancyVideo, |
24 | MVideoWithAllFiles | 15 | MVideoWithAllFiles |
25 | } from '@server/types/models' | 16 | } from '@server/types/models' |
17 | import { VideosRedundancyStrategy } from '../../../shared/models/redundancy' | ||
18 | import { logger } from '../../helpers/logger' | ||
19 | import { downloadWebTorrentVideo, generateMagnetUri } from '../../helpers/webtorrent' | ||
20 | import { CONFIG } from '../../initializers/config' | ||
21 | import { HLS_REDUNDANCY_DIRECTORY, REDUNDANCY, VIDEO_IMPORT_TIMEOUT, WEBSERVER } from '../../initializers/constants' | ||
22 | import { VideoRedundancyModel } from '../../models/redundancy/video-redundancy' | ||
23 | import { sendCreateCacheFile, sendUpdateCacheFile } from '../activitypub/send' | ||
24 | import { getLocalVideoCacheFileActivityPubUrl, getLocalVideoCacheStreamingPlaylistActivityPubUrl } from '../activitypub/url' | ||
25 | import { getOrCreateVideoAndAccountAndChannel } from '../activitypub/videos' | ||
26 | import { downloadPlaylistSegments } from '../hls' | ||
27 | import { removeVideoRedundancy } from '../redundancy' | ||
26 | import { getVideoFilename } from '../video-paths' | 28 | import { getVideoFilename } from '../video-paths' |
27 | import { VideoModel } from '@server/models/video/video' | 29 | import { AbstractScheduler } from './abstract-scheduler' |
28 | import { getServerActor } from '@server/models/application/application' | ||
29 | 30 | ||
30 | type CandidateToDuplicate = { | 31 | type CandidateToDuplicate = { |
31 | redundancy: VideosRedundancyStrategy | 32 | redundancy: VideosRedundancyStrategy |
@@ -230,7 +231,7 @@ export class VideosRedundancyScheduler extends AbstractScheduler { | |||
230 | 231 | ||
231 | const createdModel: MVideoRedundancyFileVideo = await VideoRedundancyModel.create({ | 232 | const createdModel: MVideoRedundancyFileVideo = await VideoRedundancyModel.create({ |
232 | expiresOn, | 233 | expiresOn, |
233 | url: getVideoCacheFileActivityPubUrl(file), | 234 | url: getLocalVideoCacheFileActivityPubUrl(file), |
234 | fileUrl: video.getVideoRedundancyUrl(file, WEBSERVER.URL), | 235 | fileUrl: video.getVideoRedundancyUrl(file, WEBSERVER.URL), |
235 | strategy, | 236 | strategy, |
236 | videoFileId: file.id, | 237 | videoFileId: file.id, |
@@ -269,7 +270,7 @@ export class VideosRedundancyScheduler extends AbstractScheduler { | |||
269 | 270 | ||
270 | const createdModel: MVideoRedundancyStreamingPlaylistVideo = await VideoRedundancyModel.create({ | 271 | const createdModel: MVideoRedundancyStreamingPlaylistVideo = await VideoRedundancyModel.create({ |
271 | expiresOn, | 272 | expiresOn, |
272 | url: getVideoCacheStreamingPlaylistActivityPubUrl(video, playlist), | 273 | url: getLocalVideoCacheStreamingPlaylistActivityPubUrl(video, playlist), |
273 | fileUrl: playlist.getVideoRedundancyUrl(WEBSERVER.URL), | 274 | fileUrl: playlist.getVideoRedundancyUrl(WEBSERVER.URL), |
274 | strategy, | 275 | strategy, |
275 | videoStreamingPlaylistId: playlist.id, | 276 | videoStreamingPlaylistId: playlist.id, |
diff --git a/server/lib/user.ts b/server/lib/user.ts index 7d6497302..6b0fd9b88 100644 --- a/server/lib/user.ts +++ b/server/lib/user.ts | |||
@@ -11,7 +11,7 @@ import { ActorModel } from '../models/activitypub/actor' | |||
11 | import { MAccountDefault, MActorDefault, MChannelActor } from '../types/models' | 11 | import { MAccountDefault, MActorDefault, MChannelActor } from '../types/models' |
12 | import { MUser, MUserDefault, MUserId } from '../types/models/user' | 12 | import { MUser, MUserDefault, MUserId } from '../types/models/user' |
13 | import { buildActorInstance, setAsyncActorKeys } from './activitypub/actor' | 13 | import { buildActorInstance, setAsyncActorKeys } from './activitypub/actor' |
14 | import { getAccountActivityPubUrl } from './activitypub/url' | 14 | import { getLocalAccountActivityPubUrl } from './activitypub/url' |
15 | import { Emailer } from './emailer' | 15 | import { Emailer } from './emailer' |
16 | import { LiveManager } from './live-manager' | 16 | import { LiveManager } from './live-manager' |
17 | import { Redis } from './redis' | 17 | import { Redis } from './redis' |
@@ -74,7 +74,7 @@ async function createLocalAccountWithoutKeys (parameters: { | |||
74 | type?: ActivityPubActorType | 74 | type?: ActivityPubActorType |
75 | }) { | 75 | }) { |
76 | const { name, displayName, userId, applicationId, t, type = 'Person' } = parameters | 76 | const { name, displayName, userId, applicationId, t, type = 'Person' } = parameters |
77 | const url = getAccountActivityPubUrl(name) | 77 | const url = getLocalAccountActivityPubUrl(name) |
78 | 78 | ||
79 | const actorInstance = buildActorInstance(type, url, name) | 79 | const actorInstance = buildActorInstance(type, url, name) |
80 | const actorInstanceCreated: MActorDefault = await actorInstance.save({ transaction: t }) | 80 | const actorInstanceCreated: MActorDefault = await actorInstance.save({ transaction: t }) |
diff --git a/server/lib/video-channel.ts b/server/lib/video-channel.ts index 8928dda12..49bdf4869 100644 --- a/server/lib/video-channel.ts +++ b/server/lib/video-channel.ts | |||
@@ -1,11 +1,11 @@ | |||
1 | import * as Sequelize from 'sequelize' | 1 | import * as Sequelize from 'sequelize' |
2 | import { v4 as uuidv4 } from 'uuid' | 2 | import { v4 as uuidv4 } from 'uuid' |
3 | import { VideoChannelCreate } from '../../shared/models' | 3 | import { VideoChannelCreate } from '../../shared/models' |
4 | import { VideoChannelModel } from '../models/video/video-channel' | ||
5 | import { buildActorInstance } from './activitypub/actor' | ||
6 | import { VideoModel } from '../models/video/video' | 4 | import { VideoModel } from '../models/video/video' |
5 | import { VideoChannelModel } from '../models/video/video-channel' | ||
7 | import { MAccountId, MChannelDefault, MChannelId } from '../types/models' | 6 | import { MAccountId, MChannelDefault, MChannelId } from '../types/models' |
8 | import { getVideoChannelActivityPubUrl } from './activitypub/url' | 7 | import { buildActorInstance } from './activitypub/actor' |
8 | import { getLocalVideoChannelActivityPubUrl } from './activitypub/url' | ||
9 | import { federateVideoIfNeeded } from './activitypub/videos' | 9 | import { federateVideoIfNeeded } from './activitypub/videos' |
10 | 10 | ||
11 | type CustomVideoChannelModelAccount <T extends MAccountId> = MChannelDefault & { Account?: T } | 11 | type CustomVideoChannelModelAccount <T extends MAccountId> = MChannelDefault & { Account?: T } |
@@ -16,7 +16,7 @@ async function createLocalVideoChannel <T extends MAccountId> ( | |||
16 | t: Sequelize.Transaction | 16 | t: Sequelize.Transaction |
17 | ): Promise<CustomVideoChannelModelAccount<T>> { | 17 | ): Promise<CustomVideoChannelModelAccount<T>> { |
18 | const uuid = uuidv4() | 18 | const uuid = uuidv4() |
19 | const url = getVideoChannelActivityPubUrl(videoChannelInfo.name) | 19 | const url = getLocalVideoChannelActivityPubUrl(videoChannelInfo.name) |
20 | const actorInstance = buildActorInstance('Group', url, videoChannelInfo.name, uuid) | 20 | const actorInstance = buildActorInstance('Group', url, videoChannelInfo.name, uuid) |
21 | 21 | ||
22 | const actorInstanceCreated = await actorInstance.save({ transaction: t }) | 22 | const actorInstanceCreated = await actorInstance.save({ transaction: t }) |
diff --git a/server/lib/video-comment.ts b/server/lib/video-comment.ts index c92a7c43a..736ebb2f8 100644 --- a/server/lib/video-comment.ts +++ b/server/lib/video-comment.ts | |||
@@ -5,9 +5,9 @@ import { sequelizeTypescript } from '@server/initializers/database' | |||
5 | import { ResultList } from '../../shared/models' | 5 | import { ResultList } from '../../shared/models' |
6 | import { VideoCommentThreadTree } from '../../shared/models/videos/video-comment.model' | 6 | import { VideoCommentThreadTree } from '../../shared/models/videos/video-comment.model' |
7 | import { VideoCommentModel } from '../models/video/video-comment' | 7 | import { VideoCommentModel } from '../models/video/video-comment' |
8 | import { MAccountDefault, MComment, MCommentOwnerVideoReply, MVideoFullLight, MCommentOwnerVideo } from '../types/models' | 8 | import { MAccountDefault, MComment, MCommentOwnerVideo, MCommentOwnerVideoReply, MVideoFullLight } from '../types/models' |
9 | import { sendCreateVideoComment, sendDeleteVideoComment } from './activitypub/send' | 9 | import { sendCreateVideoComment, sendDeleteVideoComment } from './activitypub/send' |
10 | import { getVideoCommentActivityPubUrl } from './activitypub/url' | 10 | import { getLocalVideoCommentActivityPubUrl } from './activitypub/url' |
11 | import { Hooks } from './plugins/hooks' | 11 | import { Hooks } from './plugins/hooks' |
12 | 12 | ||
13 | async function removeComment (videoCommentInstance: MCommentOwnerVideo) { | 13 | async function removeComment (videoCommentInstance: MCommentOwnerVideo) { |
@@ -51,7 +51,7 @@ async function createVideoComment (obj: { | |||
51 | url: new Date().toISOString() | 51 | url: new Date().toISOString() |
52 | }, { transaction: t, validate: false }) | 52 | }, { transaction: t, validate: false }) |
53 | 53 | ||
54 | comment.url = getVideoCommentActivityPubUrl(obj.video, comment) | 54 | comment.url = getLocalVideoCommentActivityPubUrl(obj.video, comment) |
55 | 55 | ||
56 | const savedComment: MCommentOwnerVideoReply = await comment.save({ transaction: t }) | 56 | const savedComment: MCommentOwnerVideoReply = await comment.save({ transaction: t }) |
57 | savedComment.InReplyToVideoComment = obj.inReplyToComment | 57 | savedComment.InReplyToVideoComment = obj.inReplyToComment |
diff --git a/server/lib/video-playlist.ts b/server/lib/video-playlist.ts index 6eeb70c8e..a1af2e1af 100644 --- a/server/lib/video-playlist.ts +++ b/server/lib/video-playlist.ts | |||
@@ -1,10 +1,10 @@ | |||
1 | import * as Sequelize from 'sequelize' | 1 | import * as Sequelize from 'sequelize' |
2 | import { VideoPlaylistModel } from '../models/video/video-playlist' | ||
3 | import { VideoPlaylistPrivacy } from '../../shared/models/videos/playlist/video-playlist-privacy.model' | 2 | import { VideoPlaylistPrivacy } from '../../shared/models/videos/playlist/video-playlist-privacy.model' |
4 | import { getVideoPlaylistActivityPubUrl } from './activitypub/url' | ||
5 | import { VideoPlaylistType } from '../../shared/models/videos/playlist/video-playlist-type.model' | 3 | import { VideoPlaylistType } from '../../shared/models/videos/playlist/video-playlist-type.model' |
4 | import { VideoPlaylistModel } from '../models/video/video-playlist' | ||
6 | import { MAccount } from '../types/models' | 5 | import { MAccount } from '../types/models' |
7 | import { MVideoPlaylistOwner } from '../types/models/video/video-playlist' | 6 | import { MVideoPlaylistOwner } from '../types/models/video/video-playlist' |
7 | import { getLocalVideoPlaylistActivityPubUrl } from './activitypub/url' | ||
8 | 8 | ||
9 | async function createWatchLaterPlaylist (account: MAccount, t: Sequelize.Transaction) { | 9 | async function createWatchLaterPlaylist (account: MAccount, t: Sequelize.Transaction) { |
10 | const videoPlaylist: MVideoPlaylistOwner = new VideoPlaylistModel({ | 10 | const videoPlaylist: MVideoPlaylistOwner = new VideoPlaylistModel({ |
@@ -14,7 +14,7 @@ async function createWatchLaterPlaylist (account: MAccount, t: Sequelize.Transac | |||
14 | ownerAccountId: account.id | 14 | ownerAccountId: account.id |
15 | }) | 15 | }) |
16 | 16 | ||
17 | videoPlaylist.url = getVideoPlaylistActivityPubUrl(videoPlaylist) // We use the UUID, so set the URL after building the object | 17 | videoPlaylist.url = getLocalVideoPlaylistActivityPubUrl(videoPlaylist) // We use the UUID, so set the URL after building the object |
18 | 18 | ||
19 | await videoPlaylist.save({ transaction: t }) | 19 | await videoPlaylist.save({ transaction: t }) |
20 | 20 | ||