diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-11-16 17:04:19 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-11-27 19:40:52 +0100 |
commit | 21e0727a84734cb0c81c1c9bb22a49b13e46fe5f (patch) | |
tree | 088da51cadbffe3ac64414b407e161f58b53bde7 /server | |
parent | d7d5611c8a23de9b483f0437ad3469afef7b8805 (diff) | |
download | PeerTube-21e0727a84734cb0c81c1c9bb22a49b13e46fe5f.tar.gz PeerTube-21e0727a84734cb0c81c1c9bb22a49b13e46fe5f.tar.zst PeerTube-21e0727a84734cb0c81c1c9bb22a49b13e46fe5f.zip |
Federate video abuses
Diffstat (limited to 'server')
-rw-r--r-- | server/controllers/api/videos/abuse.ts | 1 | ||||
-rw-r--r-- | server/helpers/custom-validators/activitypub/videos.ts | 7 | ||||
-rw-r--r-- | server/lib/activitypub/misc.ts | 6 | ||||
-rw-r--r-- | server/lib/activitypub/send-request.ts | 4 | ||||
-rw-r--r-- | server/models/video/video-abuse-interface.ts | 3 | ||||
-rw-r--r-- | server/models/video/video-abuse.ts | 15 | ||||
-rw-r--r-- | server/models/video/video.ts | 4 |
7 files changed, 28 insertions, 12 deletions
diff --git a/server/controllers/api/videos/abuse.ts b/server/controllers/api/videos/abuse.ts index d9b4e8772..88b3d538d 100644 --- a/server/controllers/api/videos/abuse.ts +++ b/server/controllers/api/videos/abuse.ts | |||
@@ -75,6 +75,7 @@ async function reportVideoAbuse (req: express.Request, res: express.Response) { | |||
75 | 75 | ||
76 | await db.sequelize.transaction(async t => { | 76 | await db.sequelize.transaction(async t => { |
77 | const videoAbuseInstance = await db.VideoAbuse.create(abuseToCreate, { transaction: t }) | 77 | const videoAbuseInstance = await db.VideoAbuse.create(abuseToCreate, { transaction: t }) |
78 | videoAbuseInstance.Video = videoInstance | ||
78 | 79 | ||
79 | // We send the video abuse to the origin server | 80 | // We send the video abuse to the origin server |
80 | if (videoInstance.isOwned() === false) { | 81 | if (videoInstance.isOwned() === false) { |
diff --git a/server/helpers/custom-validators/activitypub/videos.ts b/server/helpers/custom-validators/activitypub/videos.ts index 8486297ad..728511e3d 100644 --- a/server/helpers/custom-validators/activitypub/videos.ts +++ b/server/helpers/custom-validators/activitypub/videos.ts | |||
@@ -58,9 +58,10 @@ function isVideoTorrentObjectValid (video: any) { | |||
58 | } | 58 | } |
59 | 59 | ||
60 | function isVideoFlagValid (activity: any) { | 60 | function isVideoFlagValid (activity: any) { |
61 | return isBaseActivityValid(activity, 'Flag') && | 61 | return isBaseActivityValid(activity, 'Create') && |
62 | isVideoAbuseReasonValid(activity.content) && | 62 | activity.object.type === 'Flag' && |
63 | isActivityPubUrlValid(activity.object) | 63 | isVideoAbuseReasonValid(activity.object.content) && |
64 | isActivityPubUrlValid(activity.object.object) | ||
64 | } | 65 | } |
65 | 66 | ||
66 | function isAnnounceValid (activity: any) { | 67 | function isAnnounceValid (activity: any) { |
diff --git a/server/lib/activitypub/misc.ts b/server/lib/activitypub/misc.ts index f853d742e..c07d9f654 100644 --- a/server/lib/activitypub/misc.ts +++ b/server/lib/activitypub/misc.ts | |||
@@ -1,14 +1,12 @@ | |||
1 | import * as magnetUtil from 'magnet-uri' | 1 | import * as magnetUtil from 'magnet-uri' |
2 | import * as Sequelize from 'sequelize' | ||
3 | import { VideoTorrentObject } from '../../../shared' | 2 | import { VideoTorrentObject } from '../../../shared' |
3 | import { VideoChannelObject } from '../../../shared/models/activitypub/objects/video-channel-object' | ||
4 | import { isVideoFileInfoHashValid } from '../../helpers/custom-validators/videos' | 4 | import { isVideoFileInfoHashValid } from '../../helpers/custom-validators/videos' |
5 | import { database as db } from '../../initializers' | ||
6 | import { VIDEO_MIMETYPE_EXT } from '../../initializers/constants' | 5 | import { VIDEO_MIMETYPE_EXT } from '../../initializers/constants' |
6 | import { AccountInstance } from '../../models/account/account-interface' | ||
7 | import { VideoChannelInstance } from '../../models/video/video-channel-interface' | 7 | import { VideoChannelInstance } from '../../models/video/video-channel-interface' |
8 | import { VideoFileAttributes } from '../../models/video/video-file-interface' | 8 | import { VideoFileAttributes } from '../../models/video/video-file-interface' |
9 | import { VideoAttributes, VideoInstance } from '../../models/video/video-interface' | 9 | import { VideoAttributes, VideoInstance } from '../../models/video/video-interface' |
10 | import { VideoChannelObject } from '../../../shared/models/activitypub/objects/video-channel-object' | ||
11 | import { AccountInstance } from '../../models/account/account-interface' | ||
12 | 10 | ||
13 | function videoChannelActivityObjectToDBAttributes (videoChannelObject: VideoChannelObject, account: AccountInstance) { | 11 | function videoChannelActivityObjectToDBAttributes (videoChannelObject: VideoChannelObject, account: AccountInstance) { |
14 | return { | 12 | return { |
diff --git a/server/lib/activitypub/send-request.ts b/server/lib/activitypub/send-request.ts index d5d07011a..abc1b598d 100644 --- a/server/lib/activitypub/send-request.ts +++ b/server/lib/activitypub/send-request.ts | |||
@@ -8,7 +8,7 @@ import { | |||
8 | } from '../../models' | 8 | } from '../../models' |
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, VideoAbuseObject } from '../../../shared' |
12 | import { VideoAbuseInstance } from '../../models/video/video-abuse-interface' | 12 | import { VideoAbuseInstance } from '../../models/video/video-abuse-interface' |
13 | import { getActivityPubUrl } from '../../helpers/activitypub' | 13 | import { getActivityPubUrl } from '../../helpers/activitypub' |
14 | import { logger } from '../../helpers/logger' | 14 | import { logger } from '../../helpers/logger' |
@@ -96,7 +96,7 @@ async function sendVideoAbuse ( | |||
96 | t: Sequelize.Transaction | 96 | t: Sequelize.Transaction |
97 | ) { | 97 | ) { |
98 | const url = getActivityPubUrl('videoAbuse', videoAbuse.id.toString()) | 98 | const url = getActivityPubUrl('videoAbuse', videoAbuse.id.toString()) |
99 | const data = await createActivityData(url, fromAccount, video.url) | 99 | const data = await createActivityData(url, fromAccount, videoAbuse.toActivityPubObject()) |
100 | 100 | ||
101 | return unicastTo(data, video.VideoChannel.Account.sharedInboxUrl, t) | 101 | return unicastTo(data, video.VideoChannel.Account.sharedInboxUrl, t) |
102 | } | 102 | } |
diff --git a/server/models/video/video-abuse-interface.ts b/server/models/video/video-abuse-interface.ts index 96f0fbe4a..feafc4a19 100644 --- a/server/models/video/video-abuse-interface.ts +++ b/server/models/video/video-abuse-interface.ts | |||
@@ -5,15 +5,18 @@ import { VideoAbuse as FormattedVideoAbuse } from '../../../shared/models/videos | |||
5 | import { AccountInstance } from '../account/account-interface' | 5 | import { AccountInstance } from '../account/account-interface' |
6 | import { ServerInstance } from '../server/server-interface' | 6 | import { ServerInstance } from '../server/server-interface' |
7 | import { VideoInstance } from './video-interface' | 7 | import { VideoInstance } from './video-interface' |
8 | import { VideoAbuseObject } from '../../../shared/models/activitypub/objects/video-abuse-object' | ||
8 | 9 | ||
9 | export namespace VideoAbuseMethods { | 10 | export namespace VideoAbuseMethods { |
10 | export type ToFormattedJSON = (this: VideoAbuseInstance) => FormattedVideoAbuse | 11 | export type ToFormattedJSON = (this: VideoAbuseInstance) => FormattedVideoAbuse |
11 | 12 | ||
12 | export type ListForApi = (start: number, count: number, sort: string) => Promise< ResultList<VideoAbuseInstance> > | 13 | export type ListForApi = (start: number, count: number, sort: string) => Promise< ResultList<VideoAbuseInstance> > |
14 | export type ToActivityPubObject = () => VideoAbuseObject | ||
13 | } | 15 | } |
14 | 16 | ||
15 | export interface VideoAbuseClass { | 17 | export interface VideoAbuseClass { |
16 | listForApi: VideoAbuseMethods.ListForApi | 18 | listForApi: VideoAbuseMethods.ListForApi |
19 | toActivityPubObject: VideoAbuseMethods.ToActivityPubObject | ||
17 | } | 20 | } |
18 | 21 | ||
19 | export interface VideoAbuseAttributes { | 22 | export interface VideoAbuseAttributes { |
diff --git a/server/models/video/video-abuse.ts b/server/models/video/video-abuse.ts index f3fdeab52..e8f4f9a67 100644 --- a/server/models/video/video-abuse.ts +++ b/server/models/video/video-abuse.ts | |||
@@ -10,10 +10,12 @@ import { | |||
10 | 10 | ||
11 | VideoAbuseMethods | 11 | VideoAbuseMethods |
12 | } from './video-abuse-interface' | 12 | } from './video-abuse-interface' |
13 | import { VideoAbuseObject } from '../../../shared/models/activitypub/objects/video-abuse-object' | ||
13 | 14 | ||
14 | let VideoAbuse: Sequelize.Model<VideoAbuseInstance, VideoAbuseAttributes> | 15 | let VideoAbuse: Sequelize.Model<VideoAbuseInstance, VideoAbuseAttributes> |
15 | let toFormattedJSON: VideoAbuseMethods.ToFormattedJSON | 16 | let toFormattedJSON: VideoAbuseMethods.ToFormattedJSON |
16 | let listForApi: VideoAbuseMethods.ListForApi | 17 | let listForApi: VideoAbuseMethods.ListForApi |
18 | let toActivityPubObject: VideoAbuseMethods.ToActivityPubObject | ||
17 | 19 | ||
18 | export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) { | 20 | export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) { |
19 | VideoAbuse = sequelize.define<VideoAbuseInstance, VideoAbuseAttributes>('VideoAbuse', | 21 | VideoAbuse = sequelize.define<VideoAbuseInstance, VideoAbuseAttributes>('VideoAbuse', |
@@ -47,7 +49,8 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da | |||
47 | listForApi | 49 | listForApi |
48 | ] | 50 | ] |
49 | const instanceMethods = [ | 51 | const instanceMethods = [ |
50 | toFormattedJSON | 52 | toFormattedJSON, |
53 | toActivityPubObject | ||
51 | ] | 54 | ] |
52 | addMethodsToModel(VideoAbuse, classMethods, instanceMethods) | 55 | addMethodsToModel(VideoAbuse, classMethods, instanceMethods) |
53 | 56 | ||
@@ -80,6 +83,16 @@ toFormattedJSON = function (this: VideoAbuseInstance) { | |||
80 | return json | 83 | return json |
81 | } | 84 | } |
82 | 85 | ||
86 | toActivityPubObject = function (this: VideoAbuseInstance) { | ||
87 | const videoAbuseObject: VideoAbuseObject = { | ||
88 | type: 'Flag' as 'Flag', | ||
89 | content: this.reason, | ||
90 | object: this.Video.url | ||
91 | } | ||
92 | |||
93 | return videoAbuseObject | ||
94 | } | ||
95 | |||
83 | // ------------------------------ STATICS ------------------------------ | 96 | // ------------------------------ STATICS ------------------------------ |
84 | 97 | ||
85 | function associate (models) { | 98 | function associate (models) { |
diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 5b0377c2e..5fb254b2d 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts | |||
@@ -26,6 +26,7 @@ import { | |||
26 | unlinkPromise, | 26 | unlinkPromise, |
27 | writeFilePromise | 27 | writeFilePromise |
28 | } from '../../helpers' | 28 | } from '../../helpers' |
29 | import { isVideoUrlValid } from '../../helpers/custom-validators/videos' | ||
29 | import { | 30 | import { |
30 | API_VERSION, | 31 | API_VERSION, |
31 | CONFIG, | 32 | CONFIG, |
@@ -39,14 +40,13 @@ import { | |||
39 | VIDEO_LICENCES, | 40 | VIDEO_LICENCES, |
40 | VIDEO_PRIVACIES | 41 | VIDEO_PRIVACIES |
41 | } from '../../initializers' | 42 | } from '../../initializers' |
43 | import { sendDeleteVideo } from '../../lib/activitypub/send-request' | ||
42 | 44 | ||
43 | import { addMethodsToModel, getSort } from '../utils' | 45 | import { addMethodsToModel, getSort } from '../utils' |
44 | 46 | ||
45 | import { TagInstance } from './tag-interface' | 47 | import { TagInstance } from './tag-interface' |
46 | import { VideoFileInstance, VideoFileModel } from './video-file-interface' | 48 | import { VideoFileInstance, VideoFileModel } from './video-file-interface' |
47 | import { VideoAttributes, VideoInstance, VideoMethods } from './video-interface' | 49 | import { VideoAttributes, VideoInstance, VideoMethods } from './video-interface' |
48 | import { sendDeleteVideo } from '../../lib/activitypub/send-request' | ||
49 | import { isVideoUrlValid } from '../../helpers/custom-validators/videos' | ||
50 | 50 | ||
51 | const Buffer = safeBuffer.Buffer | 51 | const Buffer = safeBuffer.Buffer |
52 | 52 | ||