Federate video abuses

pull/128/head
Chocobozzz 2017-11-16 17:04:19 +01:00
parent d7d5611c8a
commit 21e0727a84
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
7 changed files with 28 additions and 12 deletions

View File

@ -75,6 +75,7 @@ async function reportVideoAbuse (req: express.Request, res: express.Response) {
await db.sequelize.transaction(async t => { await db.sequelize.transaction(async t => {
const videoAbuseInstance = await db.VideoAbuse.create(abuseToCreate, { transaction: t }) const videoAbuseInstance = await db.VideoAbuse.create(abuseToCreate, { transaction: t })
videoAbuseInstance.Video = videoInstance
// We send the video abuse to the origin server // We send the video abuse to the origin server
if (videoInstance.isOwned() === false) { if (videoInstance.isOwned() === false) {

View File

@ -58,9 +58,10 @@ function isVideoTorrentObjectValid (video: any) {
} }
function isVideoFlagValid (activity: any) { function isVideoFlagValid (activity: any) {
return isBaseActivityValid(activity, 'Flag') && return isBaseActivityValid(activity, 'Create') &&
isVideoAbuseReasonValid(activity.content) && activity.object.type === 'Flag' &&
isActivityPubUrlValid(activity.object) isVideoAbuseReasonValid(activity.object.content) &&
isActivityPubUrlValid(activity.object.object)
} }
function isAnnounceValid (activity: any) { function isAnnounceValid (activity: any) {

View File

@ -1,14 +1,12 @@
import * as magnetUtil from 'magnet-uri' import * as magnetUtil from 'magnet-uri'
import * as Sequelize from 'sequelize'
import { VideoTorrentObject } from '../../../shared' import { VideoTorrentObject } from '../../../shared'
import { VideoChannelObject } from '../../../shared/models/activitypub/objects/video-channel-object'
import { isVideoFileInfoHashValid } from '../../helpers/custom-validators/videos' import { isVideoFileInfoHashValid } from '../../helpers/custom-validators/videos'
import { database as db } from '../../initializers'
import { VIDEO_MIMETYPE_EXT } from '../../initializers/constants' import { VIDEO_MIMETYPE_EXT } from '../../initializers/constants'
import { AccountInstance } from '../../models/account/account-interface'
import { VideoChannelInstance } from '../../models/video/video-channel-interface' import { VideoChannelInstance } from '../../models/video/video-channel-interface'
import { VideoFileAttributes } from '../../models/video/video-file-interface' import { VideoFileAttributes } from '../../models/video/video-file-interface'
import { VideoAttributes, VideoInstance } from '../../models/video/video-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) { function videoChannelActivityObjectToDBAttributes (videoChannelObject: VideoChannelObject, account: AccountInstance) {
return { return {

View File

@ -8,7 +8,7 @@ import {
} from '../../models' } from '../../models'
import { httpRequestJobScheduler } from '../jobs' import { httpRequestJobScheduler } from '../jobs'
import { signObject, activityPubContextify } from '../../helpers' import { signObject, activityPubContextify } from '../../helpers'
import { Activity } from '../../../shared' import { Activity, VideoAbuseObject } from '../../../shared'
import { VideoAbuseInstance } from '../../models/video/video-abuse-interface' import { VideoAbuseInstance } from '../../models/video/video-abuse-interface'
import { getActivityPubUrl } from '../../helpers/activitypub' import { getActivityPubUrl } from '../../helpers/activitypub'
import { logger } from '../../helpers/logger' import { logger } from '../../helpers/logger'
@ -96,7 +96,7 @@ async function sendVideoAbuse (
t: Sequelize.Transaction t: Sequelize.Transaction
) { ) {
const url = getActivityPubUrl('videoAbuse', videoAbuse.id.toString()) 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) return unicastTo(data, video.VideoChannel.Account.sharedInboxUrl, t)
} }

View File

@ -5,15 +5,18 @@ import { VideoAbuse as FormattedVideoAbuse } from '../../../shared/models/videos
import { AccountInstance } from '../account/account-interface' import { AccountInstance } from '../account/account-interface'
import { ServerInstance } from '../server/server-interface' import { ServerInstance } from '../server/server-interface'
import { VideoInstance } from './video-interface' import { VideoInstance } from './video-interface'
import { VideoAbuseObject } from '../../../shared/models/activitypub/objects/video-abuse-object'
export namespace VideoAbuseMethods { export namespace VideoAbuseMethods {
export type ToFormattedJSON = (this: VideoAbuseInstance) => FormattedVideoAbuse export type ToFormattedJSON = (this: VideoAbuseInstance) => FormattedVideoAbuse
export type ListForApi = (start: number, count: number, sort: string) => Promise< ResultList<VideoAbuseInstance> > export type ListForApi = (start: number, count: number, sort: string) => Promise< ResultList<VideoAbuseInstance> >
export type ToActivityPubObject = () => VideoAbuseObject
} }
export interface VideoAbuseClass { export interface VideoAbuseClass {
listForApi: VideoAbuseMethods.ListForApi listForApi: VideoAbuseMethods.ListForApi
toActivityPubObject: VideoAbuseMethods.ToActivityPubObject
} }
export interface VideoAbuseAttributes { export interface VideoAbuseAttributes {

View File

@ -10,10 +10,12 @@ import {
VideoAbuseMethods VideoAbuseMethods
} from './video-abuse-interface' } from './video-abuse-interface'
import { VideoAbuseObject } from '../../../shared/models/activitypub/objects/video-abuse-object'
let VideoAbuse: Sequelize.Model<VideoAbuseInstance, VideoAbuseAttributes> let VideoAbuse: Sequelize.Model<VideoAbuseInstance, VideoAbuseAttributes>
let toFormattedJSON: VideoAbuseMethods.ToFormattedJSON let toFormattedJSON: VideoAbuseMethods.ToFormattedJSON
let listForApi: VideoAbuseMethods.ListForApi let listForApi: VideoAbuseMethods.ListForApi
let toActivityPubObject: VideoAbuseMethods.ToActivityPubObject
export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) { export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) {
VideoAbuse = sequelize.define<VideoAbuseInstance, VideoAbuseAttributes>('VideoAbuse', VideoAbuse = sequelize.define<VideoAbuseInstance, VideoAbuseAttributes>('VideoAbuse',
@ -47,7 +49,8 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da
listForApi listForApi
] ]
const instanceMethods = [ const instanceMethods = [
toFormattedJSON toFormattedJSON,
toActivityPubObject
] ]
addMethodsToModel(VideoAbuse, classMethods, instanceMethods) addMethodsToModel(VideoAbuse, classMethods, instanceMethods)
@ -80,6 +83,16 @@ toFormattedJSON = function (this: VideoAbuseInstance) {
return json return json
} }
toActivityPubObject = function (this: VideoAbuseInstance) {
const videoAbuseObject: VideoAbuseObject = {
type: 'Flag' as 'Flag',
content: this.reason,
object: this.Video.url
}
return videoAbuseObject
}
// ------------------------------ STATICS ------------------------------ // ------------------------------ STATICS ------------------------------
function associate (models) { function associate (models) {

View File

@ -26,6 +26,7 @@ import {
unlinkPromise, unlinkPromise,
writeFilePromise writeFilePromise
} from '../../helpers' } from '../../helpers'
import { isVideoUrlValid } from '../../helpers/custom-validators/videos'
import { import {
API_VERSION, API_VERSION,
CONFIG, CONFIG,
@ -39,14 +40,13 @@ import {
VIDEO_LICENCES, VIDEO_LICENCES,
VIDEO_PRIVACIES VIDEO_PRIVACIES
} from '../../initializers' } from '../../initializers'
import { sendDeleteVideo } from '../../lib/activitypub/send-request'
import { addMethodsToModel, getSort } from '../utils' import { addMethodsToModel, getSort } from '../utils'
import { TagInstance } from './tag-interface' import { TagInstance } from './tag-interface'
import { VideoFileInstance, VideoFileModel } from './video-file-interface' import { VideoFileInstance, VideoFileModel } from './video-file-interface'
import { VideoAttributes, VideoInstance, VideoMethods } from './video-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 const Buffer = safeBuffer.Buffer