aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/process-create.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-11-15 15:12:23 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-11-27 19:40:52 +0100
commit8e13fa7d09e9925b4559cbba6c5d72c5ff1bd391 (patch)
treea59070f4dc6b52a5b422bd31a8eb8ea3bff831a0 /server/lib/activitypub/process-create.ts
parent59c857da5961e2bcddcfd07832783c1e4afcd01a (diff)
downloadPeerTube-8e13fa7d09e9925b4559cbba6c5d72c5ff1bd391.tar.gz
PeerTube-8e13fa7d09e9925b4559cbba6c5d72c5ff1bd391.tar.zst
PeerTube-8e13fa7d09e9925b4559cbba6c5d72c5ff1bd391.zip
Add video abuse to activity pub
Diffstat (limited to 'server/lib/activitypub/process-create.ts')
-rw-r--r--server/lib/activitypub/process-create.ts43
1 files changed, 37 insertions, 6 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 @@
1import { ActivityCreate, VideoChannelObject, VideoTorrentObject } from '../../../shared' 1import { ActivityCreate, VideoChannelObject } from '../../../shared'
2import { ActivityAdd } from '../../../shared/models/activitypub/activity' 2import { VideoAbuseObject } from '../../../shared/models/activitypub/objects/video-abuse-object'
3import { generateThumbnailFromUrl, logger, retryTransactionWrapper } from '../../helpers' 3import { logger, retryTransactionWrapper } from '../../helpers'
4import { getActivityPubUrl, getOrCreateAccount } from '../../helpers/activitypub'
4import { database as db } from '../../initializers' 5import { database as db } from '../../initializers'
5import { videoActivityObjectToDBAttributes, videoFileActivityUrlToDBAttributes } from './misc'
6import Bluebird = require('bluebird')
7import { AccountInstance } from '../../models/account/account-interface' 6import { AccountInstance } from '../../models/account/account-interface'
8import { getActivityPubUrl, getOrCreateAccount } from '../../helpers/activitypub'
9 7
10async function processCreateActivity (activity: ActivityCreate) { 8async 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
66function 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
75async 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}