]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/middlewares/validators/shared/video-comments.ts
Use private ACL for private videos in s3
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / shared / video-comments.ts
1 import express from 'express'
2 import { VideoCommentModel } from '@server/models/video/video-comment'
3 import { MVideoId } from '@server/types/models'
4 import { HttpStatusCode, ServerErrorCode } from '@shared/models'
5
6 async function doesVideoCommentThreadExist (idArg: number | string, video: MVideoId, res: express.Response) {
7 const id = parseInt(idArg + '', 10)
8 const videoComment = await VideoCommentModel.loadById(id)
9
10 if (!videoComment) {
11 res.fail({
12 status: HttpStatusCode.NOT_FOUND_404,
13 message: 'Video comment thread not found'
14 })
15 return false
16 }
17
18 if (videoComment.videoId !== video.id) {
19 res.fail({
20 type: ServerErrorCode.COMMENT_NOT_ASSOCIATED_TO_VIDEO,
21 message: 'Video comment is not associated to this video.'
22 })
23 return false
24 }
25
26 if (videoComment.inReplyToCommentId !== null) {
27 res.fail({ message: 'Video comment is not a thread.' })
28 return false
29 }
30
31 res.locals.videoCommentThread = videoComment
32 return true
33 }
34
35 async function doesVideoCommentExist (idArg: number | string, video: MVideoId, res: express.Response) {
36 const id = parseInt(idArg + '', 10)
37 const videoComment = await VideoCommentModel.loadByIdAndPopulateVideoAndAccountAndReply(id)
38
39 if (!videoComment) {
40 res.fail({
41 status: HttpStatusCode.NOT_FOUND_404,
42 message: 'Video comment thread not found'
43 })
44 return false
45 }
46
47 if (videoComment.videoId !== video.id) {
48 res.fail({
49 type: ServerErrorCode.COMMENT_NOT_ASSOCIATED_TO_VIDEO,
50 message: 'Video comment is not associated to this video.'
51 })
52 return false
53 }
54
55 res.locals.videoCommentFull = videoComment
56 return true
57 }
58
59 async function doesCommentIdExist (idArg: number | string, res: express.Response) {
60 const id = parseInt(idArg + '', 10)
61 const videoComment = await VideoCommentModel.loadByIdAndPopulateVideoAndAccountAndReply(id)
62
63 if (!videoComment) {
64 res.fail({
65 status: HttpStatusCode.NOT_FOUND_404,
66 message: 'Video comment thread not found'
67 })
68 return false
69 }
70
71 res.locals.videoCommentFull = videoComment
72 return true
73 }
74
75 export {
76 doesVideoCommentThreadExist,
77 doesVideoCommentExist,
78 doesCommentIdExist
79 }