-import * as express from 'express'
-import { ResultList, ThreadsResultList, UserRight } from '../../../../shared/models'
-import { VideoCommentCreate } from '../../../../shared/models/videos/video-comment.model'
+import { MCommentFormattable } from '@server/types/models'
+import express from 'express'
+
+import { ResultList, ThreadsResultList, UserRight, VideoCommentCreate } from '../../../../shared/models'
+import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes'
+import { VideoCommentThreads } from '../../../../shared/models/videos/comment/video-comment.model'
import { auditLoggerFactory, CommentAuditView, getAuditIdFromRes } from '../../../helpers/audit-logger'
import { getFormattedObjects } from '../../../helpers/utils'
import { sequelizeTypescript } from '../../../initializers/database'
} from '../../../middlewares/validators'
import { AccountModel } from '../../../models/account/account'
import { VideoCommentModel } from '../../../models/video/video-comment'
-import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
-import { logger } from '@server/helpers/logger'
const auditLogger = auditLoggerFactory('comments')
const videoCommentRouter = express.Router()
sort: req.query.sort,
isLocal: req.query.isLocal,
+ onLocalVideo: req.query.onLocalVideo,
search: req.query.search,
searchAccount: req.query.searchAccount,
searchVideo: req.query.searchVideo
const video = res.locals.onlyVideo
const user = res.locals.oauth ? res.locals.oauth.token.User : undefined
- let resultList: ThreadsResultList<VideoCommentModel>
+ let resultList: ThreadsResultList<MCommentFormattable>
if (video.commentsEnabled === true) {
const apiOptions = await Hooks.wrapObject({
return res.json({
...getFormattedObjects(resultList.data, resultList.total),
totalNotDeletedComments: resultList.totalNotDeletedComments
- })
+ } as VideoCommentThreads)
}
async function listVideoThreadComments (req: express.Request, res: express.Response) {
const video = res.locals.onlyVideo
const user = res.locals.oauth ? res.locals.oauth.token.User : undefined
- let resultList: ResultList<VideoCommentModel>
+ let resultList: ResultList<MCommentFormattable>
if (video.commentsEnabled === true) {
const apiOptions = await Hooks.wrapObject({
videoId: video.id,
- isVideoOwned: video.isOwned(),
threadId: res.locals.videoCommentThread.id,
user
}, 'filter:api.video-thread-comments.list.params')
}
if (resultList.data.length === 0) {
- return res.sendStatus(HttpStatusCode.NOT_FOUND_404)
+ return res.fail({
+ status: HttpStatusCode.NOT_FOUND_404,
+ message: 'No comments were found'
+ })
}
return res.json(buildFormattedCommentTree(resultList))
Notifier.Instance.notifyOnNewComment(comment)
auditLogger.create(getAuditIdFromRes(res), new CommentAuditView(comment.toFormattedJSON()))
- Hooks.runAction('action:api.video-thread.created', { comment })
+ Hooks.runAction('action:api.video-thread.created', { comment, req, res })
return res.json({ comment: comment.toFormattedJSON() })
}
Notifier.Instance.notifyOnNewComment(comment)
auditLogger.create(getAuditIdFromRes(res), new CommentAuditView(comment.toFormattedJSON()))
- Hooks.runAction('action:api.video-comment-reply.created', { comment })
+ Hooks.runAction('action:api.video-comment-reply.created', { comment, req, res })
return res.json({ comment: comment.toFormattedJSON() })
}
async function removeVideoComment (req: express.Request, res: express.Response) {
const videoCommentInstance = res.locals.videoCommentFull
- await removeComment(videoCommentInstance)
+ await removeComment(videoCommentInstance, req, res)
auditLogger.delete(getAuditIdFromRes(res), new CommentAuditView(videoCommentInstance.toFormattedJSON()))