diff options
Diffstat (limited to 'server/controllers')
-rw-r--r-- | server/controllers/activitypub/client.ts | 2 | ||||
-rw-r--r-- | server/controllers/api/bulk.ts | 41 | ||||
-rw-r--r-- | server/controllers/api/config.ts | 13 | ||||
-rw-r--r-- | server/controllers/api/index.ts | 20 | ||||
-rw-r--r-- | server/controllers/api/videos/comment.ts | 35 |
5 files changed, 76 insertions, 35 deletions
diff --git a/server/controllers/activitypub/client.ts b/server/controllers/activitypub/client.ts index f94abf808..e48641836 100644 --- a/server/controllers/activitypub/client.ts +++ b/server/controllers/activitypub/client.ts | |||
@@ -285,7 +285,7 @@ async function videoCommentsController (req: express.Request, res: express.Respo | |||
285 | const video = res.locals.onlyImmutableVideo | 285 | const video = res.locals.onlyImmutableVideo |
286 | 286 | ||
287 | const handler = async (start: number, count: number) => { | 287 | const handler = async (start: number, count: number) => { |
288 | const result = await VideoCommentModel.listAndCountByVideoId(video.id, start, count) | 288 | const result = await VideoCommentModel.listAndCountByVideoForAP(video, start, count) |
289 | return { | 289 | return { |
290 | total: result.count, | 290 | total: result.count, |
291 | data: result.rows.map(r => r.url) | 291 | data: result.rows.map(r => r.url) |
diff --git a/server/controllers/api/bulk.ts b/server/controllers/api/bulk.ts new file mode 100644 index 000000000..1fe139c92 --- /dev/null +++ b/server/controllers/api/bulk.ts | |||
@@ -0,0 +1,41 @@ | |||
1 | import * as express from 'express' | ||
2 | import { asyncMiddleware, authenticate } from '../../middlewares' | ||
3 | import { bulkRemoveCommentsOfValidator } from '@server/middlewares/validators/bulk' | ||
4 | import { VideoCommentModel } from '@server/models/video/video-comment' | ||
5 | import { BulkRemoveCommentsOfBody } from '@shared/models/bulk/bulk-remove-comments-of-body.model' | ||
6 | import { removeComment } from '@server/lib/video-comment' | ||
7 | |||
8 | const bulkRouter = express.Router() | ||
9 | |||
10 | bulkRouter.post('/remove-comments-of', | ||
11 | authenticate, | ||
12 | asyncMiddleware(bulkRemoveCommentsOfValidator), | ||
13 | asyncMiddleware(bulkRemoveCommentsOf) | ||
14 | ) | ||
15 | |||
16 | // --------------------------------------------------------------------------- | ||
17 | |||
18 | export { | ||
19 | bulkRouter | ||
20 | } | ||
21 | |||
22 | // --------------------------------------------------------------------------- | ||
23 | |||
24 | async function bulkRemoveCommentsOf (req: express.Request, res: express.Response) { | ||
25 | const account = res.locals.account | ||
26 | const body = req.body as BulkRemoveCommentsOfBody | ||
27 | const user = res.locals.oauth.token.User | ||
28 | |||
29 | const filter = body.scope === 'my-videos' | ||
30 | ? { onVideosOfAccount: user.Account } | ||
31 | : {} | ||
32 | |||
33 | const comments = await VideoCommentModel.listForBulkDelete(account, filter) | ||
34 | |||
35 | // Don't wait result | ||
36 | res.sendStatus(204) | ||
37 | |||
38 | for (const comment of comments) { | ||
39 | await removeComment(comment) | ||
40 | } | ||
41 | } | ||
diff --git a/server/controllers/api/config.ts b/server/controllers/api/config.ts index edcb0b99e..41e5027b9 100644 --- a/server/controllers/api/config.ts +++ b/server/controllers/api/config.ts | |||
@@ -172,6 +172,13 @@ async function getConfig (req: express.Request, res: express.Response) { | |||
172 | indexUrl: CONFIG.FOLLOWINGS.INSTANCE.AUTO_FOLLOW_INDEX.INDEX_URL | 172 | indexUrl: CONFIG.FOLLOWINGS.INSTANCE.AUTO_FOLLOW_INDEX.INDEX_URL |
173 | } | 173 | } |
174 | } | 174 | } |
175 | }, | ||
176 | |||
177 | broadcastMessage: { | ||
178 | enabled: CONFIG.BROADCAST_MESSAGE.ENABLED, | ||
179 | message: CONFIG.BROADCAST_MESSAGE.MESSAGE, | ||
180 | level: CONFIG.BROADCAST_MESSAGE.LEVEL, | ||
181 | dismissable: CONFIG.BROADCAST_MESSAGE.DISMISSABLE | ||
175 | } | 182 | } |
176 | } | 183 | } |
177 | 184 | ||
@@ -432,6 +439,12 @@ function customConfig (): CustomConfig { | |||
432 | indexUrl: CONFIG.FOLLOWINGS.INSTANCE.AUTO_FOLLOW_INDEX.INDEX_URL | 439 | indexUrl: CONFIG.FOLLOWINGS.INSTANCE.AUTO_FOLLOW_INDEX.INDEX_URL |
433 | } | 440 | } |
434 | } | 441 | } |
442 | }, | ||
443 | broadcastMessage: { | ||
444 | enabled: CONFIG.BROADCAST_MESSAGE.ENABLED, | ||
445 | message: CONFIG.BROADCAST_MESSAGE.MESSAGE, | ||
446 | level: CONFIG.BROADCAST_MESSAGE.LEVEL, | ||
447 | dismissable: CONFIG.BROADCAST_MESSAGE.DISMISSABLE | ||
435 | } | 448 | } |
436 | } | 449 | } |
437 | } | 450 | } |
diff --git a/server/controllers/api/index.ts b/server/controllers/api/index.ts index 7bec6c527..c334a26b4 100644 --- a/server/controllers/api/index.ts +++ b/server/controllers/api/index.ts | |||
@@ -1,20 +1,21 @@ | |||
1 | import * as cors from 'cors' | ||
1 | import * as express from 'express' | 2 | import * as express from 'express' |
3 | import * as RateLimit from 'express-rate-limit' | ||
4 | import { badRequest } from '../../helpers/express-utils' | ||
5 | import { CONFIG } from '../../initializers/config' | ||
6 | import { accountsRouter } from './accounts' | ||
7 | import { bulkRouter } from './bulk' | ||
2 | import { configRouter } from './config' | 8 | import { configRouter } from './config' |
3 | import { jobsRouter } from './jobs' | 9 | import { jobsRouter } from './jobs' |
4 | import { oauthClientsRouter } from './oauth-clients' | 10 | import { oauthClientsRouter } from './oauth-clients' |
11 | import { overviewsRouter } from './overviews' | ||
12 | import { pluginRouter } from './plugins' | ||
13 | import { searchRouter } from './search' | ||
5 | import { serverRouter } from './server' | 14 | import { serverRouter } from './server' |
6 | import { usersRouter } from './users' | 15 | import { usersRouter } from './users' |
7 | import { accountsRouter } from './accounts' | ||
8 | import { videosRouter } from './videos' | ||
9 | import { badRequest } from '../../helpers/express-utils' | ||
10 | import { videoChannelRouter } from './video-channel' | 16 | import { videoChannelRouter } from './video-channel' |
11 | import * as cors from 'cors' | ||
12 | import { searchRouter } from './search' | ||
13 | import { overviewsRouter } from './overviews' | ||
14 | import { videoPlaylistRouter } from './video-playlist' | 17 | import { videoPlaylistRouter } from './video-playlist' |
15 | import { CONFIG } from '../../initializers/config' | 18 | import { videosRouter } from './videos' |
16 | import { pluginRouter } from './plugins' | ||
17 | import * as RateLimit from 'express-rate-limit' | ||
18 | 19 | ||
19 | const apiRouter = express.Router() | 20 | const apiRouter = express.Router() |
20 | 21 | ||
@@ -31,6 +32,7 @@ const apiRateLimiter = RateLimit({ | |||
31 | apiRouter.use(apiRateLimiter) | 32 | apiRouter.use(apiRateLimiter) |
32 | 33 | ||
33 | apiRouter.use('/server', serverRouter) | 34 | apiRouter.use('/server', serverRouter) |
35 | apiRouter.use('/bulk', bulkRouter) | ||
34 | apiRouter.use('/oauth-clients', oauthClientsRouter) | 36 | apiRouter.use('/oauth-clients', oauthClientsRouter) |
35 | apiRouter.use('/config', configRouter) | 37 | apiRouter.use('/config', configRouter) |
36 | apiRouter.use('/users', usersRouter) | 38 | apiRouter.use('/users', usersRouter) |
diff --git a/server/controllers/api/videos/comment.ts b/server/controllers/api/videos/comment.ts index 5070bb3c0..45ff969d9 100644 --- a/server/controllers/api/videos/comment.ts +++ b/server/controllers/api/videos/comment.ts | |||
@@ -1,11 +1,12 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { cloneDeep } from 'lodash' | ||
3 | import { ResultList } from '../../../../shared/models' | 2 | import { ResultList } from '../../../../shared/models' |
4 | import { VideoCommentCreate } from '../../../../shared/models/videos/video-comment.model' | 3 | import { VideoCommentCreate } from '../../../../shared/models/videos/video-comment.model' |
5 | import { logger } from '../../../helpers/logger' | 4 | import { auditLoggerFactory, CommentAuditView, getAuditIdFromRes } from '../../../helpers/audit-logger' |
6 | import { getFormattedObjects } from '../../../helpers/utils' | 5 | import { getFormattedObjects } from '../../../helpers/utils' |
7 | import { sequelizeTypescript } from '../../../initializers/database' | 6 | import { sequelizeTypescript } from '../../../initializers/database' |
8 | import { buildFormattedCommentTree, createVideoComment, markCommentAsDeleted } from '../../../lib/video-comment' | 7 | import { Notifier } from '../../../lib/notifier' |
8 | import { Hooks } from '../../../lib/plugins/hooks' | ||
9 | import { buildFormattedCommentTree, createVideoComment, removeComment } from '../../../lib/video-comment' | ||
9 | import { | 10 | import { |
10 | asyncMiddleware, | 11 | asyncMiddleware, |
11 | asyncRetryTransactionMiddleware, | 12 | asyncRetryTransactionMiddleware, |
@@ -23,12 +24,8 @@ import { | |||
23 | removeVideoCommentValidator, | 24 | removeVideoCommentValidator, |
24 | videoCommentThreadsSortValidator | 25 | videoCommentThreadsSortValidator |
25 | } from '../../../middlewares/validators' | 26 | } from '../../../middlewares/validators' |
26 | import { VideoCommentModel } from '../../../models/video/video-comment' | ||
27 | import { auditLoggerFactory, CommentAuditView, getAuditIdFromRes } from '../../../helpers/audit-logger' | ||
28 | import { AccountModel } from '../../../models/account/account' | 27 | import { AccountModel } from '../../../models/account/account' |
29 | import { Notifier } from '../../../lib/notifier' | 28 | import { VideoCommentModel } from '../../../models/video/video-comment' |
30 | import { Hooks } from '../../../lib/plugins/hooks' | ||
31 | import { sendDeleteVideoComment } from '../../../lib/activitypub/send' | ||
32 | 29 | ||
33 | const auditLogger = auditLoggerFactory('comments') | 30 | const auditLogger = auditLoggerFactory('comments') |
34 | const videoCommentRouter = express.Router() | 31 | const videoCommentRouter = express.Router() |
@@ -81,6 +78,7 @@ async function listVideoThreads (req: express.Request, res: express.Response) { | |||
81 | if (video.commentsEnabled === true) { | 78 | if (video.commentsEnabled === true) { |
82 | const apiOptions = await Hooks.wrapObject({ | 79 | const apiOptions = await Hooks.wrapObject({ |
83 | videoId: video.id, | 80 | videoId: video.id, |
81 | isVideoOwned: video.isOwned(), | ||
84 | start: req.query.start, | 82 | start: req.query.start, |
85 | count: req.query.count, | 83 | count: req.query.count, |
86 | sort: req.query.sort, | 84 | sort: req.query.sort, |
@@ -111,6 +109,7 @@ async function listVideoThreadComments (req: express.Request, res: express.Respo | |||
111 | if (video.commentsEnabled === true) { | 109 | if (video.commentsEnabled === true) { |
112 | const apiOptions = await Hooks.wrapObject({ | 110 | const apiOptions = await Hooks.wrapObject({ |
113 | videoId: video.id, | 111 | videoId: video.id, |
112 | isVideoOwned: video.isOwned(), | ||
114 | threadId: res.locals.videoCommentThread.id, | 113 | threadId: res.locals.videoCommentThread.id, |
115 | user | 114 | user |
116 | }, 'filter:api.video-thread-comments.list.params') | 115 | }, 'filter:api.video-thread-comments.list.params') |
@@ -149,9 +148,7 @@ async function addVideoCommentThread (req: express.Request, res: express.Respons | |||
149 | 148 | ||
150 | Hooks.runAction('action:api.video-thread.created', { comment }) | 149 | Hooks.runAction('action:api.video-thread.created', { comment }) |
151 | 150 | ||
152 | return res.json({ | 151 | return res.json({ comment: comment.toFormattedJSON() }) |
153 | comment: comment.toFormattedJSON() | ||
154 | }).end() | ||
155 | } | 152 | } |
156 | 153 | ||
157 | async function addVideoCommentReply (req: express.Request, res: express.Response) { | 154 | async function addVideoCommentReply (req: express.Request, res: express.Response) { |
@@ -173,27 +170,15 @@ async function addVideoCommentReply (req: express.Request, res: express.Response | |||
173 | 170 | ||
174 | Hooks.runAction('action:api.video-comment-reply.created', { comment }) | 171 | Hooks.runAction('action:api.video-comment-reply.created', { comment }) |
175 | 172 | ||
176 | return res.json({ comment: comment.toFormattedJSON() }).end() | 173 | return res.json({ comment: comment.toFormattedJSON() }) |
177 | } | 174 | } |
178 | 175 | ||
179 | async function removeVideoComment (req: express.Request, res: express.Response) { | 176 | async function removeVideoComment (req: express.Request, res: express.Response) { |
180 | const videoCommentInstance = res.locals.videoCommentFull | 177 | const videoCommentInstance = res.locals.videoCommentFull |
181 | const videoCommentInstanceBefore = cloneDeep(videoCommentInstance) | ||
182 | |||
183 | await sequelizeTypescript.transaction(async t => { | ||
184 | if (videoCommentInstance.isOwned() || videoCommentInstance.Video.isOwned()) { | ||
185 | await sendDeleteVideoComment(videoCommentInstance, t) | ||
186 | } | ||
187 | 178 | ||
188 | markCommentAsDeleted(videoCommentInstance) | 179 | await removeComment(videoCommentInstance) |
189 | |||
190 | await videoCommentInstance.save() | ||
191 | }) | ||
192 | 180 | ||
193 | auditLogger.delete(getAuditIdFromRes(res), new CommentAuditView(videoCommentInstance.toFormattedJSON())) | 181 | auditLogger.delete(getAuditIdFromRes(res), new CommentAuditView(videoCommentInstance.toFormattedJSON())) |
194 | logger.info('Video comment %d deleted.', videoCommentInstance.id) | ||
195 | |||
196 | Hooks.runAction('action:api.video-comment.deleted', { comment: videoCommentInstanceBefore }) | ||
197 | 182 | ||
198 | return res.type('json').status(204).end() | 183 | return res.type('json').status(204).end() |
199 | } | 184 | } |