2021-08-27 08:32:44 -04:00
|
|
|
import express from 'express'
|
2020-05-07 08:58:24 -04:00
|
|
|
import { blacklistVideo, unblacklistVideo } from '@server/lib/video-blacklist'
|
2021-12-24 04:14:47 -05:00
|
|
|
import { HttpStatusCode, UserRight, VideoBlacklistCreate } from '@shared/models'
|
2017-12-28 05:16:08 -05:00
|
|
|
import { logger } from '../../../helpers/logger'
|
|
|
|
import { getFormattedObjects } from '../../../helpers/utils'
|
2020-05-07 08:58:24 -04:00
|
|
|
import { sequelizeTypescript } from '../../../initializers/database'
|
2017-05-15 16:22:03 -04:00
|
|
|
import {
|
2018-08-13 10:57:13 -04:00
|
|
|
asyncMiddleware,
|
|
|
|
authenticate,
|
|
|
|
blacklistSortValidator,
|
|
|
|
ensureUserHasRight,
|
2021-06-04 03:16:23 -04:00
|
|
|
openapiOperationDoc,
|
2018-08-13 10:57:13 -04:00
|
|
|
paginationValidator,
|
|
|
|
setBlacklistSort,
|
|
|
|
setDefaultPagination,
|
|
|
|
videosBlacklistAddValidator,
|
2019-08-15 05:53:26 -04:00
|
|
|
videosBlacklistFiltersValidator,
|
2018-08-13 10:57:13 -04:00
|
|
|
videosBlacklistRemoveValidator,
|
2019-08-15 05:53:26 -04:00
|
|
|
videosBlacklistUpdateValidator
|
2017-05-15 16:22:03 -04:00
|
|
|
} from '../../../middlewares'
|
2017-12-12 11:53:50 -05:00
|
|
|
import { VideoBlacklistModel } from '../../../models/video/video-blacklist'
|
2017-05-15 16:22:03 -04:00
|
|
|
|
|
|
|
const blacklistRouter = express.Router()
|
|
|
|
|
2017-10-10 04:02:18 -04:00
|
|
|
blacklistRouter.post('/:videoId/blacklist',
|
2021-06-04 03:16:23 -04:00
|
|
|
openapiOperationDoc({ operationId: 'addVideoBlock' }),
|
2017-05-15 16:22:03 -04:00
|
|
|
authenticate,
|
2017-10-27 10:55:03 -04:00
|
|
|
ensureUserHasRight(UserRight.MANAGE_VIDEO_BLACKLIST),
|
2017-11-27 11:30:46 -05:00
|
|
|
asyncMiddleware(videosBlacklistAddValidator),
|
2020-05-07 08:58:24 -04:00
|
|
|
asyncMiddleware(addVideoToBlacklistController)
|
2017-05-05 10:53:35 -04:00
|
|
|
)
|
|
|
|
|
2017-10-10 04:02:18 -04:00
|
|
|
blacklistRouter.get('/blacklist',
|
2021-06-04 03:16:23 -04:00
|
|
|
openapiOperationDoc({ operationId: 'getVideoBlocks' }),
|
2017-10-10 04:02:18 -04:00
|
|
|
authenticate,
|
2017-10-27 10:55:03 -04:00
|
|
|
ensureUserHasRight(UserRight.MANAGE_VIDEO_BLACKLIST),
|
2017-10-10 04:02:18 -04:00
|
|
|
paginationValidator,
|
|
|
|
blacklistSortValidator,
|
|
|
|
setBlacklistSort,
|
2018-01-18 04:53:54 -05:00
|
|
|
setDefaultPagination,
|
2019-04-02 05:26:47 -04:00
|
|
|
videosBlacklistFiltersValidator,
|
2017-10-25 05:55:06 -04:00
|
|
|
asyncMiddleware(listBlacklist)
|
2017-10-10 04:02:18 -04:00
|
|
|
)
|
|
|
|
|
2018-08-13 10:57:13 -04:00
|
|
|
blacklistRouter.put('/:videoId/blacklist',
|
|
|
|
authenticate,
|
|
|
|
ensureUserHasRight(UserRight.MANAGE_VIDEO_BLACKLIST),
|
|
|
|
asyncMiddleware(videosBlacklistUpdateValidator),
|
|
|
|
asyncMiddleware(updateVideoBlacklistController)
|
|
|
|
)
|
|
|
|
|
2017-10-10 04:02:18 -04:00
|
|
|
blacklistRouter.delete('/:videoId/blacklist',
|
2021-06-04 03:16:23 -04:00
|
|
|
openapiOperationDoc({ operationId: 'delVideoBlock' }),
|
2017-10-10 04:02:18 -04:00
|
|
|
authenticate,
|
2017-10-27 10:55:03 -04:00
|
|
|
ensureUserHasRight(UserRight.MANAGE_VIDEO_BLACKLIST),
|
2017-11-27 11:30:46 -05:00
|
|
|
asyncMiddleware(videosBlacklistRemoveValidator),
|
2017-10-25 05:55:06 -04:00
|
|
|
asyncMiddleware(removeVideoFromBlacklistController)
|
2017-10-10 04:02:18 -04:00
|
|
|
)
|
|
|
|
|
2017-05-05 10:53:35 -04:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2017-05-15 16:22:03 -04:00
|
|
|
export {
|
|
|
|
blacklistRouter
|
|
|
|
}
|
2017-05-05 10:53:35 -04:00
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2020-05-07 08:58:24 -04:00
|
|
|
async function addVideoToBlacklistController (req: express.Request, res: express.Response) {
|
2019-08-15 05:53:26 -04:00
|
|
|
const videoInstance = res.locals.videoAll
|
2018-08-13 10:57:13 -04:00
|
|
|
const body: VideoBlacklistCreate = req.body
|
2017-05-05 10:53:35 -04:00
|
|
|
|
2020-05-07 08:58:24 -04:00
|
|
|
await blacklistVideo(videoInstance, body)
|
2018-12-26 04:36:24 -05:00
|
|
|
|
2019-08-15 05:53:26 -04:00
|
|
|
logger.info('Video %s blacklisted.', videoInstance.uuid)
|
2018-12-26 04:36:24 -05:00
|
|
|
|
2021-05-31 19:36:53 -04:00
|
|
|
return res.type('json').status(HttpStatusCode.NO_CONTENT_204).end()
|
2017-05-05 10:53:35 -04:00
|
|
|
}
|
2017-10-10 04:02:18 -04:00
|
|
|
|
2018-08-13 10:57:13 -04:00
|
|
|
async function updateVideoBlacklistController (req: express.Request, res: express.Response) {
|
2019-03-19 05:35:15 -04:00
|
|
|
const videoBlacklist = res.locals.videoBlacklist
|
2018-08-13 10:57:13 -04:00
|
|
|
|
|
|
|
if (req.body.reason !== undefined) videoBlacklist.reason = req.body.reason
|
|
|
|
|
|
|
|
await sequelizeTypescript.transaction(t => {
|
|
|
|
return videoBlacklist.save({ transaction: t })
|
|
|
|
})
|
|
|
|
|
2021-05-31 19:36:53 -04:00
|
|
|
return res.type('json').status(HttpStatusCode.NO_CONTENT_204).end()
|
2018-08-13 10:57:13 -04:00
|
|
|
}
|
|
|
|
|
2019-07-23 03:48:48 -04:00
|
|
|
async function listBlacklist (req: express.Request, res: express.Response) {
|
2020-04-19 08:11:40 -04:00
|
|
|
const resultList = await VideoBlacklistModel.listForApi({
|
|
|
|
start: req.query.start,
|
|
|
|
count: req.query.count,
|
|
|
|
sort: req.query.sort,
|
|
|
|
search: req.query.search,
|
|
|
|
type: req.query.type
|
|
|
|
})
|
2017-10-25 05:55:06 -04:00
|
|
|
|
2019-07-23 03:48:48 -04:00
|
|
|
return res.json(getFormattedObjects(resultList.data, resultList.total))
|
2017-10-10 04:02:18 -04:00
|
|
|
}
|
|
|
|
|
2019-07-23 03:48:48 -04:00
|
|
|
async function removeVideoFromBlacklistController (req: express.Request, res: express.Response) {
|
2019-03-19 05:35:15 -04:00
|
|
|
const videoBlacklist = res.locals.videoBlacklist
|
2019-08-15 05:53:26 -04:00
|
|
|
const video = res.locals.videoAll
|
2017-10-10 04:02:18 -04:00
|
|
|
|
2020-05-07 08:58:24 -04:00
|
|
|
await unblacklistVideo(videoBlacklist, video)
|
2019-04-02 05:26:47 -04:00
|
|
|
|
2019-08-15 05:53:26 -04:00
|
|
|
logger.info('Video %s removed from blacklist.', video.uuid)
|
2017-10-25 05:55:06 -04:00
|
|
|
|
2021-05-31 19:36:53 -04:00
|
|
|
return res.type('json').status(HttpStatusCode.NO_CONTENT_204).end()
|
2017-10-10 04:02:18 -04:00
|
|
|
}
|