X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Fmoderation.ts;h=c2565f86769601ab7d2bcfcb546252147b759d8d;hb=419b520ca4434d17f3505013174e195c3a316716;hp=4fc9cd747609a22d0d612caafc8e6c1fb944b566;hpb=ec903c010ecc54ec2acad0bf2cf10e7fbf6a0fa2;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/moderation.ts b/server/lib/moderation.ts index 4fc9cd747..c2565f867 100644 --- a/server/lib/moderation.ts +++ b/server/lib/moderation.ts @@ -1,6 +1,8 @@ +import { VideoUploadFile } from 'express' import { PathLike } from 'fs-extra' import { Transaction } from 'sequelize/types' import { AbuseAuditView, auditLoggerFactory } from '@server/helpers/audit-logger' +import { afterCommitIfTransaction } from '@server/helpers/database-utils' import { logger } from '@server/helpers/logger' import { AbuseModel } from '@server/models/abuse/abuse' import { VideoAbuseModel } from '@server/models/abuse/video-abuse' @@ -18,12 +20,12 @@ import { MVideoAccountLightBlacklistAllFiles } from '@server/types/models' import { ActivityCreate } from '../../shared/models/activitypub' -import { VideoTorrentObject } from '../../shared/models/activitypub/objects' +import { VideoObject } from '../../shared/models/activitypub/objects' import { VideoCommentObject } from '../../shared/models/activitypub/objects/video-comment-object' -import { VideoCreate, VideoImportCreate } from '../../shared/models/videos' -import { VideoCommentCreate } from '../../shared/models/videos/video-comment.model' -import { UserModel } from '../models/account/user' -import { ActorModel } from '../models/activitypub/actor' +import { LiveVideoCreate, VideoCreate, VideoImportCreate } from '../../shared/models/videos' +import { VideoCommentCreate } from '../../shared/models/videos/comment' +import { ActorModel } from '../models/actor/actor' +import { UserModel } from '../models/user/user' import { VideoModel } from '../models/video/video' import { VideoCommentModel } from '../models/video/video-comment' import { sendAbuse } from './activitypub/send/send-flag' @@ -37,7 +39,14 @@ export type AcceptResult = { // Can be filtered by plugins function isLocalVideoAccepted (object: { videoBody: VideoCreate - videoFile: Express.Multer.File & { duration?: number } + videoFile: VideoUploadFile + user: UserModel +}): AcceptResult { + return { accepted: true } +} + +function isLocalLiveVideoAccepted (object: { + liveVideoBody: LiveVideoCreate user: UserModel }): AcceptResult { return { accepted: true } @@ -62,7 +71,7 @@ function isLocalVideoCommentReplyAccepted (_object: { function isRemoteVideoAccepted (_object: { activity: ActivityCreate - videoAP: VideoTorrentObject + videoAP: VideoObject byActor: ActorModel }): AcceptResult { return { accepted: true } @@ -98,8 +107,9 @@ async function createVideoAbuse (options: { endAt: number transaction: Transaction reporterAccount: MAccountDefault + skipNotification: boolean }) { - const { baseAbuse, videoInstance, startAt, endAt, transaction, reporterAccount } = options + const { baseAbuse, videoInstance, startAt, endAt, transaction, reporterAccount, skipNotification } = options const associateFun = async (abuseInstance: MAbuseFull) => { const videoAbuseInstance: MVideoAbuseVideoFull = await VideoAbuseModel.create({ @@ -120,6 +130,7 @@ async function createVideoAbuse (options: { reporterAccount, flaggedAccount: videoInstance.VideoChannel.Account, transaction, + skipNotification, associateFun }) } @@ -129,8 +140,9 @@ function createVideoCommentAbuse (options: { commentInstance: MCommentOwnerVideo transaction: Transaction reporterAccount: MAccountDefault + skipNotification: boolean }) { - const { baseAbuse, commentInstance, transaction, reporterAccount } = options + const { baseAbuse, commentInstance, transaction, reporterAccount, skipNotification } = options const associateFun = async (abuseInstance: MAbuseFull) => { const commentAbuseInstance: MCommentAbuseAccountVideo = await VideoCommentAbuseModel.create({ @@ -149,6 +161,7 @@ function createVideoCommentAbuse (options: { reporterAccount, flaggedAccount: commentInstance.Account, transaction, + skipNotification, associateFun }) } @@ -158,11 +171,12 @@ function createAccountAbuse (options: { accountInstance: MAccountDefault transaction: Transaction reporterAccount: MAccountDefault + skipNotification: boolean }) { - const { baseAbuse, accountInstance, transaction, reporterAccount } = options + const { baseAbuse, accountInstance, transaction, reporterAccount, skipNotification } = options - const associateFun = async () => { - return { isOwned: accountInstance.isOwned() } + const associateFun = () => { + return Promise.resolve({ isOwned: accountInstance.isOwned() }) } return createAbuse({ @@ -170,11 +184,14 @@ function createAccountAbuse (options: { reporterAccount, flaggedAccount: accountInstance, transaction, + skipNotification, associateFun }) } export { + isLocalLiveVideoAccepted, + isLocalVideoAccepted, isLocalVideoThreadAccepted, isRemoteVideoAccepted, @@ -196,9 +213,10 @@ async function createAbuse (options: { reporterAccount: MAccountDefault flaggedAccount: MAccountLight associateFun: (abuseInstance: MAbuseFull) => Promise<{ isOwned: boolean} > + skipNotification: boolean transaction: Transaction }) { - const { base, reporterAccount, flaggedAccount, associateFun, transaction } = options + const { base, reporterAccount, flaggedAccount, associateFun, transaction, skipNotification } = options const auditLogger = auditLoggerFactory('abuse') const abuseAttributes = Object.assign({}, base, { flaggedAccountId: flaggedAccount.id }) @@ -210,17 +228,21 @@ async function createAbuse (options: { const { isOwned } = await associateFun(abuseInstance) if (isOwned === false) { - await sendAbuse(reporterAccount.Actor, abuseInstance, abuseInstance.FlaggedAccount, transaction) + sendAbuse(reporterAccount.Actor, abuseInstance, abuseInstance.FlaggedAccount, transaction) } - const abuseJSON = abuseInstance.toFormattedJSON() + const abuseJSON = abuseInstance.toFormattedAdminJSON() auditLogger.create(reporterAccount.Actor.getIdentifier(), new AbuseAuditView(abuseJSON)) - Notifier.Instance.notifyOnNewAbuse({ - abuse: abuseJSON, - abuseInstance, - reporter: reporterAccount.Actor.getIdentifier() - }) + if (!skipNotification) { + afterCommitIfTransaction(transaction, () => { + Notifier.Instance.notifyOnNewAbuse({ + abuse: abuseJSON, + abuseInstance, + reporter: reporterAccount.Actor.getIdentifier() + }) + }) + } logger.info('Abuse report %d created.', abuseInstance.id)