X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fcontrollers%2Fapi%2Fvideos%2Fcomment.ts;h=020d0b10470b709a989bbb48762b281cc05c5112;hb=9b337d8c0fce9c9aa68e44d76569c5abc6c0202e;hp=45ff969d94757d311a4fc34abdbd9a045cfd253b;hpb=b763f88dd0f455ce0ccae9cb81182c985a47c101;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/controllers/api/videos/comment.ts b/server/controllers/api/videos/comment.ts index 45ff969d9..020d0b104 100644 --- a/server/controllers/api/videos/comment.ts +++ b/server/controllers/api/videos/comment.ts @@ -1,5 +1,5 @@ import * as express from 'express' -import { ResultList } from '../../../../shared/models' +import { ResultList, UserRight } from '../../../../shared/models' import { VideoCommentCreate } from '../../../../shared/models/videos/video-comment.model' import { auditLoggerFactory, CommentAuditView, getAuditIdFromRes } from '../../../helpers/audit-logger' import { getFormattedObjects } from '../../../helpers/utils' @@ -11,6 +11,7 @@ import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, + ensureUserHasRight, optionalAuthenticate, paginationValidator, setDefaultPagination, @@ -19,9 +20,11 @@ import { import { addVideoCommentReplyValidator, addVideoCommentThreadValidator, + listVideoCommentsValidator, listVideoCommentThreadsValidator, listVideoThreadCommentsValidator, removeVideoCommentValidator, + videoCommentsValidator, videoCommentThreadsSortValidator } from '../../../middlewares/validators' import { AccountModel } from '../../../models/account/account' @@ -61,6 +64,17 @@ videoCommentRouter.delete('/:videoId/comments/:commentId', asyncRetryTransactionMiddleware(removeVideoComment) ) +videoCommentRouter.get('/comments', + authenticate, + ensureUserHasRight(UserRight.SEE_ALL_COMMENTS), + paginationValidator, + videoCommentsValidator, + setDefaultSort, + setDefaultPagination, + listVideoCommentsValidator, + asyncMiddleware(listComments) +) + // --------------------------------------------------------------------------- export { @@ -69,6 +83,26 @@ export { // --------------------------------------------------------------------------- +async function listComments (req: express.Request, res: express.Response) { + const options = { + start: req.query.start, + count: req.query.count, + sort: req.query.sort, + + isLocal: req.query.isLocal, + search: req.query.search, + searchAccount: req.query.searchAccount, + searchVideo: req.query.searchVideo + } + + const resultList = await VideoCommentModel.listCommentsForApi(options) + + return res.json({ + total: resultList.total, + data: resultList.data.map(c => c.toFormattedAdminJSON()) + }) +} + async function listVideoThreads (req: express.Request, res: express.Response) { const video = res.locals.onlyVideo const user = res.locals.oauth ? res.locals.oauth.token.User : undefined @@ -126,6 +160,10 @@ async function listVideoThreadComments (req: express.Request, res: express.Respo } } + if (resultList.data.length === 0) { + return res.sendStatus(404) + } + return res.json(buildFormattedCommentTree(resultList)) }