From 0e6cd1c00f71554fe7375a96db693a6983951ba6 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 12 Aug 2022 11:05:11 +0200 Subject: Add ability to list comments on local videos --- server/controllers/api/videos/comment.ts | 1 + server/middlewares/validators/videos/video-comments.ts | 6 ++++++ server/models/video/video-comment.ts | 8 +++++++- server/tests/api/videos/video-comments.ts | 16 ++++++++++++++++ 4 files changed, 30 insertions(+), 1 deletion(-) (limited to 'server') diff --git a/server/controllers/api/videos/comment.ts b/server/controllers/api/videos/comment.ts index 47fa2f2e2..44d64776c 100644 --- a/server/controllers/api/videos/comment.ts +++ b/server/controllers/api/videos/comment.ts @@ -91,6 +91,7 @@ async function listComments (req: express.Request, res: express.Response) { sort: req.query.sort, isLocal: req.query.isLocal, + onLocalVideo: req.query.onLocalVideo, search: req.query.search, searchAccount: req.query.searchAccount, searchVideo: req.query.searchVideo diff --git a/server/middlewares/validators/videos/video-comments.ts b/server/middlewares/validators/videos/video-comments.ts index b22a4e3b7..68f41e50e 100644 --- a/server/middlewares/validators/videos/video-comments.ts +++ b/server/middlewares/validators/videos/video-comments.ts @@ -24,6 +24,12 @@ const listVideoCommentsValidator = [ .custom(isBooleanValid) .withMessage('Should have a valid is local boolean'), + query('onLocalVideo') + .optional() + .customSanitizer(toBooleanOrNull) + .custom(isBooleanValid) + .withMessage('Should have a valid is on local video boolean'), + query('search') .optional() .custom(exists).withMessage('Should have a valid search'), diff --git a/server/models/video/video-comment.ts b/server/models/video/video-comment.ts index 6c5a764bf..1195e47e9 100644 --- a/server/models/video/video-comment.ts +++ b/server/models/video/video-comment.ts @@ -14,6 +14,7 @@ import { Table, UpdatedAt } from 'sequelize-typescript' +import { exists } from '@server/helpers/custom-validators/misc' import { getServerActor } from '@server/models/application/application' import { MAccount, MAccountId, MUserAccountId } from '@server/types/models' import { VideoPrivacy } from '@shared/models' @@ -312,12 +313,13 @@ export class VideoCommentModel extends Model { return { offset: start, diff --git a/server/tests/api/videos/video-comments.ts b/server/tests/api/videos/video-comments.ts index 1488ce2b5..5ab401aa4 100644 --- a/server/tests/api/videos/video-comments.ts +++ b/server/tests/api/videos/video-comments.ts @@ -254,6 +254,22 @@ describe('Test video comments', function () { expect(total).to.equal(0) }) + it('Should filter instance comments by onLocalVideo', async function () { + { + const { total, data } = await command.listForAdmin({ onLocalVideo: false }) + + expect(data).to.have.lengthOf(0) + expect(total).to.equal(0) + } + + { + const { total, data } = await command.listForAdmin({ onLocalVideo: true }) + + expect(data).to.not.have.lengthOf(0) + expect(total).to.not.equal(0) + } + }) + it('Should search instance comments by account', async function () { const { total, data } = await command.listForAdmin({ searchAccount: 'user' }) -- cgit v1.2.3