aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-01-10 15:39:51 +0100
committerChocobozzz <me@florianbigard.com>2019-01-10 15:39:51 +0100
commit5abb9fbbd12e7097e348d6a38622d364b1fa47ed (patch)
tree8ef483ad15bd76c75876e0e2f34fd3c99b786103 /server/controllers/api
parent93f85e90ffa27453e2c909406b62bef65963b8ad (diff)
downloadPeerTube-5abb9fbbd12e7097e348d6a38622d364b1fa47ed.tar.gz
PeerTube-5abb9fbbd12e7097e348d6a38622d364b1fa47ed.tar.zst
PeerTube-5abb9fbbd12e7097e348d6a38622d364b1fa47ed.zip
Add ability to unfederate a local video (on blacklist)
Diffstat (limited to 'server/controllers/api')
-rw-r--r--server/controllers/api/videos/blacklist.ts17
-rw-r--r--server/controllers/api/videos/index.ts6
2 files changed, 20 insertions, 3 deletions
diff --git a/server/controllers/api/videos/blacklist.ts b/server/controllers/api/videos/blacklist.ts
index 9ef08812b..43b0516e7 100644
--- a/server/controllers/api/videos/blacklist.ts
+++ b/server/controllers/api/videos/blacklist.ts
@@ -18,6 +18,8 @@ import { VideoBlacklistModel } from '../../../models/video/video-blacklist'
18import { sequelizeTypescript } from '../../../initializers' 18import { sequelizeTypescript } from '../../../initializers'
19import { Notifier } from '../../../lib/notifier' 19import { Notifier } from '../../../lib/notifier'
20import { VideoModel } from '../../../models/video/video' 20import { VideoModel } from '../../../models/video/video'
21import { sendCreateVideo, sendDeleteVideo, sendUpdateVideo } from '../../../lib/activitypub/send'
22import { federateVideoIfNeeded } from '../../../lib/activitypub'
21 23
22const blacklistRouter = express.Router() 24const blacklistRouter = express.Router()
23 25
@@ -66,12 +68,17 @@ async function addVideoToBlacklist (req: express.Request, res: express.Response)
66 68
67 const toCreate = { 69 const toCreate = {
68 videoId: videoInstance.id, 70 videoId: videoInstance.id,
71 unfederated: body.unfederate === true,
69 reason: body.reason 72 reason: body.reason
70 } 73 }
71 74
72 const blacklist = await VideoBlacklistModel.create(toCreate) 75 const blacklist = await VideoBlacklistModel.create(toCreate)
73 blacklist.Video = videoInstance 76 blacklist.Video = videoInstance
74 77
78 if (body.unfederate === true) {
79 await sendDeleteVideo(videoInstance, undefined)
80 }
81
75 Notifier.Instance.notifyOnVideoBlacklist(blacklist) 82 Notifier.Instance.notifyOnVideoBlacklist(blacklist)
76 83
77 logger.info('Video %s blacklisted.', res.locals.video.uuid) 84 logger.info('Video %s blacklisted.', res.locals.video.uuid)
@@ -101,8 +108,14 @@ async function removeVideoFromBlacklistController (req: express.Request, res: ex
101 const videoBlacklist = res.locals.videoBlacklist as VideoBlacklistModel 108 const videoBlacklist = res.locals.videoBlacklist as VideoBlacklistModel
102 const video: VideoModel = res.locals.video 109 const video: VideoModel = res.locals.video
103 110
104 await sequelizeTypescript.transaction(t => { 111 await sequelizeTypescript.transaction(async t => {
105 return videoBlacklist.destroy({ transaction: t }) 112 const unfederated = videoBlacklist.unfederated
113 await videoBlacklist.destroy({ transaction: t })
114
115 // Re federate the video
116 if (unfederated === true) {
117 await federateVideoIfNeeded(video, true, t)
118 }
106 }) 119 })
107 120
108 Notifier.Instance.notifyOnVideoUnblacklist(video) 121 Notifier.Instance.notifyOnVideoUnblacklist(video)
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts
index 33521a8c1..28ac26598 100644
--- a/server/controllers/api/videos/index.ts
+++ b/server/controllers/api/videos/index.ts
@@ -364,7 +364,11 @@ async function updateVideo (req: express.Request, res: express.Response) {
364 } 364 }
365 365
366 const isNewVideo = wasPrivateVideo && videoInstanceUpdated.privacy !== VideoPrivacy.PRIVATE 366 const isNewVideo = wasPrivateVideo && videoInstanceUpdated.privacy !== VideoPrivacy.PRIVATE
367 await federateVideoIfNeeded(videoInstanceUpdated, isNewVideo, t) 367
368 // Don't send update if the video was unfederated
369 if (!videoInstanceUpdated.VideoBlacklist || videoInstanceUpdated.VideoBlacklist.unfederated === false) {
370 await federateVideoIfNeeded(videoInstanceUpdated, isNewVideo, t)
371 }
368 372
369 auditLogger.update( 373 auditLogger.update(
370 getAuditIdFromRes(res), 374 getAuditIdFromRes(res),