]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/activitypub/send/send-flag.ts
Cleaner warning of IP address leaking on embedded videos (#2034)
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / send / send-flag.ts
CommitLineData
1e7eb25f
C
1import { ActorModel } from '../../../models/activitypub/actor'
2import { VideoModel } from '../../../models/video/video'
3import { VideoAbuseModel } from '../../../models/video/video-abuse'
4import { getVideoAbuseActivityPubUrl } from '../url'
5import { unicastTo } from './utils'
6import { logger } from '../../../helpers/logger'
7import { ActivityAudience, ActivityFlag } from '../../../../shared/models/activitypub'
8import { audiencify, getAudience } from '../audience'
2284f202 9import { Transaction } from 'sequelize'
1e7eb25f 10
2284f202 11async function sendVideoAbuse (byActor: ActorModel, videoAbuse: VideoAbuseModel, video: VideoModel, t: Transaction) {
1e7eb25f
C
12 if (!video.VideoChannel.Account.Actor.serverId) return // Local user
13
14 const url = getVideoAbuseActivityPubUrl(videoAbuse)
15
16 logger.info('Creating job to send video abuse %s.', url)
17
18 // Custom audience, we only send the abuse to the origin instance
19 const audience = { to: [ video.VideoChannel.Account.Actor.url ], cc: [] }
20 const flagActivity = buildFlagActivity(url, byActor, videoAbuse, audience)
21
2284f202 22 t.afterCommit(() => unicastTo(flagActivity, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl))
1e7eb25f
C
23}
24
25function buildFlagActivity (url: string, byActor: ActorModel, videoAbuse: VideoAbuseModel, audience: ActivityAudience): ActivityFlag {
26 if (!audience) audience = getAudience(byActor)
27
28 const activity = Object.assign(
29 { id: url, actor: byActor.url },
30 videoAbuse.toActivityPubObject()
31 )
32
33 return audiencify(activity, audience)
34}
35
36// ---------------------------------------------------------------------------
37
38export {
39 sendVideoAbuse
40}