diff options
author | Chocobozzz <me@florianbigard.com> | 2020-11-13 16:38:23 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2020-11-13 16:38:23 +0100 |
commit | 0f8d00e3144060270d7fe603865fccaf18649c47 (patch) | |
tree | 6ccd0b44735ea4541a53d4fda17459260a69e676 /server/controllers/api | |
parent | dc13623baa244e13c33cc803de808818ef1e95a4 (diff) | |
download | PeerTube-0f8d00e3144060270d7fe603865fccaf18649c47.tar.gz PeerTube-0f8d00e3144060270d7fe603865fccaf18649c47.tar.zst PeerTube-0f8d00e3144060270d7fe603865fccaf18649c47.zip |
Implement video comment list in admin
Diffstat (limited to 'server/controllers/api')
-rw-r--r-- | server/controllers/api/videos/comment.ts | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/server/controllers/api/videos/comment.ts b/server/controllers/api/videos/comment.ts index 45ff969d9..ccd76c093 100644 --- a/server/controllers/api/videos/comment.ts +++ b/server/controllers/api/videos/comment.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { ResultList } from '../../../../shared/models' | 2 | import { ResultList, UserRight } from '../../../../shared/models' |
3 | import { VideoCommentCreate } from '../../../../shared/models/videos/video-comment.model' | 3 | import { VideoCommentCreate } from '../../../../shared/models/videos/video-comment.model' |
4 | import { auditLoggerFactory, CommentAuditView, getAuditIdFromRes } from '../../../helpers/audit-logger' | 4 | import { auditLoggerFactory, CommentAuditView, getAuditIdFromRes } from '../../../helpers/audit-logger' |
5 | import { getFormattedObjects } from '../../../helpers/utils' | 5 | import { getFormattedObjects } from '../../../helpers/utils' |
@@ -11,6 +11,7 @@ import { | |||
11 | asyncMiddleware, | 11 | asyncMiddleware, |
12 | asyncRetryTransactionMiddleware, | 12 | asyncRetryTransactionMiddleware, |
13 | authenticate, | 13 | authenticate, |
14 | ensureUserHasRight, | ||
14 | optionalAuthenticate, | 15 | optionalAuthenticate, |
15 | paginationValidator, | 16 | paginationValidator, |
16 | setDefaultPagination, | 17 | setDefaultPagination, |
@@ -19,9 +20,11 @@ import { | |||
19 | import { | 20 | import { |
20 | addVideoCommentReplyValidator, | 21 | addVideoCommentReplyValidator, |
21 | addVideoCommentThreadValidator, | 22 | addVideoCommentThreadValidator, |
23 | listVideoCommentsValidator, | ||
22 | listVideoCommentThreadsValidator, | 24 | listVideoCommentThreadsValidator, |
23 | listVideoThreadCommentsValidator, | 25 | listVideoThreadCommentsValidator, |
24 | removeVideoCommentValidator, | 26 | removeVideoCommentValidator, |
27 | videoCommentsValidator, | ||
25 | videoCommentThreadsSortValidator | 28 | videoCommentThreadsSortValidator |
26 | } from '../../../middlewares/validators' | 29 | } from '../../../middlewares/validators' |
27 | import { AccountModel } from '../../../models/account/account' | 30 | import { AccountModel } from '../../../models/account/account' |
@@ -61,6 +64,17 @@ videoCommentRouter.delete('/:videoId/comments/:commentId', | |||
61 | asyncRetryTransactionMiddleware(removeVideoComment) | 64 | asyncRetryTransactionMiddleware(removeVideoComment) |
62 | ) | 65 | ) |
63 | 66 | ||
67 | videoCommentRouter.get('/comments', | ||
68 | authenticate, | ||
69 | ensureUserHasRight(UserRight.SEE_ALL_COMMENTS), | ||
70 | paginationValidator, | ||
71 | videoCommentsValidator, | ||
72 | setDefaultSort, | ||
73 | setDefaultPagination, | ||
74 | listVideoCommentsValidator, | ||
75 | asyncMiddleware(listComments) | ||
76 | ) | ||
77 | |||
64 | // --------------------------------------------------------------------------- | 78 | // --------------------------------------------------------------------------- |
65 | 79 | ||
66 | export { | 80 | export { |
@@ -69,6 +83,26 @@ export { | |||
69 | 83 | ||
70 | // --------------------------------------------------------------------------- | 84 | // --------------------------------------------------------------------------- |
71 | 85 | ||
86 | async function listComments (req: express.Request, res: express.Response) { | ||
87 | const options = { | ||
88 | start: req.query.start, | ||
89 | count: req.query.count, | ||
90 | sort: req.query.sort, | ||
91 | |||
92 | isLocal: req.query.isLocal, | ||
93 | search: req.query.search, | ||
94 | searchAccount: req.query.searchAccount, | ||
95 | searchVideo: req.query.searchVideo | ||
96 | } | ||
97 | |||
98 | const resultList = await VideoCommentModel.listCommentsForApi(options) | ||
99 | |||
100 | return res.json({ | ||
101 | total: resultList.total, | ||
102 | data: resultList.data.map(c => c.toFormattedAdminJSON()) | ||
103 | }) | ||
104 | } | ||
105 | |||
72 | async function listVideoThreads (req: express.Request, res: express.Response) { | 106 | async function listVideoThreads (req: express.Request, res: express.Response) { |
73 | const video = res.locals.onlyVideo | 107 | const video = res.locals.onlyVideo |
74 | const user = res.locals.oauth ? res.locals.oauth.token.User : undefined | 108 | const user = res.locals.oauth ? res.locals.oauth.token.User : undefined |