import * as express from 'express'
-
-import { database as db } from '../../../initializers/database'
-import * as friends from '../../../lib/friends'
-import {
- logger,
- getFormattedObjects,
- retryTransactionWrapper
-} from '../../../helpers'
+import { UserRight, VideoAbuseCreate } from '../../../../shared'
+import { retryTransactionWrapper } from '../../../helpers/database-utils'
+import { logger } from '../../../helpers/logger'
+import { getFormattedObjects } from '../../../helpers/utils'
+import { sequelizeTypescript } from '../../../initializers'
+import { sendVideoAbuse } from '../../../lib/activitypub/send'
import {
- authenticate,
- ensureUserHasRight,
- paginationValidator,
- videoAbuseReportValidator,
- videoAbusesSortValidator,
- setVideoAbusesSort,
- setPagination,
- asyncMiddleware
+ asyncMiddleware, authenticate, ensureUserHasRight, paginationValidator, setDefaultSort, setDefaultPagination, videoAbuseReportValidator,
+ videoAbusesSortValidator
} from '../../../middlewares'
-import { VideoInstance } from '../../../models'
-import { VideoAbuseCreate, UserRight } from '../../../../shared'
+import { AccountModel } from '../../../models/account/account'
+import { VideoModel } from '../../../models/video/video'
+import { VideoAbuseModel } from '../../../models/video/video-abuse'
const abuseVideoRouter = express.Router()
ensureUserHasRight(UserRight.MANAGE_VIDEO_ABUSES),
paginationValidator,
videoAbusesSortValidator,
- setVideoAbusesSort,
- setPagination,
+ setDefaultSort,
+ setDefaultPagination,
asyncMiddleware(listVideoAbuses)
)
abuseVideoRouter.post('/:id/abuse',
authenticate,
- videoAbuseReportValidator,
+ asyncMiddleware(videoAbuseReportValidator),
asyncMiddleware(reportVideoAbuseRetryWrapper)
)
// ---------------------------------------------------------------------------
async function listVideoAbuses (req: express.Request, res: express.Response, next: express.NextFunction) {
- const resultList = await db.VideoAbuse.listForApi(req.query.start, req.query.count, req.query.sort)
+ const resultList = await VideoAbuseModel.listForApi(req.query.start, req.query.count, req.query.sort)
return res.json(getFormattedObjects(resultList.data, resultList.total))
}
}
async function reportVideoAbuse (req: express.Request, res: express.Response) {
- const videoInstance = res.locals.video as VideoInstance
- const reporterUsername = res.locals.oauth.token.User.username
+ const videoInstance = res.locals.video as VideoModel
+ const reporterAccount = res.locals.oauth.token.User.Account as AccountModel
const body: VideoAbuseCreate = req.body
const abuseToCreate = {
- reporterUsername,
+ reporterAccountId: reporterAccount.id,
reason: body.reason,
- videoId: videoInstance.id,
- reporterPodId: null // This is our pod that reported this abuse
+ videoId: videoInstance.id
}
- await db.sequelize.transaction(async t => {
- const abuse = await db.VideoAbuse.create(abuseToCreate, { transaction: t })
- // We send the information to the destination pod
- if (videoInstance.isOwned() === false) {
- const reportData = {
- reporterUsername,
- reportReason: abuse.reason,
- videoUUID: videoInstance.uuid
- }
+ await sequelizeTypescript.transaction(async t => {
+ const videoAbuseInstance = await VideoAbuseModel.create(abuseToCreate, { transaction: t })
+ videoAbuseInstance.Video = videoInstance
- await friends.reportAbuseVideoToFriend(reportData, videoInstance, t)
+ // We send the video abuse to the origin server
+ if (videoInstance.isOwned() === false) {
+ await sendVideoAbuse(reporterAccount.Actor, videoAbuseInstance, videoInstance, t)
}
})