mirror of https://github.com/Chocobozzz/PeerTube
Federate video abuses
parent
d7d5611c8a
commit
21e0727a84
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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<VideoAbuseInstance> >
|
||||
export type ToActivityPubObject = () => VideoAbuseObject
|
||||
}
|
||||
|
||||
export interface VideoAbuseClass {
|
||||
listForApi: VideoAbuseMethods.ListForApi
|
||||
toActivityPubObject: VideoAbuseMethods.ToActivityPubObject
|
||||
}
|
||||
|
||||
export interface VideoAbuseAttributes {
|
||||
|
|
|
@ -10,10 +10,12 @@ import {
|
|||
|
||||
VideoAbuseMethods
|
||||
} from './video-abuse-interface'
|
||||
import { VideoAbuseObject } from '../../../shared/models/activitypub/objects/video-abuse-object'
|
||||
|
||||
let VideoAbuse: Sequelize.Model<VideoAbuseInstance, VideoAbuseAttributes>
|
||||
let toFormattedJSON: VideoAbuseMethods.ToFormattedJSON
|
||||
let listForApi: VideoAbuseMethods.ListForApi
|
||||
let toActivityPubObject: VideoAbuseMethods.ToActivityPubObject
|
||||
|
||||
export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) {
|
||||
VideoAbuse = sequelize.define<VideoAbuseInstance, VideoAbuseAttributes>('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) {
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue