diff options
Diffstat (limited to 'server/lib')
-rw-r--r-- | server/lib/activitypub/process-create.ts | 43 | ||||
-rw-r--r-- | server/lib/activitypub/send-request.ts | 25 |
2 files changed, 57 insertions, 11 deletions
diff --git a/server/lib/activitypub/process-create.ts b/server/lib/activitypub/process-create.ts index 471674ead..8d842b822 100644 --- a/server/lib/activitypub/process-create.ts +++ b/server/lib/activitypub/process-create.ts | |||
@@ -1,11 +1,9 @@ | |||
1 | import { ActivityCreate, VideoChannelObject, VideoTorrentObject } from '../../../shared' | 1 | import { ActivityCreate, VideoChannelObject } from '../../../shared' |
2 | import { ActivityAdd } from '../../../shared/models/activitypub/activity' | 2 | import { VideoAbuseObject } from '../../../shared/models/activitypub/objects/video-abuse-object' |
3 | import { generateThumbnailFromUrl, logger, retryTransactionWrapper } from '../../helpers' | 3 | import { logger, retryTransactionWrapper } from '../../helpers' |
4 | import { getActivityPubUrl, getOrCreateAccount } from '../../helpers/activitypub' | ||
4 | import { database as db } from '../../initializers' | 5 | import { database as db } from '../../initializers' |
5 | import { videoActivityObjectToDBAttributes, videoFileActivityUrlToDBAttributes } from './misc' | ||
6 | import Bluebird = require('bluebird') | ||
7 | import { AccountInstance } from '../../models/account/account-interface' | 6 | import { AccountInstance } from '../../models/account/account-interface' |
8 | import { getActivityPubUrl, getOrCreateAccount } from '../../helpers/activitypub' | ||
9 | 7 | ||
10 | async function processCreateActivity (activity: ActivityCreate) { | 8 | async function processCreateActivity (activity: ActivityCreate) { |
11 | const activityObject = activity.object | 9 | const activityObject = activity.object |
@@ -14,6 +12,8 @@ async function processCreateActivity (activity: ActivityCreate) { | |||
14 | 12 | ||
15 | if (activityType === 'VideoChannel') { | 13 | if (activityType === 'VideoChannel') { |
16 | return processCreateVideoChannel(account, activityObject as VideoChannelObject) | 14 | return processCreateVideoChannel(account, activityObject as VideoChannelObject) |
15 | } else if (activityType === 'Flag') { | ||
16 | return processCreateVideoAbuse(account, activityObject as VideoAbuseObject) | ||
17 | } | 17 | } |
18 | 18 | ||
19 | logger.warn('Unknown activity object type %s when creating activity.', activityType, { activity: activity.id }) | 19 | logger.warn('Unknown activity object type %s when creating activity.', activityType, { activity: activity.id }) |
@@ -62,3 +62,34 @@ async function addRemoteVideoChannel (account: AccountInstance, videoChannelToCr | |||
62 | 62 | ||
63 | logger.info('Remote video channel with uuid %s inserted.', videoChannelToCreateData.uuid) | 63 | logger.info('Remote video channel with uuid %s inserted.', videoChannelToCreateData.uuid) |
64 | } | 64 | } |
65 | |||
66 | function processCreateVideoAbuse (account: AccountInstance, videoAbuseToCreateData: VideoAbuseObject) { | ||
67 | const options = { | ||
68 | arguments: [ account, videoAbuseToCreateData ], | ||
69 | errorMessage: 'Cannot insert the remote video abuse with many retries.' | ||
70 | } | ||
71 | |||
72 | return retryTransactionWrapper(addRemoteVideoAbuse, options) | ||
73 | } | ||
74 | |||
75 | async function addRemoteVideoAbuse (account: AccountInstance, videoAbuseToCreateData: VideoAbuseObject) { | ||
76 | logger.debug('Reporting remote abuse for video %s.', videoAbuseToCreateData.object) | ||
77 | |||
78 | return db.sequelize.transaction(async t => { | ||
79 | const video = await db.Video.loadByUrl(videoAbuseToCreateData.object, t) | ||
80 | if (!video) { | ||
81 | logger.warn('Unknown video %s for remote video abuse.', videoAbuseToCreateData.object) | ||
82 | return | ||
83 | } | ||
84 | |||
85 | const videoAbuseData = { | ||
86 | reporterAccountId: account.id, | ||
87 | reason: videoAbuseToCreateData.content, | ||
88 | videoId: video.id | ||
89 | } | ||
90 | |||
91 | await db.VideoAbuse.create(videoAbuseData) | ||
92 | |||
93 | logger.info('Remote abuse for video uuid %s created', videoAbuseToCreateData.object) | ||
94 | }) | ||
95 | } | ||
diff --git a/server/lib/activitypub/send-request.ts b/server/lib/activitypub/send-request.ts index f942a2eba..1a6cebc03 100644 --- a/server/lib/activitypub/send-request.ts +++ b/server/lib/activitypub/send-request.ts | |||
@@ -9,6 +9,8 @@ import { | |||
9 | import { httpRequestJobScheduler } from '../jobs' | 9 | import { httpRequestJobScheduler } from '../jobs' |
10 | import { signObject, activityPubContextify } from '../../helpers' | 10 | import { signObject, activityPubContextify } from '../../helpers' |
11 | import { Activity } from '../../../shared' | 11 | import { Activity } from '../../../shared' |
12 | import { VideoAbuseInstance } from '../../models/video/video-abuse-interface' | ||
13 | import { getActivityPubUrl } from '../../helpers/activitypub' | ||
12 | 14 | ||
13 | async function sendCreateVideoChannel (videoChannel: VideoChannelInstance, t: Sequelize.Transaction) { | 15 | async function sendCreateVideoChannel (videoChannel: VideoChannelInstance, t: Sequelize.Transaction) { |
14 | const videoChannelObject = videoChannel.toActivityPubObject() | 16 | const videoChannelObject = videoChannel.toActivityPubObject() |
@@ -56,16 +58,28 @@ async function sendDeleteAccount (account: AccountInstance, t: Sequelize.Transac | |||
56 | return broadcastToFollowers(data, account, t) | 58 | return broadcastToFollowers(data, account, t) |
57 | } | 59 | } |
58 | 60 | ||
61 | async function sendVideoAbuse ( | ||
62 | fromAccount: AccountInstance, | ||
63 | videoAbuse: VideoAbuseInstance, | ||
64 | video: VideoInstance, | ||
65 | t: Sequelize.Transaction | ||
66 | ) { | ||
67 | const url = getActivityPubUrl('videoAbuse', videoAbuse.id.toString()) | ||
68 | const data = await createActivityData(url, fromAccount, video.url) | ||
69 | |||
70 | return unicastTo(data, video.VideoChannel.Account.sharedInboxUrl, t) | ||
71 | } | ||
72 | |||
59 | async function sendAccept (fromAccount: AccountInstance, toAccount: AccountInstance, t: Sequelize.Transaction) { | 73 | async function sendAccept (fromAccount: AccountInstance, toAccount: AccountInstance, t: Sequelize.Transaction) { |
60 | const data = await acceptActivityData(fromAccount) | 74 | const data = await acceptActivityData(fromAccount) |
61 | 75 | ||
62 | return unicastTo(data, toAccount, t) | 76 | return unicastTo(data, toAccount.inboxUrl, t) |
63 | } | 77 | } |
64 | 78 | ||
65 | async function sendFollow (fromAccount: AccountInstance, toAccount: AccountInstance, t: Sequelize.Transaction) { | 79 | async function sendFollow (fromAccount: AccountInstance, toAccount: AccountInstance, t: Sequelize.Transaction) { |
66 | const data = await followActivityData(toAccount.url, fromAccount) | 80 | const data = await followActivityData(toAccount.url, fromAccount) |
67 | 81 | ||
68 | return unicastTo(data, toAccount, t) | 82 | return unicastTo(data, toAccount.inboxUrl, t) |
69 | } | 83 | } |
70 | 84 | ||
71 | // --------------------------------------------------------------------------- | 85 | // --------------------------------------------------------------------------- |
@@ -79,7 +93,8 @@ export { | |||
79 | sendDeleteVideo, | 93 | sendDeleteVideo, |
80 | sendDeleteAccount, | 94 | sendDeleteAccount, |
81 | sendAccept, | 95 | sendAccept, |
82 | sendFollow | 96 | sendFollow, |
97 | sendVideoAbuse | ||
83 | } | 98 | } |
84 | 99 | ||
85 | // --------------------------------------------------------------------------- | 100 | // --------------------------------------------------------------------------- |
@@ -95,9 +110,9 @@ async function broadcastToFollowers (data: any, fromAccount: AccountInstance, t: | |||
95 | return httpRequestJobScheduler.createJob(t, 'httpRequestBroadcastHandler', jobPayload) | 110 | return httpRequestJobScheduler.createJob(t, 'httpRequestBroadcastHandler', jobPayload) |
96 | } | 111 | } |
97 | 112 | ||
98 | async function unicastTo (data: any, toAccount: AccountInstance, t: Sequelize.Transaction) { | 113 | async function unicastTo (data: any, toAccountUrl: string, t: Sequelize.Transaction) { |
99 | const jobPayload = { | 114 | const jobPayload = { |
100 | uris: [ toAccount.inboxUrl ], | 115 | uris: [ toAccountUrl ], |
101 | body: data | 116 | body: data |
102 | } | 117 | } |
103 | 118 | ||