1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-06 03:50:26 +02:00

Add blacklist reason field

This commit is contained in:
Chocobozzz 2018-08-13 16:57:13 +02:00
parent efc9e8450a
commit 26b7305a23
No known key found for this signature in database
GPG key ID: 583A612D890159BE
35 changed files with 689 additions and 163 deletions

View file

@ -201,14 +201,14 @@ async function getUserVideos (req: express.Request, res: express.Response, next:
user.Account.id,
req.query.start as number,
req.query.count as number,
req.query.sort as VideoSortField,
false // Display my NSFW videos
req.query.sort as VideoSortField
)
const additionalAttributes = {
waitTranscoding: true,
state: true,
scheduledUpdate: true
scheduledUpdate: true,
blacklistInfo: true
}
return res.json(getFormattedObjects(resultList.data, resultList.total, { additionalAttributes }))
}

View file

@ -1,12 +1,21 @@
import * as express from 'express'
import { BlacklistedVideo, UserRight } from '../../../../shared'
import { BlacklistedVideo, UserRight, VideoBlacklistCreate } from '../../../../shared'
import { logger } from '../../../helpers/logger'
import { getFormattedObjects } from '../../../helpers/utils'
import {
asyncMiddleware, authenticate, blacklistSortValidator, ensureUserHasRight, paginationValidator, setBlacklistSort, setDefaultPagination,
videosBlacklistAddValidator, videosBlacklistRemoveValidator
asyncMiddleware,
authenticate,
blacklistSortValidator,
ensureUserHasRight,
paginationValidator,
setBlacklistSort,
setDefaultPagination,
videosBlacklistAddValidator,
videosBlacklistRemoveValidator,
videosBlacklistUpdateValidator
} from '../../../middlewares'
import { VideoBlacklistModel } from '../../../models/video/video-blacklist'
import { sequelizeTypescript } from '../../../initializers'
const blacklistRouter = express.Router()
@ -27,6 +36,13 @@ blacklistRouter.get('/blacklist',
asyncMiddleware(listBlacklist)
)
blacklistRouter.put('/:videoId/blacklist',
authenticate,
ensureUserHasRight(UserRight.MANAGE_VIDEO_BLACKLIST),
asyncMiddleware(videosBlacklistUpdateValidator),
asyncMiddleware(updateVideoBlacklistController)
)
blacklistRouter.delete('/:videoId/blacklist',
authenticate,
ensureUserHasRight(UserRight.MANAGE_VIDEO_BLACKLIST),
@ -42,17 +58,32 @@ export {
// ---------------------------------------------------------------------------
async function addVideoToBlacklist (req: express.Request, res: express.Response, next: express.NextFunction) {
async function addVideoToBlacklist (req: express.Request, res: express.Response) {
const videoInstance = res.locals.video
const body: VideoBlacklistCreate = req.body
const toCreate = {
videoId: videoInstance.id
videoId: videoInstance.id,
reason: body.reason
}
await VideoBlacklistModel.create(toCreate)
return res.type('json').status(204).end()
}
async function updateVideoBlacklistController (req: express.Request, res: express.Response) {
const videoBlacklist = res.locals.videoBlacklist as VideoBlacklistModel
logger.info(videoBlacklist)
if (req.body.reason !== undefined) videoBlacklist.reason = req.body.reason
await sequelizeTypescript.transaction(t => {
return videoBlacklist.save({ transaction: t })
})
return res.type('json').status(204).end()
}
async function listBlacklist (req: express.Request, res: express.Response, next: express.NextFunction) {
const resultList = await VideoBlacklistModel.listForApi(req.query.start, req.query.count, req.query.sort)
@ -60,16 +91,13 @@ async function listBlacklist (req: express.Request, res: express.Response, next:
}
async function removeVideoFromBlacklistController (req: express.Request, res: express.Response, next: express.NextFunction) {
const blacklistedVideo = res.locals.blacklistedVideo as VideoBlacklistModel
const videoBlacklist = res.locals.videoBlacklist as VideoBlacklistModel
try {
await blacklistedVideo.destroy()
await sequelizeTypescript.transaction(t => {
return videoBlacklist.destroy({ transaction: t })
})
logger.info('Video %s removed from blacklist.', res.locals.video.uuid)
logger.info('Video %s removed from blacklist.', res.locals.video.uuid)
return res.sendStatus(204)
} catch (err) {
logger.error('Some error while removing video %s from blacklist.', res.locals.video.uuid, { err })
throw err
}
return res.type('json').status(204).end()
}