2017-06-05 14:53:49 -05:00
|
|
|
import * as express from 'express'
|
2020-07-01 09:05:30 -05:00
|
|
|
import { AbuseModel } from '@server/models/abuse/abuse'
|
|
|
|
import { getServerActor } from '@server/models/application/application'
|
|
|
|
import { AbuseCreate, UserRight, VideoAbuseCreate } from '../../../../shared'
|
2017-05-15 15:22:03 -05:00
|
|
|
import {
|
2020-07-01 09:05:30 -05:00
|
|
|
abusesSortValidator,
|
2018-06-13 07:27:40 -05:00
|
|
|
asyncMiddleware,
|
|
|
|
asyncRetryTransactionMiddleware,
|
|
|
|
authenticate,
|
|
|
|
ensureUserHasRight,
|
|
|
|
paginationValidator,
|
|
|
|
setDefaultPagination,
|
|
|
|
setDefaultSort,
|
2018-08-10 09:54:01 -05:00
|
|
|
videoAbuseGetValidator,
|
2020-07-01 09:05:30 -05:00
|
|
|
videoAbuseListValidator,
|
2018-06-13 07:27:40 -05:00
|
|
|
videoAbuseReportValidator,
|
2020-07-01 09:05:30 -05:00
|
|
|
videoAbuseUpdateValidator
|
2017-05-15 15:22:03 -05:00
|
|
|
} from '../../../middlewares'
|
2020-07-01 09:05:30 -05:00
|
|
|
import { deleteAbuse, reportAbuse, updateAbuse } from '../abuse'
|
|
|
|
|
|
|
|
// FIXME: deprecated in 2.3. Remove this controller
|
2017-05-15 15:22:03 -05:00
|
|
|
|
|
|
|
const abuseVideoRouter = express.Router()
|
|
|
|
|
|
|
|
abuseVideoRouter.get('/abuse',
|
|
|
|
authenticate,
|
2020-07-01 09:05:30 -05:00
|
|
|
ensureUserHasRight(UserRight.MANAGE_ABUSES),
|
2017-05-15 15:22:03 -05:00
|
|
|
paginationValidator,
|
2020-07-01 09:05:30 -05:00
|
|
|
abusesSortValidator,
|
2018-01-17 03:50:33 -06:00
|
|
|
setDefaultSort,
|
2018-01-18 03:53:54 -06:00
|
|
|
setDefaultPagination,
|
2020-05-06 10:39:07 -05:00
|
|
|
videoAbuseListValidator,
|
2017-10-25 04:55:06 -05:00
|
|
|
asyncMiddleware(listVideoAbuses)
|
2017-05-05 09:53:35 -05:00
|
|
|
)
|
2018-08-10 09:54:01 -05:00
|
|
|
abuseVideoRouter.put('/:videoId/abuse/:id',
|
|
|
|
authenticate,
|
2020-07-01 09:05:30 -05:00
|
|
|
ensureUserHasRight(UserRight.MANAGE_ABUSES),
|
2018-08-10 09:54:01 -05:00
|
|
|
asyncMiddleware(videoAbuseUpdateValidator),
|
|
|
|
asyncRetryTransactionMiddleware(updateVideoAbuse)
|
|
|
|
)
|
|
|
|
abuseVideoRouter.post('/:videoId/abuse',
|
2017-05-15 15:22:03 -05:00
|
|
|
authenticate,
|
2017-11-27 10:30:46 -06:00
|
|
|
asyncMiddleware(videoAbuseReportValidator),
|
2018-06-13 07:27:40 -05:00
|
|
|
asyncRetryTransactionMiddleware(reportVideoAbuse)
|
2017-05-05 09:53:35 -05:00
|
|
|
)
|
2018-08-10 09:54:01 -05:00
|
|
|
abuseVideoRouter.delete('/:videoId/abuse/:id',
|
|
|
|
authenticate,
|
2020-07-01 09:05:30 -05:00
|
|
|
ensureUserHasRight(UserRight.MANAGE_ABUSES),
|
2018-08-10 09:54:01 -05:00
|
|
|
asyncMiddleware(videoAbuseGetValidator),
|
|
|
|
asyncRetryTransactionMiddleware(deleteVideoAbuse)
|
|
|
|
)
|
2017-05-05 09:53:35 -05:00
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2017-05-15 15:22:03 -05:00
|
|
|
export {
|
|
|
|
abuseVideoRouter
|
|
|
|
}
|
2017-05-05 09:53:35 -05:00
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2018-08-10 09:54:01 -05:00
|
|
|
async function listVideoAbuses (req: express.Request, res: express.Response) {
|
2019-08-29 07:31:04 -05:00
|
|
|
const user = res.locals.oauth.token.user
|
|
|
|
const serverActor = await getServerActor()
|
|
|
|
|
2020-07-24 08:05:51 -05:00
|
|
|
const resultList = await AbuseModel.listForAdminApi({
|
2019-08-29 07:31:04 -05:00
|
|
|
start: req.query.start,
|
|
|
|
count: req.query.count,
|
|
|
|
sort: req.query.sort,
|
2020-05-06 10:39:07 -05:00
|
|
|
id: req.query.id,
|
2020-07-01 09:05:30 -05:00
|
|
|
filter: 'video',
|
2020-06-22 06:00:39 -05:00
|
|
|
predefinedReason: req.query.predefinedReason,
|
2020-04-18 03:00:19 -05:00
|
|
|
search: req.query.search,
|
2020-05-06 10:39:07 -05:00
|
|
|
state: req.query.state,
|
|
|
|
videoIs: req.query.videoIs,
|
|
|
|
searchReporter: req.query.searchReporter,
|
|
|
|
searchReportee: req.query.searchReportee,
|
|
|
|
searchVideo: req.query.searchVideo,
|
|
|
|
searchVideoChannel: req.query.searchVideoChannel,
|
2019-08-29 07:31:04 -05:00
|
|
|
serverAccountId: serverActor.Account.id,
|
|
|
|
user
|
|
|
|
})
|
2017-10-25 04:55:06 -05:00
|
|
|
|
2020-07-24 08:05:51 -05:00
|
|
|
return res.json({
|
|
|
|
total: resultList.total,
|
|
|
|
data: resultList.data.map(d => d.toFormattedAdminJSON())
|
|
|
|
})
|
2017-05-05 09:53:35 -05:00
|
|
|
}
|
|
|
|
|
2018-08-10 09:54:01 -05:00
|
|
|
async function updateVideoAbuse (req: express.Request, res: express.Response) {
|
2020-07-01 09:05:30 -05:00
|
|
|
return updateAbuse(req, res)
|
2018-08-10 09:54:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
async function deleteVideoAbuse (req: express.Request, res: express.Response) {
|
2020-07-01 09:05:30 -05:00
|
|
|
return deleteAbuse(req, res)
|
2018-08-10 09:54:01 -05:00
|
|
|
}
|
|
|
|
|
2017-10-25 04:55:06 -05:00
|
|
|
async function reportVideoAbuse (req: express.Request, res: express.Response) {
|
2020-07-01 09:05:30 -05:00
|
|
|
const oldBody = req.body as VideoAbuseCreate
|
2017-10-25 04:55:06 -05:00
|
|
|
|
2020-07-01 09:05:30 -05:00
|
|
|
req.body = {
|
|
|
|
accountId: res.locals.videoAll.VideoChannel.accountId,
|
2018-08-10 09:54:01 -05:00
|
|
|
|
2020-07-01 09:05:30 -05:00
|
|
|
reason: oldBody.reason,
|
|
|
|
predefinedReasons: oldBody.predefinedReasons,
|
2018-06-13 07:27:40 -05:00
|
|
|
|
2020-07-01 09:05:30 -05:00
|
|
|
video: {
|
|
|
|
id: res.locals.videoAll.id,
|
|
|
|
startAt: oldBody.startAt,
|
|
|
|
endAt: oldBody.endAt
|
|
|
|
}
|
|
|
|
} as AbuseCreate
|
2018-09-20 03:13:13 -05:00
|
|
|
|
2020-07-01 09:05:30 -05:00
|
|
|
return reportAbuse(req, res)
|
2017-05-05 09:53:35 -05:00
|
|
|
}
|