From 21e0727a84734cb0c81c1c9bb22a49b13e46fe5f Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 16 Nov 2017 17:04:19 +0100 Subject: Federate video abuses --- server/models/video/video-abuse-interface.ts | 3 +++ server/models/video/video-abuse.ts | 15 ++++++++++++++- server/models/video/video.ts | 4 ++-- 3 files changed, 19 insertions(+), 3 deletions(-) (limited to 'server/models') 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 -- cgit v1.2.3