diff options
author | Chocobozzz <me@florianbigard.com> | 2020-05-14 16:56:15 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-05-29 09:21:26 +0200 |
commit | 444c0a0e017824fb4ce526281a22c4abe0a13c50 (patch) | |
tree | 6a3c1ea8c4995361c582176257d1e1315287411d /server/controllers/api/bulk.ts | |
parent | 99139e7753e20ab0fba8eae5638d3dd3e792fe43 (diff) | |
download | PeerTube-444c0a0e017824fb4ce526281a22c4abe0a13c50.tar.gz PeerTube-444c0a0e017824fb4ce526281a22c4abe0a13c50.tar.zst PeerTube-444c0a0e017824fb4ce526281a22c4abe0a13c50.zip |
Add ability to bulk delete comments
Diffstat (limited to 'server/controllers/api/bulk.ts')
-rw-r--r-- | server/controllers/api/bulk.ts | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/server/controllers/api/bulk.ts b/server/controllers/api/bulk.ts new file mode 100644 index 000000000..1fe139c92 --- /dev/null +++ b/server/controllers/api/bulk.ts | |||
@@ -0,0 +1,41 @@ | |||
1 | import * as express from 'express' | ||
2 | import { asyncMiddleware, authenticate } from '../../middlewares' | ||
3 | import { bulkRemoveCommentsOfValidator } from '@server/middlewares/validators/bulk' | ||
4 | import { VideoCommentModel } from '@server/models/video/video-comment' | ||
5 | import { BulkRemoveCommentsOfBody } from '@shared/models/bulk/bulk-remove-comments-of-body.model' | ||
6 | import { removeComment } from '@server/lib/video-comment' | ||
7 | |||
8 | const bulkRouter = express.Router() | ||
9 | |||
10 | bulkRouter.post('/remove-comments-of', | ||
11 | authenticate, | ||
12 | asyncMiddleware(bulkRemoveCommentsOfValidator), | ||
13 | asyncMiddleware(bulkRemoveCommentsOf) | ||
14 | ) | ||
15 | |||
16 | // --------------------------------------------------------------------------- | ||
17 | |||
18 | export { | ||
19 | bulkRouter | ||
20 | } | ||
21 | |||
22 | // --------------------------------------------------------------------------- | ||
23 | |||
24 | async function bulkRemoveCommentsOf (req: express.Request, res: express.Response) { | ||
25 | const account = res.locals.account | ||
26 | const body = req.body as BulkRemoveCommentsOfBody | ||
27 | const user = res.locals.oauth.token.User | ||
28 | |||
29 | const filter = body.scope === 'my-videos' | ||
30 | ? { onVideosOfAccount: user.Account } | ||
31 | : {} | ||
32 | |||
33 | const comments = await VideoCommentModel.listForBulkDelete(account, filter) | ||
34 | |||
35 | // Don't wait result | ||
36 | res.sendStatus(204) | ||
37 | |||
38 | for (const comment of comments) { | ||
39 | await removeComment(comment) | ||
40 | } | ||
41 | } | ||