2021-05-10 05:13:41 -04:00
|
|
|
import { VideoUploadFile } from 'express'
|
2020-07-01 10:05:30 -04:00
|
|
|
import { PathLike } from 'fs-extra'
|
|
|
|
import { Transaction } from 'sequelize/types'
|
|
|
|
import { AbuseAuditView, auditLoggerFactory } from '@server/helpers/audit-logger'
|
2021-05-10 05:13:41 -04:00
|
|
|
import { afterCommitIfTransaction } from '@server/helpers/database-utils'
|
2020-07-01 10:05:30 -04:00
|
|
|
import { logger } from '@server/helpers/logger'
|
|
|
|
import { AbuseModel } from '@server/models/abuse/abuse'
|
|
|
|
import { VideoAbuseModel } from '@server/models/abuse/video-abuse'
|
|
|
|
import { VideoCommentAbuseModel } from '@server/models/abuse/video-comment-abuse'
|
|
|
|
import { VideoFileModel } from '@server/models/video/video-file'
|
|
|
|
import { FilteredModelAttributes } from '@server/types'
|
|
|
|
import {
|
|
|
|
MAbuseFull,
|
|
|
|
MAccountDefault,
|
|
|
|
MAccountLight,
|
|
|
|
MCommentAbuseAccountVideo,
|
|
|
|
MCommentOwnerVideo,
|
|
|
|
MUser,
|
|
|
|
MVideoAbuseVideoFull,
|
|
|
|
MVideoAccountLightBlacklistAllFiles
|
|
|
|
} from '@server/types/models'
|
|
|
|
import { ActivityCreate } from '../../shared/models/activitypub'
|
2020-09-17 07:59:02 -04:00
|
|
|
import { VideoObject } from '../../shared/models/activitypub/objects'
|
2020-07-01 10:05:30 -04:00
|
|
|
import { VideoCommentObject } from '../../shared/models/activitypub/objects/video-comment-object'
|
2020-11-06 07:59:50 -05:00
|
|
|
import { LiveVideoCreate, VideoCreate, VideoImportCreate } from '../../shared/models/videos'
|
2021-07-09 08:15:11 -04:00
|
|
|
import { VideoCommentCreate } from '../../shared/models/videos/comment'
|
2021-05-11 05:15:29 -04:00
|
|
|
import { ActorModel } from '../models/actor/actor'
|
2021-05-11 05:27:40 -04:00
|
|
|
import { UserModel } from '../models/user/user'
|
2020-07-01 10:05:30 -04:00
|
|
|
import { VideoModel } from '../models/video/video'
|
|
|
|
import { VideoCommentModel } from '../models/video/video-comment'
|
|
|
|
import { sendAbuse } from './activitypub/send/send-flag'
|
|
|
|
import { Notifier } from './notifier'
|
2019-07-18 08:28:37 -04:00
|
|
|
|
|
|
|
export type AcceptResult = {
|
|
|
|
accepted: boolean
|
|
|
|
errorMessage?: string
|
|
|
|
}
|
|
|
|
|
|
|
|
// Can be filtered by plugins
|
|
|
|
function isLocalVideoAccepted (object: {
|
2020-01-31 10:56:52 -05:00
|
|
|
videoBody: VideoCreate
|
2021-05-10 05:13:41 -04:00
|
|
|
videoFile: VideoUploadFile
|
2019-07-18 08:28:37 -04:00
|
|
|
user: UserModel
|
|
|
|
}): AcceptResult {
|
|
|
|
return { accepted: true }
|
|
|
|
}
|
|
|
|
|
2020-11-06 07:59:50 -05:00
|
|
|
function isLocalLiveVideoAccepted (object: {
|
|
|
|
liveVideoBody: LiveVideoCreate
|
|
|
|
user: UserModel
|
|
|
|
}): AcceptResult {
|
|
|
|
return { accepted: true }
|
|
|
|
}
|
|
|
|
|
2019-07-18 08:28:37 -04:00
|
|
|
function isLocalVideoThreadAccepted (_object: {
|
2020-01-31 10:56:52 -05:00
|
|
|
commentBody: VideoCommentCreate
|
|
|
|
video: VideoModel
|
2019-07-18 08:28:37 -04:00
|
|
|
user: UserModel
|
|
|
|
}): AcceptResult {
|
|
|
|
return { accepted: true }
|
|
|
|
}
|
|
|
|
|
|
|
|
function isLocalVideoCommentReplyAccepted (_object: {
|
2020-01-31 10:56:52 -05:00
|
|
|
commentBody: VideoCommentCreate
|
|
|
|
parentComment: VideoCommentModel
|
|
|
|
video: VideoModel
|
2019-07-18 08:28:37 -04:00
|
|
|
user: UserModel
|
|
|
|
}): AcceptResult {
|
|
|
|
return { accepted: true }
|
|
|
|
}
|
|
|
|
|
|
|
|
function isRemoteVideoAccepted (_object: {
|
2020-01-31 10:56:52 -05:00
|
|
|
activity: ActivityCreate
|
2020-09-17 07:59:02 -04:00
|
|
|
videoAP: VideoObject
|
2019-07-18 08:28:37 -04:00
|
|
|
byActor: ActorModel
|
|
|
|
}): AcceptResult {
|
|
|
|
return { accepted: true }
|
|
|
|
}
|
|
|
|
|
|
|
|
function isRemoteVideoCommentAccepted (_object: {
|
2020-01-31 10:56:52 -05:00
|
|
|
activity: ActivityCreate
|
|
|
|
commentAP: VideoCommentObject
|
2019-07-18 08:28:37 -04:00
|
|
|
byActor: ActorModel
|
|
|
|
}): AcceptResult {
|
|
|
|
return { accepted: true }
|
|
|
|
}
|
|
|
|
|
2020-05-14 05:10:26 -04:00
|
|
|
function isPreImportVideoAccepted (object: {
|
|
|
|
videoImportBody: VideoImportCreate
|
|
|
|
user: MUser
|
|
|
|
}): AcceptResult {
|
|
|
|
return { accepted: true }
|
|
|
|
}
|
|
|
|
|
|
|
|
function isPostImportVideoAccepted (object: {
|
|
|
|
videoFilePath: PathLike
|
|
|
|
videoFile: VideoFileModel
|
|
|
|
user: MUser
|
|
|
|
}): AcceptResult {
|
|
|
|
return { accepted: true }
|
|
|
|
}
|
|
|
|
|
2020-07-01 10:05:30 -04:00
|
|
|
async function createVideoAbuse (options: {
|
|
|
|
baseAbuse: FilteredModelAttributes<AbuseModel>
|
|
|
|
videoInstance: MVideoAccountLightBlacklistAllFiles
|
|
|
|
startAt: number
|
|
|
|
endAt: number
|
|
|
|
transaction: Transaction
|
|
|
|
reporterAccount: MAccountDefault
|
2021-12-09 08:27:32 -05:00
|
|
|
skipNotification: boolean
|
2020-07-01 10:05:30 -04:00
|
|
|
}) {
|
2021-12-09 08:27:32 -05:00
|
|
|
const { baseAbuse, videoInstance, startAt, endAt, transaction, reporterAccount, skipNotification } = options
|
2020-07-01 10:05:30 -04:00
|
|
|
|
|
|
|
const associateFun = async (abuseInstance: MAbuseFull) => {
|
|
|
|
const videoAbuseInstance: MVideoAbuseVideoFull = await VideoAbuseModel.create({
|
|
|
|
abuseId: abuseInstance.id,
|
|
|
|
videoId: videoInstance.id,
|
|
|
|
startAt: startAt,
|
|
|
|
endAt: endAt
|
|
|
|
}, { transaction })
|
|
|
|
|
|
|
|
videoAbuseInstance.Video = videoInstance
|
|
|
|
abuseInstance.VideoAbuse = videoAbuseInstance
|
|
|
|
|
|
|
|
return { isOwned: videoInstance.isOwned() }
|
|
|
|
}
|
|
|
|
|
|
|
|
return createAbuse({
|
|
|
|
base: baseAbuse,
|
|
|
|
reporterAccount,
|
|
|
|
flaggedAccount: videoInstance.VideoChannel.Account,
|
|
|
|
transaction,
|
2021-12-09 08:27:32 -05:00
|
|
|
skipNotification,
|
2020-07-01 10:05:30 -04:00
|
|
|
associateFun
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function createVideoCommentAbuse (options: {
|
|
|
|
baseAbuse: FilteredModelAttributes<AbuseModel>
|
|
|
|
commentInstance: MCommentOwnerVideo
|
|
|
|
transaction: Transaction
|
|
|
|
reporterAccount: MAccountDefault
|
2021-12-09 08:27:32 -05:00
|
|
|
skipNotification: boolean
|
2020-07-01 10:05:30 -04:00
|
|
|
}) {
|
2021-12-09 08:27:32 -05:00
|
|
|
const { baseAbuse, commentInstance, transaction, reporterAccount, skipNotification } = options
|
2020-07-01 10:05:30 -04:00
|
|
|
|
|
|
|
const associateFun = async (abuseInstance: MAbuseFull) => {
|
|
|
|
const commentAbuseInstance: MCommentAbuseAccountVideo = await VideoCommentAbuseModel.create({
|
|
|
|
abuseId: abuseInstance.id,
|
|
|
|
videoCommentId: commentInstance.id
|
|
|
|
}, { transaction })
|
|
|
|
|
|
|
|
commentAbuseInstance.VideoComment = commentInstance
|
|
|
|
abuseInstance.VideoCommentAbuse = commentAbuseInstance
|
|
|
|
|
|
|
|
return { isOwned: commentInstance.isOwned() }
|
|
|
|
}
|
|
|
|
|
|
|
|
return createAbuse({
|
|
|
|
base: baseAbuse,
|
|
|
|
reporterAccount,
|
|
|
|
flaggedAccount: commentInstance.Account,
|
|
|
|
transaction,
|
2021-12-09 08:27:32 -05:00
|
|
|
skipNotification,
|
2020-07-01 10:05:30 -04:00
|
|
|
associateFun
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function createAccountAbuse (options: {
|
|
|
|
baseAbuse: FilteredModelAttributes<AbuseModel>
|
|
|
|
accountInstance: MAccountDefault
|
|
|
|
transaction: Transaction
|
|
|
|
reporterAccount: MAccountDefault
|
2021-12-09 08:27:32 -05:00
|
|
|
skipNotification: boolean
|
2020-07-01 10:05:30 -04:00
|
|
|
}) {
|
2021-12-09 08:27:32 -05:00
|
|
|
const { baseAbuse, accountInstance, transaction, reporterAccount, skipNotification } = options
|
2020-07-01 10:05:30 -04:00
|
|
|
|
2021-08-25 10:14:11 -04:00
|
|
|
const associateFun = () => {
|
|
|
|
return Promise.resolve({ isOwned: accountInstance.isOwned() })
|
2020-07-01 10:05:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return createAbuse({
|
|
|
|
base: baseAbuse,
|
|
|
|
reporterAccount,
|
|
|
|
flaggedAccount: accountInstance,
|
|
|
|
transaction,
|
2021-12-09 08:27:32 -05:00
|
|
|
skipNotification,
|
2020-07-01 10:05:30 -04:00
|
|
|
associateFun
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-07-18 08:28:37 -04:00
|
|
|
export {
|
2020-11-06 07:59:50 -05:00
|
|
|
isLocalLiveVideoAccepted,
|
|
|
|
|
2019-07-18 08:28:37 -04:00
|
|
|
isLocalVideoAccepted,
|
|
|
|
isLocalVideoThreadAccepted,
|
|
|
|
isRemoteVideoAccepted,
|
|
|
|
isRemoteVideoCommentAccepted,
|
2020-05-14 05:10:26 -04:00
|
|
|
isLocalVideoCommentReplyAccepted,
|
|
|
|
isPreImportVideoAccepted,
|
2020-07-01 10:05:30 -04:00
|
|
|
isPostImportVideoAccepted,
|
|
|
|
|
|
|
|
createAbuse,
|
|
|
|
createVideoAbuse,
|
|
|
|
createVideoCommentAbuse,
|
|
|
|
createAccountAbuse
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
async function createAbuse (options: {
|
|
|
|
base: FilteredModelAttributes<AbuseModel>
|
|
|
|
reporterAccount: MAccountDefault
|
|
|
|
flaggedAccount: MAccountLight
|
|
|
|
associateFun: (abuseInstance: MAbuseFull) => Promise<{ isOwned: boolean} >
|
2021-12-09 08:27:32 -05:00
|
|
|
skipNotification: boolean
|
2020-07-01 10:05:30 -04:00
|
|
|
transaction: Transaction
|
|
|
|
}) {
|
2021-12-09 08:27:32 -05:00
|
|
|
const { base, reporterAccount, flaggedAccount, associateFun, transaction, skipNotification } = options
|
2020-07-01 10:05:30 -04:00
|
|
|
const auditLogger = auditLoggerFactory('abuse')
|
|
|
|
|
|
|
|
const abuseAttributes = Object.assign({}, base, { flaggedAccountId: flaggedAccount.id })
|
|
|
|
const abuseInstance: MAbuseFull = await AbuseModel.create(abuseAttributes, { transaction })
|
|
|
|
|
|
|
|
abuseInstance.ReporterAccount = reporterAccount
|
|
|
|
abuseInstance.FlaggedAccount = flaggedAccount
|
|
|
|
|
|
|
|
const { isOwned } = await associateFun(abuseInstance)
|
|
|
|
|
|
|
|
if (isOwned === false) {
|
2021-06-15 03:17:19 -04:00
|
|
|
sendAbuse(reporterAccount.Actor, abuseInstance, abuseInstance.FlaggedAccount, transaction)
|
2020-07-01 10:05:30 -04:00
|
|
|
}
|
|
|
|
|
2020-07-24 09:05:51 -04:00
|
|
|
const abuseJSON = abuseInstance.toFormattedAdminJSON()
|
2020-07-01 10:05:30 -04:00
|
|
|
auditLogger.create(reporterAccount.Actor.getIdentifier(), new AbuseAuditView(abuseJSON))
|
|
|
|
|
2021-12-09 08:27:32 -05:00
|
|
|
if (!skipNotification) {
|
|
|
|
afterCommitIfTransaction(transaction, () => {
|
|
|
|
Notifier.Instance.notifyOnNewAbuse({
|
|
|
|
abuse: abuseJSON,
|
|
|
|
abuseInstance,
|
|
|
|
reporter: reporterAccount.Actor.getIdentifier()
|
|
|
|
})
|
2021-03-04 10:12:46 -05:00
|
|
|
})
|
2021-12-09 08:27:32 -05:00
|
|
|
}
|
2020-07-01 10:05:30 -04:00
|
|
|
|
|
|
|
logger.info('Abuse report %d created.', abuseInstance.id)
|
|
|
|
|
|
|
|
return abuseJSON
|
2019-07-18 08:28:37 -04:00
|
|
|
}
|