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) {
}
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) {
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 {
} 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'
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)
}
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 {
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',
listForApi
]
const instanceMethods = [
- toFormattedJSON
+ toFormattedJSON,
+ toActivityPubObject
]
addMethodsToModel(VideoAbuse, classMethods, instanceMethods)
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) {
unlinkPromise,
writeFilePromise
} from '../../helpers'
+import { isVideoUrlValid } from '../../helpers/custom-validators/videos'
import {
API_VERSION,
CONFIG,
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