X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fcontrollers%2Fapi%2Fvideos%2Fblacklist.ts;h=27dcfb76112010428f05ac70bd249f5096e849b7;hb=7ccddd7b5250bd25a917a6e77e58b87b9484a2a4;hp=b01296200c96050a05a441d2dc7e88f31a377626;hpb=418d092afa81e2c8fe8ac6838fc4b5eb0af6a782;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/controllers/api/videos/blacklist.ts b/server/controllers/api/videos/blacklist.ts index b01296200..27dcfb761 100644 --- a/server/controllers/api/videos/blacklist.ts +++ b/server/controllers/api/videos/blacklist.ts @@ -1,5 +1,5 @@ import * as express from 'express' -import { UserRight, VideoBlacklist, VideoBlacklistCreate } from '../../../../shared' +import { VideoBlacklist, UserRight, VideoBlacklistCreate, VideoBlacklistType } from '../../../../shared' import { logger } from '../../../helpers/logger' import { getFormattedObjects } from '../../../helpers/utils' import { @@ -12,12 +12,12 @@ import { setDefaultPagination, videosBlacklistAddValidator, videosBlacklistRemoveValidator, - videosBlacklistUpdateValidator + videosBlacklistUpdateValidator, + videosBlacklistFiltersValidator } from '../../../middlewares' import { VideoBlacklistModel } from '../../../models/video/video-blacklist' import { sequelizeTypescript } from '../../../initializers' import { Notifier } from '../../../lib/notifier' -import { VideoModel } from '../../../models/video/video' import { sendDeleteVideo } from '../../../lib/activitypub/send' import { federateVideoIfNeeded } from '../../../lib/activitypub' @@ -37,6 +37,7 @@ blacklistRouter.get('/blacklist', blacklistSortValidator, setBlacklistSort, setDefaultPagination, + videosBlacklistFiltersValidator, asyncMiddleware(listBlacklist) ) @@ -69,7 +70,8 @@ async function addVideoToBlacklist (req: express.Request, res: express.Response) const toCreate = { videoId: videoInstance.id, unfederated: body.unfederate === true, - reason: body.reason + reason: body.reason, + type: VideoBlacklistType.MANUAL } const blacklist = await VideoBlacklistModel.create(toCreate) @@ -87,7 +89,7 @@ async function addVideoToBlacklist (req: express.Request, res: express.Response) } async function updateVideoBlacklistController (req: express.Request, res: express.Response) { - const videoBlacklist = res.locals.videoBlacklist as VideoBlacklistModel + const videoBlacklist = res.locals.videoBlacklist if (req.body.reason !== undefined) videoBlacklist.reason = req.body.reason @@ -99,27 +101,39 @@ async function updateVideoBlacklistController (req: express.Request, res: expres } 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) + const resultList = await VideoBlacklistModel.listForApi(req.query.start, req.query.count, req.query.sort, req.query.type) return res.json(getFormattedObjects(resultList.data, resultList.total)) } async function removeVideoFromBlacklistController (req: express.Request, res: express.Response, next: express.NextFunction) { - const videoBlacklist = res.locals.videoBlacklist as VideoBlacklistModel - const video: VideoModel = res.locals.video + const videoBlacklist = res.locals.videoBlacklist + const video = res.locals.video - await sequelizeTypescript.transaction(async t => { + const videoBlacklistType = await sequelizeTypescript.transaction(async t => { const unfederated = videoBlacklist.unfederated + const videoBlacklistType = videoBlacklist.type + await videoBlacklist.destroy({ transaction: t }) // Re federate the video if (unfederated === true) { await federateVideoIfNeeded(video, true, t) } + + return videoBlacklistType }) Notifier.Instance.notifyOnVideoUnblacklist(video) + if (videoBlacklistType === VideoBlacklistType.AUTO_BEFORE_PUBLISHED) { + Notifier.Instance.notifyOnVideoPublishedAfterRemovedFromAutoBlacklist(video) + + // Delete on object so new video notifications will send + delete video.VideoBlacklist + Notifier.Instance.notifyOnNewVideo(video) + } + logger.info('Video %s removed from blacklist.', res.locals.video.uuid) return res.type('json').status(204).end()