From: Chocobozzz Date: Thu, 16 Nov 2017 16:04:19 +0000 (+0100) Subject: Federate video abuses X-Git-Tag: v0.0.1-alpha~210 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=21e0727a84734cb0c81c1c9bb22a49b13e46fe5f;p=oweals%2Fpeertube.git Federate video abuses --- 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) { await db.sequelize.transaction(async t => { const videoAbuseInstance = await db.VideoAbuse.create(abuseToCreate, { transaction: t }) + videoAbuseInstance.Video = videoInstance // We send the video abuse to the origin server 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) { } function isVideoFlagValid (activity: any) { - return isBaseActivityValid(activity, 'Flag') && - isVideoAbuseReasonValid(activity.content) && - isActivityPubUrlValid(activity.object) + return isBaseActivityValid(activity, 'Create') && + activity.object.type === 'Flag' && + isVideoAbuseReasonValid(activity.object.content) && + isActivityPubUrlValid(activity.object.object) } 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 @@ import * as magnetUtil from 'magnet-uri' -import * as Sequelize from 'sequelize' import { VideoTorrentObject } from '../../../shared' +import { VideoChannelObject } from '../../../shared/models/activitypub/objects/video-channel-object' import { isVideoFileInfoHashValid } from '../../helpers/custom-validators/videos' -import { database as db } from '../../initializers' import { VIDEO_MIMETYPE_EXT } from '../../initializers/constants' +import { AccountInstance } from '../../models/account/account-interface' import { VideoChannelInstance } from '../../models/video/video-channel-interface' import { VideoFileAttributes } from '../../models/video/video-file-interface' import { VideoAttributes, VideoInstance } from '../../models/video/video-interface' -import { VideoChannelObject } from '../../../shared/models/activitypub/objects/video-channel-object' -import { AccountInstance } from '../../models/account/account-interface' function videoChannelActivityObjectToDBAttributes (videoChannelObject: VideoChannelObject, account: AccountInstance) { 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 { } from '../../models' import { httpRequestJobScheduler } from '../jobs' import { signObject, activityPubContextify } from '../../helpers' -import { Activity } from '../../../shared' +import { Activity, VideoAbuseObject } from '../../../shared' import { VideoAbuseInstance } from '../../models/video/video-abuse-interface' import { getActivityPubUrl } from '../../helpers/activitypub' import { logger } from '../../helpers/logger' @@ -96,7 +96,7 @@ async function sendVideoAbuse ( t: Sequelize.Transaction ) { const url = getActivityPubUrl('videoAbuse', videoAbuse.id.toString()) - const data = await createActivityData(url, fromAccount, video.url) + const data = await createActivityData(url, fromAccount, videoAbuse.toActivityPubObject()) return unicastTo(data, video.VideoChannel.Account.sharedInboxUrl, t) } 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 import { AccountInstance } from '../account/account-interface' import { ServerInstance } from '../server/server-interface' import { VideoInstance } from './video-interface' +import { VideoAbuseObject } from '../../../shared/models/activitypub/objects/video-abuse-object' export namespace VideoAbuseMethods { export type ToFormattedJSON = (this: VideoAbuseInstance) => FormattedVideoAbuse export type ListForApi = (start: number, count: number, sort: string) => Promise< ResultList > + export type ToActivityPubObject = () => VideoAbuseObject } export interface VideoAbuseClass { listForApi: VideoAbuseMethods.ListForApi + toActivityPubObject: VideoAbuseMethods.ToActivityPubObject } 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 { VideoAbuseMethods } from './video-abuse-interface' +import { VideoAbuseObject } from '../../../shared/models/activitypub/objects/video-abuse-object' let VideoAbuse: Sequelize.Model let toFormattedJSON: VideoAbuseMethods.ToFormattedJSON let listForApi: VideoAbuseMethods.ListForApi +let toActivityPubObject: VideoAbuseMethods.ToActivityPubObject export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) { VideoAbuse = sequelize.define('VideoAbuse', @@ -47,7 +49,8 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da listForApi ] const instanceMethods = [ - toFormattedJSON + toFormattedJSON, + toActivityPubObject ] addMethodsToModel(VideoAbuse, classMethods, instanceMethods) @@ -80,6 +83,16 @@ toFormattedJSON = function (this: VideoAbuseInstance) { return json } +toActivityPubObject = function (this: VideoAbuseInstance) { + const videoAbuseObject: VideoAbuseObject = { + type: 'Flag' as 'Flag', + content: this.reason, + object: this.Video.url + } + + return videoAbuseObject +} + // ------------------------------ STATICS ------------------------------ 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 { unlinkPromise, writeFilePromise } from '../../helpers' +import { isVideoUrlValid } from '../../helpers/custom-validators/videos' import { API_VERSION, CONFIG, @@ -39,14 +40,13 @@ import { VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../initializers' +import { sendDeleteVideo } from '../../lib/activitypub/send-request' import { addMethodsToModel, getSort } from '../utils' import { TagInstance } from './tag-interface' import { VideoFileInstance, VideoFileModel } from './video-file-interface' import { VideoAttributes, VideoInstance, VideoMethods } from './video-interface' -import { sendDeleteVideo } from '../../lib/activitypub/send-request' -import { isVideoUrlValid } from '../../helpers/custom-validators/videos' const Buffer = safeBuffer.Buffer