aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/api')
-rw-r--r--server/controllers/api/users/my-history.ts2
-rw-r--r--server/controllers/api/videos/abuse.ts2
-rw-r--r--server/controllers/api/videos/blacklist.ts60
-rw-r--r--server/controllers/api/videos/comment.ts2
-rw-r--r--server/controllers/api/videos/ownership.ts2
5 files changed, 14 insertions, 54 deletions
diff --git a/server/controllers/api/users/my-history.ts b/server/controllers/api/users/my-history.ts
index 4da1f3496..77a15e5fc 100644
--- a/server/controllers/api/users/my-history.ts
+++ b/server/controllers/api/users/my-history.ts
@@ -9,7 +9,7 @@ import {
9} from '../../../middlewares' 9} from '../../../middlewares'
10import { getFormattedObjects } from '../../../helpers/utils' 10import { getFormattedObjects } from '../../../helpers/utils'
11import { UserVideoHistoryModel } from '../../../models/account/user-video-history' 11import { UserVideoHistoryModel } from '../../../models/account/user-video-history'
12import { sequelizeTypescript } from '../../../initializers' 12import { sequelizeTypescript } from '../../../initializers/database'
13 13
14const myVideosHistoryRouter = express.Router() 14const myVideosHistoryRouter = express.Router()
15 15
diff --git a/server/controllers/api/videos/abuse.ts b/server/controllers/api/videos/abuse.ts
index 3fe7f7e51..bce50aefb 100644
--- a/server/controllers/api/videos/abuse.ts
+++ b/server/controllers/api/videos/abuse.ts
@@ -2,7 +2,7 @@ import * as express from 'express'
2import { UserRight, VideoAbuseCreate, VideoAbuseState } from '../../../../shared' 2import { UserRight, VideoAbuseCreate, VideoAbuseState } from '../../../../shared'
3import { logger } from '../../../helpers/logger' 3import { logger } from '../../../helpers/logger'
4import { getFormattedObjects } from '../../../helpers/utils' 4import { getFormattedObjects } from '../../../helpers/utils'
5import { sequelizeTypescript } from '../../../initializers' 5import { sequelizeTypescript } from '../../../initializers/database'
6import { 6import {
7 asyncMiddleware, 7 asyncMiddleware,
8 asyncRetryTransactionMiddleware, 8 asyncRetryTransactionMiddleware,
diff --git a/server/controllers/api/videos/blacklist.ts b/server/controllers/api/videos/blacklist.ts
index abd09387c..3b25ceea2 100644
--- a/server/controllers/api/videos/blacklist.ts
+++ b/server/controllers/api/videos/blacklist.ts
@@ -1,7 +1,9 @@
1import * as express from 'express' 1import * as express from 'express'
2import { UserRight, VideoBlacklistCreate, VideoBlacklistType } from '../../../../shared' 2import { blacklistVideo, unblacklistVideo } from '@server/lib/video-blacklist'
3import { UserRight, VideoBlacklistCreate } from '../../../../shared'
3import { logger } from '../../../helpers/logger' 4import { logger } from '../../../helpers/logger'
4import { getFormattedObjects } from '../../../helpers/utils' 5import { getFormattedObjects } from '../../../helpers/utils'
6import { sequelizeTypescript } from '../../../initializers/database'
5import { 7import {
6 asyncMiddleware, 8 asyncMiddleware,
7 authenticate, 9 authenticate,
@@ -16,11 +18,6 @@ import {
16 videosBlacklistUpdateValidator 18 videosBlacklistUpdateValidator
17} from '../../../middlewares' 19} from '../../../middlewares'
18import { VideoBlacklistModel } from '../../../models/video/video-blacklist' 20import { VideoBlacklistModel } from '../../../models/video/video-blacklist'
19import { sequelizeTypescript } from '../../../initializers'
20import { Notifier } from '../../../lib/notifier'
21import { sendDeleteVideo } from '../../../lib/activitypub/send'
22import { federateVideoIfNeeded } from '../../../lib/activitypub/videos'
23import { MVideoBlacklistVideo } from '@server/typings/models'
24 21
25const blacklistRouter = express.Router() 22const blacklistRouter = express.Router()
26 23
@@ -28,7 +25,7 @@ blacklistRouter.post('/:videoId/blacklist',
28 authenticate, 25 authenticate,
29 ensureUserHasRight(UserRight.MANAGE_VIDEO_BLACKLIST), 26 ensureUserHasRight(UserRight.MANAGE_VIDEO_BLACKLIST),
30 asyncMiddleware(videosBlacklistAddValidator), 27 asyncMiddleware(videosBlacklistAddValidator),
31 asyncMiddleware(addVideoToBlacklist) 28 asyncMiddleware(addVideoToBlacklistController)
32) 29)
33 30
34blacklistRouter.get('/blacklist', 31blacklistRouter.get('/blacklist',
@@ -64,29 +61,15 @@ export {
64 61
65// --------------------------------------------------------------------------- 62// ---------------------------------------------------------------------------
66 63
67async function addVideoToBlacklist (req: express.Request, res: express.Response) { 64async function addVideoToBlacklistController (req: express.Request, res: express.Response) {
68 const videoInstance = res.locals.videoAll 65 const videoInstance = res.locals.videoAll
69 const body: VideoBlacklistCreate = req.body 66 const body: VideoBlacklistCreate = req.body
70 67
71 const toCreate = { 68 await blacklistVideo(videoInstance, body)
72 videoId: videoInstance.id,
73 unfederated: body.unfederate === true,
74 reason: body.reason,
75 type: VideoBlacklistType.MANUAL
76 }
77
78 const blacklist: MVideoBlacklistVideo = await VideoBlacklistModel.create(toCreate)
79 blacklist.Video = videoInstance
80
81 if (body.unfederate === true) {
82 await sendDeleteVideo(videoInstance, undefined)
83 }
84
85 Notifier.Instance.notifyOnVideoBlacklist(blacklist)
86 69
87 logger.info('Video %s blacklisted.', videoInstance.uuid) 70 logger.info('Video %s blacklisted.', videoInstance.uuid)
88 71
89 return res.type('json').status(204).end() 72 return res.type('json').sendStatus(204)
90} 73}
91 74
92async function updateVideoBlacklistController (req: express.Request, res: express.Response) { 75async function updateVideoBlacklistController (req: express.Request, res: express.Response) {
@@ -98,7 +81,7 @@ async function updateVideoBlacklistController (req: express.Request, res: expres
98 return videoBlacklist.save({ transaction: t }) 81 return videoBlacklist.save({ transaction: t })
99 }) 82 })
100 83
101 return res.type('json').status(204).end() 84 return res.type('json').sendStatus(204)
102} 85}
103 86
104async function listBlacklist (req: express.Request, res: express.Response) { 87async function listBlacklist (req: express.Request, res: express.Response) {
@@ -117,32 +100,9 @@ async function removeVideoFromBlacklistController (req: express.Request, res: ex
117 const videoBlacklist = res.locals.videoBlacklist 100 const videoBlacklist = res.locals.videoBlacklist
118 const video = res.locals.videoAll 101 const video = res.locals.videoAll
119 102
120 const videoBlacklistType = await sequelizeTypescript.transaction(async t => { 103 await unblacklistVideo(videoBlacklist, video)
121 const unfederated = videoBlacklist.unfederated
122 const videoBlacklistType = videoBlacklist.type
123
124 await videoBlacklist.destroy({ transaction: t })
125 video.VideoBlacklist = undefined
126
127 // Re federate the video
128 if (unfederated === true) {
129 await federateVideoIfNeeded(video, true, t)
130 }
131
132 return videoBlacklistType
133 })
134
135 Notifier.Instance.notifyOnVideoUnblacklist(video)
136
137 if (videoBlacklistType === VideoBlacklistType.AUTO_BEFORE_PUBLISHED) {
138 Notifier.Instance.notifyOnVideoPublishedAfterRemovedFromAutoBlacklist(video)
139
140 // Delete on object so new video notifications will send
141 delete video.VideoBlacklist
142 Notifier.Instance.notifyOnNewVideoIfNeeded(video)
143 }
144 104
145 logger.info('Video %s removed from blacklist.', video.uuid) 105 logger.info('Video %s removed from blacklist.', video.uuid)
146 106
147 return res.type('json').status(204).end() 107 return res.type('json').sendStatus(204)
148} 108}
diff --git a/server/controllers/api/videos/comment.ts b/server/controllers/api/videos/comment.ts
index 5f3fed5c0..5070bb3c0 100644
--- a/server/controllers/api/videos/comment.ts
+++ b/server/controllers/api/videos/comment.ts
@@ -4,7 +4,7 @@ import { ResultList } from '../../../../shared/models'
4import { VideoCommentCreate } from '../../../../shared/models/videos/video-comment.model' 4import { VideoCommentCreate } from '../../../../shared/models/videos/video-comment.model'
5import { logger } from '../../../helpers/logger' 5import { logger } from '../../../helpers/logger'
6import { getFormattedObjects } from '../../../helpers/utils' 6import { getFormattedObjects } from '../../../helpers/utils'
7import { sequelizeTypescript } from '../../../initializers' 7import { sequelizeTypescript } from '../../../initializers/database'
8import { buildFormattedCommentTree, createVideoComment, markCommentAsDeleted } from '../../../lib/video-comment' 8import { buildFormattedCommentTree, createVideoComment, markCommentAsDeleted } from '../../../lib/video-comment'
9import { 9import {
10 asyncMiddleware, 10 asyncMiddleware,
diff --git a/server/controllers/api/videos/ownership.ts b/server/controllers/api/videos/ownership.ts
index 190036f85..540a49010 100644
--- a/server/controllers/api/videos/ownership.ts
+++ b/server/controllers/api/videos/ownership.ts
@@ -1,6 +1,6 @@
1import * as express from 'express' 1import * as express from 'express'
2import { logger } from '../../../helpers/logger' 2import { logger } from '../../../helpers/logger'
3import { sequelizeTypescript } from '../../../initializers' 3import { sequelizeTypescript } from '../../../initializers/database'
4import { 4import {
5 asyncMiddleware, 5 asyncMiddleware,
6 asyncRetryTransactionMiddleware, 6 asyncRetryTransactionMiddleware,